Skip to content

Commit

Permalink
adding CNXHash class
Browse files Browse the repository at this point in the history
  • Loading branch information
rich-hart committed Oct 16, 2015
1 parent c9b7482 commit 52ce858
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cnxarchive/utils/ident_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
'split_legacy_hash',
'uuid2base64',
'base642uuid',
'identifiers_equal'
'identifiers_equal',
"CNXHash"
)


Expand Down Expand Up @@ -113,3 +114,17 @@ def identifiers_equal(identifier1,identifier2):
return identifier1 == identifier2
if len(identifier1) > len(identifier2):
return uuid2base64(identifier1) == identifier2

class CNXHash(uuid.UUID):
short_hash_length = 8
def __init__(self,uu=None,*args,**kwargs):
if type(uu)==uuid.UUID:
uuid.UUID.__init__(self,bytes=uu.get_bytes())
elif type(uu)==str:
uuid.UUID.__init__(self,hex=uu)
else:
uuid.UUID.__init__(self,*args,**kwargs)

def get_shortid(self):
shortid = uuid2base64(self.__str__())[:self.short_hash_length]
return shortid

0 comments on commit 52ce858

Please sign in to comment.