javaclass

Changeset

95:055b402634bc
2005-01-09 Paul Boddie raw files shortlog changelog graph Added a method to provide the "unqualified Python name" of methods. This is useful when generating wrappers of existing Python classes where the additional type information usually included in "Python names" is not present in the wrapped method names.
classfile.py (file)
     1.1 --- a/classfile.py	Sun Jan 09 01:36:06 2005 +0100
     1.2 +++ b/classfile.py	Sun Jan 09 22:34:45 2005 +0100
     1.3 @@ -63,14 +63,19 @@
     1.4      array_sep = "_array_" # was "[]"
     1.5      base_seps = ("_", "_") # was "<" and ">"
     1.6  
     1.7 -    def get_python_name(self):
     1.8 +    def get_unqualified_python_name(self):
     1.9          name = self.get_name()
    1.10          if str(name) == "<init>":
    1.11 -            name = "__init__"
    1.12 +            return "__init__"
    1.13          elif str(name) == "<clinit>":
    1.14              return "__clinit__"
    1.15          else:
    1.16 -            name = str(name)
    1.17 +            return str(name)
    1.18 +
    1.19 +    def get_python_name(self):
    1.20 +        name = self.get_unqualified_python_name()
    1.21 +        if name == "__clinit__":
    1.22 +            return name
    1.23          return name + self.symbol_sep + self._get_descriptor_as_name()
    1.24  
    1.25      def _get_descriptor_as_name(self):
    1.26 @@ -621,7 +626,8 @@
    1.27  
    1.28  if __name__ == "__main__":
    1.29      import sys
    1.30 -    f = open(sys.argv[1])
    1.31 +    f = open(sys.argv[1], "rb")
    1.32      c = ClassFile(f.read())
    1.33 +    f.close()
    1.34  
    1.35  # vim: tabstop=4 expandtab shiftwidth=4