示例#1
0
    def get_taz_style_id(iface):
        """
          Computes and returns the interface in the wrong way for maintaining
          backwards compatibility.
        """

        import utils

        name = iface.__name__

        try:
            import hashlib
            ash = hashlib.md5(name + ":").hexdigest()
        except:
            import md5
            ash = md5.new(name + ":").hexdigest()

        # encode it in base36 to get shorter ID
        ash = utils.radix( int(ash, 16), 36 )
        # ID have to be 25 char long
        ash = '0' * (25 - len(ash)) + ash
        assert (len(ash) == 25)
        return ("%s:%s" % (name, ash))
示例#2
0
    def get_id(iface):

        """Returns the unique identifier of the given interface."""

        # the algorithm is simple:
        # build a string containing the class name and a sorted list of the
        # properties and return the MD5 fingerprint of it
        import hashlib
        import utils

        name = iface.__name__
        items1 = Interface.get_permissions(iface)
        items1.sort()
        items2 = Interface.get_methods(iface)
        items2.sort()

        tmp = ["%s:%s" % (k, v) for k, v in items1 + items2]
        tmp = "%s:%s" % (name, ",".join(tmp))

        try:
            import hashlib
            ash = hashlib.md5(tmp).hexdigest()
        except:
            import md5
            ash = md5.new(tmp).hexdigest()

        # encode it in base36 to get shorter ID
        ash = utils.radix( int(ash, 16), 36 )
        # ID have to be 25 char long
        ash = '0' * (25 - len(ash)) + ash

        assert (len(ash) == 25)

        # the "-2" suffix is for marking the ID as rev 2
        iface_id = "%s:%s-2" % (name, ash)
        return iface_id