| 22 | | def microid(c, p): |
|---|
| 23 | | return sha.new(sha.new(c).hexdigest() + sha.new(p).hexdigest()).hexdigest() |
|---|
| | 22 | def microid(c, p, newstyle = True, hash = "sha1"): |
|---|
| | 23 | """ |
|---|
| | 24 | This function generates a MicroID digest based on claimer URI and property URI |
|---|
| | 25 | |
|---|
| | 26 | >>> microid("http://nicolast.be", "http://www.eikke.com", False) |
|---|
| | 27 | 'a6a18b671b0239ed85a32543ec487f443582e926' |
|---|
| | 28 | >>> microid("http://nicolast.be", "http://blog.eikke.com") |
|---|
| | 29 | 'http+http:sha1:207ec367c4f64dc9d37c47fb490ed9c2f686f875' |
|---|
| | 30 | >>> microid("mailto:spambox@nicolast.be", "http://nicolast.be") |
|---|
| | 31 | 'mailto+http:sha1:6646f18368bc40c4095092d61807ae98de9ef19a' |
|---|
| | 32 | """ |
|---|
| | 33 | hashfunc = None |
|---|
| | 34 | if hash == "sha1": |
|---|
| | 35 | hashfunc = sha.new |
|---|
| | 36 | else: |
|---|
| | 37 | raise Exception, "Only sha1 hashing is supported for now" |
|---|
| | 38 | |
|---|
| | 39 | digest = hashfunc(hashfunc(c).hexdigest() + hashfunc(p).hexdigest()).hexdigest() |
|---|
| | 40 | |
|---|
| | 41 | if newstyle: |
|---|
| | 42 | s1 = c.split(":")[0] |
|---|
| | 43 | s2 = p.split(":")[0] |
|---|
| | 44 | digest = "%(firsturi)s+%(seconduri)s:%(hash)s:%(microid)s" % {"firsturi": s1, "seconduri": s2, "hash": hash, "microid": digest} |
|---|
| | 45 | return digest |
|---|