Commits

Ronny Pfannschmidt committed fb283ac

move generate_paste_hash to model

Comments (0)

Files changed (2)

lodgeit/models.py

     :copyright: 2010 by Christopher Grebs.
     :license: BSD.
 """
+import difflib
 import time
-import difflib
+import re
 from datetime import datetime
+from hashlib import sha1
+from functools import partial
+from random import random
 from werkzeug import cached_property
 
 from flask import request
 from flask_sqlalchemy import SQLAlchemy
 
-from lodgeit.utils import generate_paste_hash
 from lodgeit.lib.highlighting import highlight, preview_highlight, LANGUAGES
 from lodgeit.lib.diff import prepare_udiff
 
 
 db = SQLAlchemy(app)
 
+_word_only = partial(re.compile(r'[^a-zA-Z0-9]').sub, '')
+def generate_paste_hash():
+    """Generates a more or less unique-truncated SHA1 hash."""
+    while 1:
+        digest = sha1('%s|%s' % (random(), time.time())).digest()
+        val = _word_only(digest.encode('base64').strip().splitlines()[0])[:20]
+        # sanity check.  number only not allowed (though unlikely)
+        if not val.isdigit():
+            return val
+
+
 class Paste(db.Model):
     __tablename__ = 'pastes'
 
     :copyright: 2007-2008 by Christopher Grebs.
     :license: BSD
 """
-import re
 import time
 from os import path
-from random import random
-from functools import partial
 
 from werkzeug import Request as RequestBase, Response
 from werkzeug.contrib.securecookie import SecureCookie
 from lodgeit.lib.highlighting import get_style
 
 try:
-    from hashlib import sha1
 except:
     from sha import new as sha1
 
 #: constants
-_word_only = partial(re.compile(r'[^a-zA-Z0-9]').sub, '')
 COOKIE_NAME = u'lodgeit_session'
 
 
 
-def generate_paste_hash():
-    """Generates a more or less unique-truncated SHA1 hash."""
-    while 1:
-        digest = sha1('%s|%s' % (random(), time.time())).digest()
-        val = _word_only(digest.encode('base64').strip().splitlines()[0])[:20]
-        # sanity check.  number only not allowed (though unlikely)
-        if not val.isdigit():
-            return val
 
 
 class Request(RequestBase):
         ngettext=request.translations.ungettext,
         style = style,
         css = css,
-        url = request.get_url,
     )
     return jinja_environment.get_template(template_name).render(context)