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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '3.1.2'
  5. from urlparse import urljoin as _urljoin
  6.  
  7. class _AttributeDocstrings(type):
  8.     
  9.     def __init__(cls, name, bases, dct):
  10.         if not cls.__doc__:
  11.             pass
  12.         newdoc = [
  13.             '']
  14.         dctnames = dct.keys()
  15.         dctnames.sort()
  16.         for name in dctnames:
  17.             if name.endswith('__doc'):
  18.                 if hasattr(cls, name):
  19.                     delattr(cls, name)
  20.                 
  21.                 val = []([ '    ' + line.strip() for line in dct[name].split('\n') ])
  22.                 attrname = name[:-5]
  23.                 
  24.                 try:
  25.                     attrval = getattr(cls, attrname)
  26.                 except AttributeError:
  27.                     []
  28.                     []
  29.                     '\n'.join
  30.                     attrval = 'missing'
  31.                 except:
  32.                     []
  33.  
  34.                 newdoc.append('%s [= %r]:\n%s' % (attrname, attrval, val))
  35.                 continue
  36.             []
  37.         
  38.         cls.__doc__ = '\n\n'.join(newdoc)
  39.  
  40.  
  41. from cherrypy._cperror import HTTPError, HTTPRedirect, InternalRedirect
  42. from cherrypy._cperror import NotFound, CherryPyException, TimeoutError
  43. from cherrypy import _cpdispatch as dispatch
  44. from cherrypy import _cptools
  45. tools = _cptools.default_toolbox
  46. Tool = _cptools.Tool
  47. from cherrypy import _cprequest
  48. from cherrypy.lib import http as _http
  49. from cherrypy import _cptree
  50. tree = _cptree.Tree()
  51. from cherrypy._cptree import Application
  52. from cherrypy import _cpwsgi as wsgi
  53. from cherrypy import process
  54.  
  55. try:
  56.     from cherrypy.process import win32
  57.     engine = win32.Win32Bus()
  58.     engine.console_control_handler = win32.ConsoleCtrlHandler(engine)
  59.     del win32
  60. except ImportError:
  61.     engine = process.bus
  62.  
  63.  
  64. class _TimeoutMonitor(process.plugins.Monitor):
  65.     
  66.     def __init__(self, bus):
  67.         self.servings = []
  68.         process.plugins.Monitor.__init__(self, bus, self.run)
  69.  
  70.     
  71.     def acquire(self):
  72.         self.servings.append((serving.request, serving.response))
  73.  
  74.     
  75.     def release(self):
  76.         
  77.         try:
  78.             self.servings.remove((serving.request, serving.response))
  79.         except ValueError:
  80.             pass
  81.  
  82.  
  83.     
  84.     def run(self):
  85.         for req, resp in self.servings:
  86.             resp.check_timeout()
  87.         
  88.  
  89.  
  90. engine.timeout_monitor = _TimeoutMonitor(engine)
  91. engine.timeout_monitor.subscribe()
  92. engine.autoreload = process.plugins.Autoreloader(engine)
  93. engine.autoreload.subscribe()
  94. engine.thread_manager = process.plugins.ThreadManager(engine)
  95. engine.thread_manager.subscribe()
  96. engine.signal_handler = process.plugins.SignalHandler(engine)
  97. from cherrypy import _cpserver
  98. server = _cpserver.Server()
  99. server.subscribe()
  100.  
  101. def quickstart(root = None, script_name = '', config = None):
  102.     if config:
  103.         _global_conf_alias.update(config)
  104.     
  105.     if root is not None:
  106.         tree.mount(root, script_name, config)
  107.     
  108.     if hasattr(engine, 'signal_handler'):
  109.         engine.signal_handler.subscribe()
  110.     
  111.     if hasattr(engine, 'console_control_handler'):
  112.         engine.console_control_handler.subscribe()
  113.     
  114.     engine.start()
  115.     engine.block()
  116.  
  117.  
  118. try:
  119.     from threading import local as _local
  120. except ImportError:
  121.     from cherrypy._cpthreadinglocal import local as _local
  122.  
  123.  
  124. class _Serving(_local):
  125.     __metaclass__ = _AttributeDocstrings
  126.     request = _cprequest.Request(_http.Host('127.0.0.1', 80), _http.Host('127.0.0.1', 1111))
  127.     request__doc = '\n    The request object for the current thread. In the main thread,\n    and any threads which are not receiving HTTP requests, this is None.'
  128.     response = _cprequest.Response()
  129.     response__doc = '\n    The response object for the current thread. In the main thread,\n    and any threads which are not receiving HTTP requests, this is None.'
  130.     
  131.     def load(self, request, response):
  132.         self.request = request
  133.         self.response = response
  134.  
  135.     
  136.     def clear(self):
  137.         self.__dict__.clear()
  138.  
  139.  
  140. serving = _Serving()
  141.  
  142. class _ThreadLocalProxy(object):
  143.     __slots__ = [
  144.         '__attrname__',
  145.         '__dict__']
  146.     
  147.     def __init__(self, attrname):
  148.         self.__attrname__ = attrname
  149.  
  150.     
  151.     def __getattr__(self, name):
  152.         child = getattr(serving, self.__attrname__)
  153.         return getattr(child, name)
  154.  
  155.     
  156.     def __setattr__(self, name, value):
  157.         if name in ('__attrname__',):
  158.             object.__setattr__(self, name, value)
  159.         else:
  160.             child = getattr(serving, self.__attrname__)
  161.             setattr(child, name, value)
  162.  
  163.     
  164.     def __delattr__(self, name):
  165.         child = getattr(serving, self.__attrname__)
  166.         delattr(child, name)
  167.  
  168.     
  169.     def _get_dict(self):
  170.         child = getattr(serving, self.__attrname__)
  171.         d = child.__class__.__dict__.copy()
  172.         d.update(child.__dict__)
  173.         return d
  174.  
  175.     __dict__ = property(_get_dict)
  176.     
  177.     def __getitem__(self, key):
  178.         child = getattr(serving, self.__attrname__)
  179.         return child[key]
  180.  
  181.     
  182.     def __setitem__(self, key, value):
  183.         child = getattr(serving, self.__attrname__)
  184.         child[key] = value
  185.  
  186.     
  187.     def __delitem__(self, key):
  188.         child = getattr(serving, self.__attrname__)
  189.         del child[key]
  190.  
  191.     
  192.     def __contains__(self, key):
  193.         child = getattr(serving, self.__attrname__)
  194.         return key in child
  195.  
  196.     
  197.     def __len__(self):
  198.         child = getattr(serving, self.__attrname__)
  199.         return len(child)
  200.  
  201.     
  202.     def __nonzero__(self):
  203.         child = getattr(serving, self.__attrname__)
  204.         return bool(child)
  205.  
  206.  
  207. request = _ThreadLocalProxy('request')
  208. response = _ThreadLocalProxy('response')
  209.  
  210. class _ThreadData(_local):
  211.     pass
  212.  
  213. thread_data = _ThreadData()
  214.  
  215. def _cherrypy_pydoc_resolve(thing, forceload = 0):
  216.     if isinstance(thing, _ThreadLocalProxy):
  217.         thing = getattr(serving, thing.__attrname__)
  218.     
  219.     return _pydoc._builtin_resolve(thing, forceload)
  220.  
  221.  
  222. try:
  223.     import pydoc as _pydoc
  224.     _pydoc._builtin_resolve = _pydoc.resolve
  225.     _pydoc.resolve = _cherrypy_pydoc_resolve
  226. except ImportError:
  227.     pass
  228.  
  229. from cherrypy import _cplogging
  230.  
  231. class _GlobalLogManager(_cplogging.LogManager):
  232.     
  233.     def __call__(self, *args, **kwargs):
  234.         
  235.         try:
  236.             log = request.app.log
  237.         except AttributeError:
  238.             log = self
  239.  
  240.         return log.error(*args, **kwargs)
  241.  
  242.     
  243.     def access(self):
  244.         
  245.         try:
  246.             return request.app.log.access()
  247.         except AttributeError:
  248.             return _cplogging.LogManager.access(self)
  249.  
  250.  
  251.  
  252. log = _GlobalLogManager()
  253. log.screen = True
  254. log.error_file = ''
  255. log.access_file = ''
  256.  
  257. def _buslog(msg, level):
  258.     log.error(msg, 'ENGINE', severity = level)
  259.  
  260. engine.subscribe('log', _buslog)
  261.  
  262. def expose(func = None, alias = None):
  263.     
  264.     def expose_(func):
  265.         func.exposed = True
  266.         if alias is not None:
  267.             if isinstance(alias, basestring):
  268.                 parents[alias.replace('.', '_')] = func
  269.             else:
  270.                 for a in alias:
  271.                     parents[a.replace('.', '_')] = func
  272.                 
  273.         
  274.         return func
  275.  
  276.     import sys
  277.     import types
  278.     if isinstance(func, (types.FunctionType, types.MethodType)):
  279.         if alias is None:
  280.             func.exposed = True
  281.             return func
  282.         parents = sys._getframe(1).f_locals
  283.         return expose_(func)
  284.     isinstance(func, (types.FunctionType, types.MethodType))
  285.     if func is None:
  286.         if alias is None:
  287.             parents = sys._getframe(1).f_locals
  288.             return expose_
  289.         parents = sys._getframe(1).f_locals
  290.         return expose_
  291.     func is None
  292.     parents = sys._getframe(1).f_locals
  293.     alias = func
  294.     return expose_
  295.  
  296.  
  297. def url(path = '', qs = '', script_name = None, base = None, relative = None):
  298.     if qs:
  299.         qs = '?' + qs
  300.     
  301.     if request.app:
  302.         if not path.startswith('/'):
  303.             pi = request.path_info
  304.             if request.is_index is True:
  305.                 if not pi.endswith('/'):
  306.                     pi = pi + '/'
  307.                 
  308.             elif request.is_index is False:
  309.                 if pi.endswith('/') and pi != '/':
  310.                     pi = pi[:-1]
  311.                 
  312.             
  313.             if path == '':
  314.                 path = pi
  315.             else:
  316.                 path = _urljoin(pi, path)
  317.         
  318.         if script_name is None:
  319.             script_name = request.script_name
  320.         
  321.         if base is None:
  322.             base = request.base
  323.         
  324.         newurl = base + script_name + path + qs
  325.     elif base is None:
  326.         base = server.base()
  327.     
  328.     if not script_name:
  329.         pass
  330.     path = '' + path
  331.     newurl = base + path + qs
  332.     if './' in newurl:
  333.         atoms = []
  334.         for atom in newurl.split('/'):
  335.             if atom == '.':
  336.                 continue
  337.             if atom == '..':
  338.                 atoms.pop()
  339.                 continue
  340.             atoms.append(atom)
  341.         
  342.         newurl = '/'.join(atoms)
  343.     
  344.     if relative is None:
  345.         relative = getattr(request.app, 'relative_urls', False)
  346.     
  347.     if relative == 'server':
  348.         newurl = '/' + '/'.join(newurl.split('/', 3)[3:])
  349.     elif relative:
  350.         old = url().split('/')[:-1]
  351.         new = newurl.split('/')
  352.         while old and new:
  353.             a = old[0]
  354.             b = new[0]
  355.             if a != b:
  356.                 break
  357.             
  358.             old.pop(0)
  359.             new.pop(0)
  360.         new = [
  361.             '..'] * len(old) + new
  362.         newurl = '/'.join(new)
  363.     
  364.     return newurl
  365.  
  366. from cherrypy import _cpconfig
  367. config = _global_conf_alias = _cpconfig.Config()
  368. from cherrypy import _cpchecker
  369. checker = _cpchecker.Checker()
  370. engine.subscribe('start', checker)
  371.