19
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
from xml.etree import ElementTree as ET
25
from elementtree import ElementTree as ET
123
129
return _wrap_with_date_time_title(date, _displaydate(date))
126
class Container (object):
132
class Container(object):
128
134
Convert a dict into an object with attributes.
130
137
def __init__(self, _dict=None, **kw):
131
138
if _dict is not None:
132
139
for key, value in _dict.iteritems():
137
144
def __repr__(self):
139
146
for key, value in self.__dict__.iteritems():
140
if key.startswith('_') or (getattr(self.__dict__[key], '__call__', None) is not None):
147
if key.startswith('_') or (getattr(self.__dict__[key],
148
'__call__', None) is not None):
142
150
out += '%r => %r, ' % (key, value)
172
181
return '%s at %s' % (username, domains[-2])
173
182
return '%s at %s' % (username, domains[0])
184
def hide_emails(emails):
186
try to obscure any email address in a list of bazaar committers' names.
190
result.append(hide_email(email))
176
193
# only do this if unicode turns out to be a problem
177
194
#_BADCHARS_RE = re.compile(ur'[\u007f-\uffff]')
179
196
# FIXME: get rid of this method; use fixed_width() and avoid XML().
180
199
def html_clean(s):
182
201
clean up a string for html display. expand any tabs, encode any html
227
247
s = s.decode('utf-8')
228
248
except UnicodeDecodeError:
229
249
s = s.decode('iso-8859-15')
230
return s.expandtabs().replace(' ', NONBREAKING_SPACE)
251
s = cgi.escape(s).expandtabs().replace(' ', NONBREAKING_SPACE)
253
return HSC.clean(s).replace('\n', '<br/>')
233
256
def fake_permissions(kind, executable):
311
335
navigation.position = 0
312
336
navigation.count = len(navigation.revid_list)
313
337
navigation.page_position = navigation.position // navigation.pagesize + 1
314
navigation.page_count = (len(navigation.revid_list) + (navigation.pagesize - 1)) // navigation.pagesize
338
navigation.page_count = (len(navigation.revid_list) + (navigation.pagesize\
339
- 1)) // navigation.pagesize
316
341
def get_offset(offset):
317
if (navigation.position + offset < 0) or (navigation.position + offset > navigation.count - 1):
342
if (navigation.position + offset < 0) or (
343
navigation.position + offset > navigation.count - 1):
319
345
return navigation.revid_list[navigation.position + offset]
327
353
navigation.next_page_revid)
328
354
start_revno = navigation.history.get_revno(navigation.start_revid)
330
params = { 'filter_file_id': navigation.filter_file_id }
356
params = {'filter_file_id': navigation.filter_file_id}
331
357
if getattr(navigation, 'query', None) is not None:
332
358
params['q'] = navigation.query
341
367
navigation.next_page_url = navigation.branch.context_url(
342
368
[navigation.scan_url, next_page_revno], **params)
344
371
def directory_breadcrumbs(path, is_root, view):
346
373
Generate breadcrumb information from the directory path given
348
375
The path given should be a path up to any branch that is currently being
352
379
path -- The path to convert into breadcrumbs
353
380
is_root -- Whether or not loggerhead is serving a branch at its root
383
408
breadcrumbs[-1]['suffix'] = '/' + view
384
409
return breadcrumbs
386
412
def branch_breadcrumbs(path, inv, view):
388
414
Generate breadcrumb information from the branch path given
390
416
The path given should be a path that exists within a branch
393
419
path -- The path to convert into breadcrumbs
394
420
inv -- Inventory to get file information from
417
445
return new_decorator
420
# common threading-lock decorator
421
def with_lock(lockname, debug_name=None):
422
if debug_name is None:
423
debug_name = lockname
425
def _decorator(unbound):
426
def locked(self, *args, **kw):
427
getattr(self, lockname).acquire()
429
return unbound(self, *args, **kw)
431
getattr(self, lockname).release()
438
452
def _f(*a, **kw):
439
453
from loggerhead.lsprof import profile
442
456
ret, stats = profile(f, *a, **kw)
443
log.debug('Finished profiled %s in %d msec.' % (f.__name__, int((time.time() - z) * 1000)))
457
log.debug('Finished profiled %s in %d msec.' % (f.__name__,
458
int((time.time() - z) * 1000)))
446
461
now = time.time()
447
462
msec = int(now * 1000) % 1000
448
timestr = time.strftime('%Y%m%d%H%M%S', time.localtime(now)) + ('%03d' % msec)
463
timestr = time.strftime('%Y%m%d%H%M%S',
464
time.localtime(now)) + ('%03d' % (msec,))
449
465
filename = f.__name__ + '-' + timestr + '.lsprof'
450
466
cPickle.dump(stats, open(filename, 'w'), 2)
507
523
overrides = dict((k, v) for (k, v) in overrides.iteritems() if k in _valid)
508
524
map.update(overrides)
528
class Reloader(object):
530
This class wraps all paste.reloader logic. All methods are @classmethod.
533
_reloader_environ_key = 'PYTHON_RELOADER_SHOULD_RUN'
536
def _turn_sigterm_into_systemexit(cls):
538
Attempts to turn a SIGTERM exception into a SystemExit exception.
545
def handle_term(signo, frame):
547
signal.signal(signal.SIGTERM, handle_term)
550
def is_installed(cls):
551
return os.environ.get(cls._reloader_environ_key)
555
from paste import reloader
556
reloader.install(int(1))
559
def restart_with_reloader(cls):
560
"""Based on restart_with_monitor from paste.script.serve."""
561
print 'Starting subprocess with file monitor'
563
args = [sys.executable] + sys.argv
564
new_environ = os.environ.copy()
565
new_environ[cls._reloader_environ_key] = 'true'
569
cls._turn_sigterm_into_systemexit()
570
proc = subprocess.Popen(args, env=new_environ)
571
exit_code = proc.wait()
573
except KeyboardInterrupt:
574
print '^C caught in monitor process'
578
and getattr(os, 'kill', None) is not None):
581
os.kill(proc.pid, signal.SIGTERM)
582
except (OSError, IOError):
585
# Reloader always exits with code 3; but if we are
586
# a monitor, any exit code will restart
589
print '-'*20, 'Restarting', '-'*20
592
def convert_file_errors(application):
593
"""WSGI wrapper to convert some file errors to Paste exceptions"""
594
def new_application(environ, start_response):
596
return application(environ, start_response)
597
except (IOError, OSError), e:
599
from paste import httpexceptions
600
if e.errno == errno.ENOENT:
601
raise httpexceptions.HTTPNotFound()
602
elif e.errno == errno.EACCES:
603
raise httpexceptions.HTTPForbidden()
606
return new_application