home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1429 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  3.2 KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
  6. __docformat__ = 'restructuredtext en'
  7. import time
  8. import sys
  9. import cherrypy
  10. from calibre import strftime as _strftime, prints
  11. from calibre.utils.date import now as nowf
  12. from calibre.utils.config import tweaks
  13.  
  14. class Offsets(object):
  15.     
  16.     def __init__(self, offset, delta, total):
  17.         if offset < 0:
  18.             offset = 0
  19.         
  20.         if offset >= total:
  21.             raise cherrypy.HTTPError(404, 'Invalid offset: %r' % offset)
  22.         offset >= total
  23.         last_allowed_index = total - 1
  24.         last_current_index = offset + delta - 1
  25.         self.slice_upper_bound = offset + delta
  26.         self.offset = offset
  27.         self.next_offset = last_current_index + 1
  28.         if self.next_offset > last_allowed_index:
  29.             self.next_offset = -1
  30.         
  31.         self.previous_offset = self.offset - delta
  32.         if self.previous_offset < 0:
  33.             self.previous_offset = 0
  34.         
  35.         self.last_offset = last_allowed_index - delta
  36.         if self.last_offset < 0:
  37.             self.last_offset = 0
  38.         
  39.  
  40.  
  41.  
  42. def expose(func):
  43.     
  44.     def do(*args, **kwargs):
  45.         self = func.im_self
  46.         if self.opts.develop:
  47.             start = time.time()
  48.         
  49.         dict.update(cherrypy.response.headers, {
  50.             'Server': self.server_name })
  51.         if not self.embedded:
  52.             self.db.check_if_modified()
  53.         
  54.         ans = func(*args, **kwargs)
  55.         if self.opts.develop:
  56.             prints('Function', func.__name__, 'called with args:', args, kwargs)
  57.             prints('\tTime:', func.__name__, time.time() - start)
  58.         
  59.         return ans
  60.  
  61.     do.__name__ = func.__name__
  62.     return do
  63.  
  64.  
  65. def strftime(fmt = '%Y/%m/%d %H:%M:%S', dt = None):
  66.     if not hasattr(dt, 'timetuple'):
  67.         dt = nowf()
  68.     
  69.     dt = dt.timetuple()
  70.     
  71.     try:
  72.         return _strftime(fmt, dt)
  73.     except:
  74.         return _strftime(fmt, nowf().timetuple())
  75.  
  76.  
  77.  
  78. def format_tag_string(tags, sep, ignore_max = False, no_tag_count = False):
  79.     MAX = None if ignore_max else tweaks['max_content_server_tags_shown']
  80.     tlist.sort(cmp = (lambda x, y: cmp(x.lower(), y.lower())))
  81.     if len(tlist) > MAX:
  82.         tlist = tlist[:MAX] + [
  83.             '...']
  84.     
  85.     if no_tag_count:
  86.         if tlist:
  87.             return ', '.join(tlist)
  88.         return ''
  89.     if tlist:
  90.         return u'%s:&:%s' % (tweaks['max_content_server_tags_shown'], ', '.join(tlist))
  91.     return ''
  92.  
  93.