http://bugzilla.novell.com/show_bug.cgi?id=520499 Summary: yast2-python-bindings does not properly handle imported module names that are not valid Python identifiers Classification: openSUSE Product: openSUSE 11.1 Version: Final Platform: All OS/Version: openSUSE 11.1 Status: NEW Severity: Normal Priority: P5 - None Component: YaST2 AssignedTo: bnc-team-screening@forge.provo.novell.com ReportedBy: opensuse@jeffshantz.com QAContact: jsrain@novell.com Found By: --- Created an attachment (id=303964) --> (http://bugzilla.novell.com/attachment.cgi?id=303964) Patch fixing the issue User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/2008103100 SUSE/3.0.4-4.6 Firefox/3.0.4 I am using version 2.17.3 of yast2-python-bindings. If you use the import_module() method and attempt to import a YCP module whose name is not a valid Python identifier, it will be imported properly, but will fail when you try to use it. For instance, if you tried to import: ycp.import_module("YaPI::HTTPD") It would be imported as; ycp.YaPI::HTTPD However, when you attempt to use this module, Python throws an error since it's an invalid Python identifier. I have debugged and fixed the issue and attached a patch. I have added a method that translates imported module names so that they are imported into Python having valid identifier names. For instance, if you import: ycp.import_module("YaPI::HTTPD") It will be imported as: ycp.YaPI__HTTPD As you can see, invalid characters are translated to underscores. The translation ensures that all characters of the module name are letters, numbers, or underscores, and also that the first character is a letter or underscore. This is in accordance with correct Python syntax. The changes are specific to YCP.cc, and one method has been added (translate_namespace). The translated name is then used in the PyDict_SetItemString() call in RegFunctions(). I have tested the fix at the command line, and have used the patched version of the bindings with the YaST Education module (which I am currently developing in Python). So far, everything is working great, and I can now use YaPI modules. Reproducible: Always Steps to Reproduce: Try importing a module in the YaPI directory. I used HTTPD, since its module name is YaPI::HTTPD, which is an invalid Python identifier. jeff@js3:~> python Python 2.6 (r26:66714, Dec 3 2008, 06:05:48) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import ycp ycp.import_module("YaPI::HTTPD") True ycp.YaPI::HTTPD.GetKnownModules() File "<stdin>", line 1 ycp.YaPI::HTTPD.GetKnownModules() ^ SyntaxError: invalid syntax
After applying my patch: # cd /usr/src/packages/SOURCES/yast2-python-bindings-2.17.3/src # patch < /home/jeff/patch patching file YCP.cc # cd .. && make && sudo make install # python Python 2.6 (r26:66714, Dec 3 2008, 06:05:48) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import ycp ycp.import_module("YaPI::HTTPD") True ycp.YaPI__HTTPD.GetModuleList() ('actions', 'alias', 'auth_basic', 'authn_file', 'authz_host', 'authz_groupfile', 'authz_default', 'authz_user', 'authn_dbm', 'autoindex', 'cgi', 'dir', 'env', 'expires', 'include', 'log_config', 'mime', 'negotiation', 'setenvif', 'ssl', 'suexec', 'userdir', 'php5')
# python Actual Results: See Steps to Reproduce. Expected Results: See Steps to Reproduce. -- Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.