Skip to content

Commit

Permalink
finetune fake_isbn algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
xlcnd committed Jan 23, 2015
1 parent c6567b4 commit f9f0888
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions isbnlib/dev/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def fake_isbn(title, author='unkown', publisher='unkown', sid=1):
key = regex1.sub(' ', key)
key = regex2.sub(' ', key).strip().lower()
# hash
return str(int(md5(b(key)).hexdigest()[:10], 16)
+ sid * 1000000000000)[:13]
return (str(sid) + str(int(md5(b(key)).hexdigest()[:10], 16)))[:13]


def in_virtual(): # pragma: no cover
Expand Down
4 changes: 2 additions & 2 deletions isbnlib/test/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_parse_placeholders():

def test_fake_isbn():
assert_equals(fake_isbn(' Hello?? Wer, ! ksDf: asdf. ; '), '1111006407537')
assert_equals(fake_isbn(' Hello?? Wer, ! ksDf: asdf. ; ', author=''), '2084496808737')
assert_equals(fake_isbn(' Hello?? Wer, ! ksDf: asdf. ; ', author=' '), '2084496808737')
assert_equals(fake_isbn(' Hello?? Wer, ! ksDf: asdf. ; ', author=''), '1108449680873')
assert_equals(fake_isbn(' Hello?? Wer, ! ksDf: asdf. ; ', author=' '), '1108449680873')
assert_equals(fake_isbn(' Hello?? Wer, ! ksDf: asdf. ; ', author='', publisher=''), '1181593982422')
assert_equals(fake_isbn(' Hello?? Wer, ! ksDf: asdf. ; ', author='a', publisher='K'), '1895031085488')
assert_equals(fake_isbn(' Hello?? Wer, ! ksDf: asdf. ; ', author='A', publisher='k'), '1895031085488')

0 comments on commit f9f0888

Please sign in to comment.