for those who wondered why pyxpcom has trouble looking up some trivial error codes such as NS_ERROR_FILE_NOT_FOUND:

this is a problem related to signed ints and longs being treated differently in python.

here is a fixed version of the exception class that properly looks up and returns errors:

# The standard XPCOM exception object.
# Instances of this class are raised by the XPCOM extension module.
class Exception(exceptions.Exception):
   def __init__(self, errno, message = None):
       assert int(errno) == errno, "The errno param must be an integer"
       self.errno = errno
       if self.errno < 0: # fix signed int problem
           self.errno = 0x100000000 + self.errno
       self.message = message
       exceptions.Exception.__init__(self, errno)
   def __str__(self):
       if not hr_map:
           import nsError
           for name, val in nsError.__dict__.items():
               if type(val) in (long,int):
                   hr_map[val] = name
       message = self.message
       if message is None:
           message = hr_map.get(self.errno)
           if message is None:
               message = ""
       return "0x%x (%s)" % (self.errno, message)


--
Leonard Ritter
Software Developer
UI Experience

Steganos. Privacy Software made easy.

Steganos GmbH
Wildunger Straße 6
60487 Frankfurt am Main
Germany

Tel.: +49 (0) 69 - 71 91 82-42
Fax: +49 (0) 69 - 71 91 82-11
E-Mail: [EMAIL PROTECTED]

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to