From 24fc691e0d66b37e4134a4ef2c12eb2490698afb Mon Sep 17 00:00:00 2001 From: Spencer Miller Date: Thu, 19 Jun 2014 16:29:39 -0700 Subject: [PATCH] added a from_string method to HumanHasher This lets you make calls like: >>> humanhash.from_string("humanhash") 'asparagus-oven-minnesota-hamper' --- humanhash.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/humanhash.py b/humanhash.py index b9380df..e1f31cf 100644 --- a/humanhash.py +++ b/humanhash.py @@ -135,8 +135,20 @@ def uuid(self, **params): digest = str(uuidlib.uuid4()).replace('-', '') return self.humanize(digest, **params), digest + + def from_string(self, value, **params): + + """ + Generate a UUID with a human-readable representation from an input string. + + Returns `human_repr`. Accepts the same keyword arguments as :meth:`humanize` + """ + + digest = str(uuidlib.uuid3(uuidlib.NAMESPACE_DNS, value)).replace('-', '') + return self.humanize(digest, **params) DEFAULT_HASHER = HumanHasher() uuid = DEFAULT_HASHER.uuid humanize = DEFAULT_HASHER.humanize +from_string = DEFAULT_HASHER.from_string