Esempio n. 1
0
    def get_checksum(self):
        if self.index_by_name:
            objects = frozenset(self)
            checksum = persistent_hash(objects)
        else:
            checksum = persistent_hash(None)

        return checksum
Esempio n. 2
0
    def test_common_persistent_hash_1(self):
        assert persistent_hash(1) == persistent_hash(1)
        assert persistent_hash((1, '2')) == persistent_hash((1, '2'))

        u = uuid.uuid4()
        assert persistent_hash(u) != persistent_hash(uuid.uuid4())
        assert persistent_hash(u) != persistent_hash(u.hex)
        assert persistent_hash(u) == persistent_hash(u)
Esempio n. 3
0
 def persistent_hash(self):
     vals = []
     for k, v in self.items():
         if is_named_class(v):
             v = v.name
         vals.append((k, v))
     return phash.persistent_hash(frozenset(vals))
Esempio n. 4
0
    def test_common_persistent_hash_2(self):
        class Foo:
            def persistent_hash(self):
                return 123

        val = frozenset(('aaaa', 'bbb', 21, 33.123, b'aaa', True, None, Foo()))
        exp = 2133544778164784224951520084939573399144598351897512116789
        self.assertEqual(persistent_hash(val), exp)
Esempio n. 5
0
    def persistent_hash(self):
        """Compute object 'snapshot' hash.

        This is an explicit method since schema Objects are mutable.
        The hash must be externally stable, i.e. stable across the runs
        and thus must not contain default object hashes (addresses),
        including that of None.
        """
        return phash.persistent_hash(self.hash_criteria())
Esempio n. 6
0
    def test_common_persistent_hash_3(self):
        class NoPH:
            pass

        with self.assertRaisesRegex(TypeError, 'un.*hashable'):
            persistent_hash(NoPH())

        self.assertFalse(issubclass(NoPH, PersistentlyHashable))
        self.assertFalse(isinstance(NoPH, PersistentlyHashable))
        self.assertFalse(isinstance(NoPH(), PersistentlyHashable))

        class PH:
            def persistent_hash(self):
                return 123

        self.assertTrue(issubclass(PH, PersistentlyHashable))
        self.assertFalse(isinstance(PH, PersistentlyHashable))
        self.assertTrue(isinstance(PH(), PersistentlyHashable))

        self.assertEqual(persistent_hash(PH()), 123)
Esempio n. 7
0
 def __init__(self,
              *,
              attribute_map,
              metaclass=None,
              classname=None,
              recursive_link=False,
              virtuals_map=None):
     self.attribute_map = attribute_map
     self.virtuals_map = virtuals_map
     self.metaclass = metaclass
     self.classname = classname
     self.recursive_link = recursive_link
     self.id = str(persistent_hash.persistent_hash(self))
Esempio n. 8
0
 def gen_virt_parent_name(cls, names, module=None):
     name = 'Virtual_%x' % persistent_hash(frozenset(names))
     if module is None:
         module = next(iter(names)).module
     return sn.Name(name=name, module=module)
Esempio n. 9
0
 def __init__(self, **kwargs):
     hash_items = (kwargs['parent_id'], kwargs['checksum'],
                   kwargs['comment'])
     kwargs['id'] = persistent_hash('%s%s%s' % hash_items)
     super().__init__(**kwargs)
Esempio n. 10
0
 def persistent_hash(self):
     return persistent_hash(self.get_names())
Esempio n. 11
0
 def persistent_hash(self):
     return persistent_hash(self.__class__.name + ':' + self.value)
Esempio n. 12
0
 def persistent_hash(self):
     return persistent_hash(frozenset(self.forms.values()))
Esempio n. 13
0
 def persistent_hash(self):
     return persistent_hash.persistent_hash(
         (tuple(self.attribute_map), frozenset(self.virtuals_map.items())
          if self.virtuals_map else None, self.metaclass, self.classname,
          self.recursive_link))
Esempio n. 14
0
 def persistent_hash(self):
     return persistent_hash(self.int)
Esempio n. 15
0
 def get_checksum_details(self):
     objects = list(sorted(self, key=lambda e: e.name))
     return [(str(o.name), persistent_hash(o)) for o in objects]
Esempio n. 16
0
    def get_checksum(self):
        c = []
        for n, m in self.modules.items():
            c.append((n, m.get_checksum()))

        return persistent_hash(frozenset(c))