~mwhudson/loggerhead/dont-hold-branches-open

« back to all changes in this revision

Viewing changes to loggerhead/util.py

  • Committer: Michael Hudson
  • Date: 2008-07-01 00:10:47 UTC
  • Revision ID: michael.hudson@canonical.com-20080701001047-2pg0c4uypojhqeu0
man, deleting dead code is addictive

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import datetime
28
28
import logging
29
29
import re
30
 
import sha
31
30
import struct
32
 
import sys
33
31
import threading
34
32
import time
35
 
import traceback
36
33
 
37
34
 
38
35
log = logging.getLogger("loggerhead.controllers")
142
139
        return out
143
140
 
144
141
 
145
 
def clean_revid(revid):
146
 
    if revid == 'missing':
147
 
        return revid
148
 
    return sha.new(revid).hexdigest()
149
 
 
150
 
 
151
 
def obfuscate(text):
152
 
    return ''.join([ '&#%d;' % ord(c) for c in text ])
153
 
 
154
 
 
155
142
def trunc(text, limit=10):
156
143
    if len(text) <= limit:
157
144
        return text
158
145
    return text[:limit] + '...'
159
146
 
160
147
 
161
 
def to_utf8(s):
162
 
    if isinstance(s, unicode):
163
 
        return s.encode('utf-8')
164
 
    return s
165
 
 
166
 
 
167
148
STANDARD_PATTERN = re.compile(r'^(.*?)\s*<(.*?)>\s*$')
168
149
EMAIL_PATTERN = re.compile(r'[-\w\d\+_!%\.]+@[-\w\d\+_!%\.]+')
169
150
 
232
213
    return '-rw-r--r--'
233
214
 
234
215
 
235
 
def if_present(format, value):
236
 
    """
237
 
    format a value using a format string, if the value exists and is not None.
238
 
    """
239
 
    if value is None:
240
 
        return ''
241
 
    return format % value
242
 
 
243
 
 
244
216
def b64(s):
245
217
    s = base64.encodestring(s).replace('\n', '')
246
218
    while (len(s) > 0) and (s[-1] == '='):
343
315
            [navigation.scan_url, next_page_revno], **params)
344
316
 
345
317
 
346
 
def log_exception(log):
347
 
    for line in ''.join(traceback.format_exception(*sys.exc_info())).split('\n'):
348
 
        log.debug(line)
349
 
 
350
 
 
351
318
def decorator(unbound):
352
319
    def new_decorator(f):
353
320
        g = unbound(f)
377
344
    return _decorator
378
345
 
379
346
 
380
 
 
381
347
@decorator
382
348
def lsprof(f):
383
349
    def _f(*a, **kw):