Package: python-xpcom
Version: 1:0.0~hg20100212-5+1
Severity: normal

When trying to access the 'print' method of the nsIWebBrowserPrint
interface, python-xpcom generates Python code on the fly and fails to
evaluate it because 'print' is a reserved keyword in Python:

(sugar-jhbuild1)sascha.silbe@twin:~$ ./print-bug.py
returning /tmp/prefs.js for key NS_APP_PREFS_50_FILE
GConf Error: Failed to contact configuration server; the most common cause is a 
missing or misconfigured D-Bus session bus daemon. See 
http://projects.gnome.org/gconf/ for information. (Details -  1: Server ping 
error: IDL:omg.org/CORBA/COMM_FAILURE:1.0)
Traceback (most recent call last):
  File "./print-bug.py", line 20, in _save_pdf
    getattr(print_iface, 'print')
  File "/usr/lib/pymodules/python2.6/xpcom/client/__init__.py", line 374, in 
__getattr__
    return getattr(interface, attr)
  File "/usr/lib/pymodules/python2.6/xpcom/client/__init__.py", line 466, in 
__getattr__
    unbound_method = BuildMethod(method_info, self._iid_)
  File "/usr/lib/pymodules/python2.6/xpcom/client/__init__.py", line 125, in 
BuildMethod
    codeObject = compile(method_code, "<XPCOMObject method '%s'>" % (name,), 
"exec")
  File "<XPCOMObject method 'print'>", line 2
    def print(self, Param1, Param2):
            ^
SyntaxError: invalid syntax


print-bug.py is attached.

In case anyone else gets stuck on the issue, here is how I worked around it:

        try:
            print_method = getattr(print_iface, 'print')
        except SyntaxError:
            # HACK: Run-time patch python-xpcom to work around a bug.
            # 'print' is a reserved keyword, so it must not occur in generated
            # code.
            iid = interfaces.nsIWebBrowserPrint
            internal_interface = print_iface.__dict__['_interfaces_'][iid]
            info = internal_interface.__dict__['_method_infos_']['print']
            info.name = 'print_'
            print_method = getattr(print_iface, 'print')


-- System Information:
Debian Release: 6.0.1
  APT prefers stable
  APT policy: (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages python-xpcom depends on:
ii  libc6                   2.11.2-10        Embedded GNU C Library: Shared lib
ii  libnspr4-0d             4.8.6-1          NetScape Portable Runtime Library
ii  libpython2.6            2.6.6-8+b1       Shared Python runtime library (ver
ii  libstdc++6              4.4.5-8          The GNU Standard C++ Library v3
ii  python                  2.6.6-3+squeeze6 interactive high-level object-orie
ii  python-support          1.0.10           automated rebuilding support for P
ii  xulrunner-1.9.2         1.9.2.13-2       XUL + XPCOM application runner

python-xpcom recommends no packages.

python-xpcom suggests no packages.

-- no debconf information
#!/usr/bin/env python
import gobject
import gtk
import hulahop.webview
import xpcom.components

hulahop.startup('/tmp')


class Browser(hulahop.webview.WebView):
    def do_setup(self):
        hulahop.webview.WebView.do_setup(self)
        gobject.timeout_add(3, self._save_pdf)

    def _save_pdf(self):
        cls = xpcom.components.classes['@mozilla.org/gfx/printsettings-service;1']
        setting_service = cls.getService(xpcom.components.interfaces.nsIPrintSettingsService)
        req = self.get_dom_window().QueryInterface(xpcom.components.interfaces.nsIInterfaceRequestor)
        print_iface = req.getInterface(xpcom.components.interfaces.nsIWebBrowserPrint)
        getattr(print_iface, 'print')


browser = Browser()
browser.show()
main_window = gtk.Window()
main_window.add(browser)
main_window.show()
browser.load_uri('http://www.sugarlabs.org/')
gtk.main()

Reply via email to