Example #1
0
    def _get_unique_name(self, obj):
        """Return a unique object name (a string).  Note that this does
        not cache the object, so if called with the same object 3 times
        you'll get three different names.
        """
        cname = obj.__class__.__name__
        nm = self._name_map
        result = ''
        builtin = False
        if cname in __builtin__.__dict__:
            builtin = True
            if hasattr(obj, '__name__'):
                cname = obj.__name__
        else:
            cname = camel_case_to_python(cname)

        special_ids = self._special_ids
        while len(result) == 0 or result in special_ids:
            if cname in nm:
                id = nm[cname] + 1
                nm[cname] = id
                result = '%s%d' % (cname, id)
            else:
                nm[cname] = 0
                # The first id doesn't need a number if it isn't builtin.
                if builtin:
                    result = '%s0' % (cname)
                else:
                    result = cname
        return result
Example #2
0
    def _get_unique_name(self, obj):
        """Return a unique object name (a string).  Note that this does
        not cache the object, so if called with the same object 3 times
        you'll get three different names.
        """
        cname = obj.__class__.__name__
        nm = self._name_map
        result = ''
        builtin = False
        if cname in __builtin__.__dict__:
            builtin = True
            if hasattr(obj, '__name__'):
                cname = obj.__name__
        else:
            cname = camel_case_to_python(cname)

        special_ids = self._special_ids
        while len(result) == 0 or result in special_ids:
            if cname in nm:
                id = nm[cname] + 1
                nm[cname] = id
                result = '%s%d'%(cname, id)
            else:
                nm[cname] = 0
                # The first id doesn't need a number if it isn't builtin.
                if builtin:
                    result = '%s0'%(cname)
                else:
                    result = cname
        return result
Example #3
0
 def test_python_conversion(self):
     """ Does CamelCase -> Python name work?
     """
     c_names = [ 'GetFooBar', 'GetOBBTree', 'XMLDataReader',
                 'GetFooXML', 'HTMLIsSGML', '_SetMe', '_XYZTest',
                 'Actor2D', 'Actor3D', 'Actor6D', 'PLOT3DReader',
                 'Actor61Dimension', 'GL2PSExporter', 'Volume16Reader' ]
     t_names = [ 'get_foo_bar', 'get_obb_tree', 'xml_data_reader',
                 'get_foo_xml', 'html_is_sgml', '_set_me',
                 '_xyz_test', 'actor2d', 'actor3d', 'actor6_d',
                 'plot3d_reader', 'actor61_dimension',
                 'gl2ps_exporter', 'volume16_reader' ]
     for i, c_name in enumerate(c_names):
         t_name = camel_case_to_python(c_name)
         self.assertEqual(t_name, t_names[i])
 def test_python_conversion(self):
     """ Does CamelCase -> Python name work?
     """
     c_names = [
         'GetFooBar', 'GetOBBTree', 'XMLDataReader', 'GetFooXML',
         'HTMLIsSGML', '_SetMe', '_XYZTest', 'Actor2D', 'Actor3D',
         'Actor6D', 'PLOT3DReader', 'Actor61Dimension', 'GL2PSExporter',
         'Volume16Reader'
     ]
     t_names = [
         'get_foo_bar', 'get_obb_tree', 'xml_data_reader', 'get_foo_xml',
         'html_is_sgml', '_set_me', '_xyz_test', 'actor2d', 'actor3d',
         'actor6_d', 'plot3d_reader', 'actor61_dimension', 'gl2ps_exporter',
         'volume16_reader'
     ]
     for i, c_name in enumerate(c_names):
         t_name = camel_case_to_python(c_name)
         self.assertEqual(t_name, t_names[i])
Example #5
0
 def test_python_conversion(self):
     """ Does CamelCase -> Python name work?
     """
     c_names = [
         "GetFooBar",
         "GetOBBTree",
         "XMLDataReader",
         "GetFooXML",
         "HTMLIsSGML",
         "_SetMe",
         "_XYZTest",
         "Actor2D",
         "Actor3D",
         "Actor6D",
         "PLOT3DReader",
         "Actor61Dimension",
         "GL2PSExporter",
         "Volume16Reader",
     ]
     t_names = [
         "get_foo_bar",
         "get_obb_tree",
         "xml_data_reader",
         "get_foo_xml",
         "html_is_sgml",
         "_set_me",
         "_xyz_test",
         "actor2d",
         "actor3d",
         "actor6_d",
         "plot3d_reader",
         "actor61_dimension",
         "gl2ps_exporter",
         "volume16_reader",
     ]
     for i, c_name in enumerate(c_names):
         t_name = camel_case_to_python(c_name)
         self.assertEqual(t_name, t_names[i])