1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17  """ 
 18  =============================== 
 19   WSGI Tackling Framework (WTF) 
 20  =============================== 
 21   
 22  WSGI Tackling Framework (WTF). 
 23  """ 
 24  __author__ = u"Andr\xe9 Malo" 
 25  __docformat__ = "restructuredtext en" 
 26  __license__ = "Apache License, Version 2.0" 
 27  __version__ = ('0.8.25', False, 4271) 
 28   
 29   
 30 -class Error(Exception): 
  31      """ Base exception for this package """ 
 32      pass 
  33   
 35      """ Base warning for this package """ 
 36   
 37      @classmethod 
 38 -    def emit(cls, message, stacklevel=1): 
  39          """ Emit a warning of this very category """ 
 40          import warnings as _warnings 
 41          _warnings.warn(message, cls, max(1, stacklevel) + 1) 
   42   
 45      """ Extend _urllib.quote and _urllib.quote_plus 
 46   
 47      :Parameters: 
 48       - `envkey`: The environment key to lookup. If this key is set and ``1`` 
 49         the charset definition won't be fixed and this function is a no-op. 
 50         If unset or ``None``, no lookup is made. 
 51   
 52      :Types: 
 53       - `envkey`: ``str`` 
 54      """ 
 55      import os 
 56      if envkey is not None and os.environ.get(envkey) == '1': 
 57          return 
 58   
 59      import urllib 
 60      from wtf import webutil 
 61      urllib.quote = webutil.quote 
 62      urllib.quote_plus = webutil.quote_plus 
 63      urllib.unquote = webutil.unquote 
 64      urllib.unquote_plus = webutil.unquote_plus 
  65   
 68      """ 
 69      Fixup cp1252 codec in order to use it as a real superset of latin-1 
 70   
 71      :Parameters: 
 72       - `envkey`: The environment key to lookup. If this key is set and ``1`` 
 73         the charset definition won't be fixed and this function is a no-op. 
 74         If unset or ``None``, no lookup is made. 
 75   
 76      :Types: 
 77       - `envkey`: ``str`` 
 78      """ 
 79      import os 
 80      if envkey is not None and os.environ.get(envkey) == '1': 
 81          return 
 82   
 83      import codecs 
 84      from encodings import cp1252 
 85   
 86      try: 
 87          dmap = cp1252.decoding_map  
 88      except AttributeError: 
 89          dtable = list(cp1252.decoding_table) 
 90          codepoint = 0 
 91          try: 
 92              while True: 
 93                  codepoint = dtable.index(u'\ufffe', codepoint) 
 94                  dtable[codepoint] = unichr(codepoint) 
 95          except ValueError: 
 96               
 97              pass 
 98          dtable = u''.join(dtable) 
 99          cp1252.decoding_table = dtable 
100          cp1252.encoding_table = codecs.charmap_build(dtable) 
101      else: 
102           
103          for key, value in dmap.iteritems(): 
104              if value is None: 
105                  dmap[key] = key 
106          cp1252.encoding_map = codecs.make_encoding_map(dmap) 
 107   
110      """ 
111      Register default 
112   
113      :Parameters: 
114       - `envkey`: The environment key to lookup. If this environment variable 
115         is set and ``1`` nothing will be registered and and this function 
116         is a no-op. If unset or ``None``, no lookup is made. 
117   
118      :Types: 
119       - `envkey`: ``str`` 
120      """ 
121      import os 
122      if envkey is not None and os.environ.get(envkey) == '1': 
123          return 
124   
125      from wtf.opi import register, daemon 
126      register('daemon', daemon.DaemonOPI) 
127   
128      from wtf.opi.worker import register, threaded, single 
129      register('threaded', threaded.ThreadedWorker) 
130      register('single', single.SingleWorker) 
131   
132      from wtf.impl import register, scgi, http 
133      register('scgi', scgi.SCGIServer) 
134      register('http', http.HTTPServer) 
 135   
138      """ 
139      Factory for creating a module factory 
140   
141      :Parameters: 
142       - `envkey`: Name of the environment variable which has to be "1" in 
143         order to disable the C override. 
144   
145      :Types: 
146       - `envkey`: ``str`` 
147   
148      :return: Module factory function 
149      :rtype: ``callable`` 
150      """ 
151      import os 
152      enabled = envkey is None or os.environ.get(envkey) != '1' 
153      if enabled: 
154          def module_factory(modname): 
155              """ 
156              Module factory 
157   
158              :Parameters: 
159               - `modname`: dotted module name relative to the wtf package 
160   
161              :Types: 
162               - `modname`: ``str`` 
163   
164              :return: The imported module or ``None`` on import disabled or 
165                       error 
166              :rtype: ``module`` 
167              """ 
168              try: 
169                  mod = __import__( 
170                      'wtf.%s' % modname, globals(), locals(), ['*'] 
171                  ) 
172              except ImportError: 
173                  mod = None 
174              return mod 
 175      else: 
176          def module_factory(modname): 
177              """ 
178              Module factory 
179   
180              :Parameters: 
181               - `modname`: dotted module name relative to the wtf package 
182   
183              :Types: 
184               - `modname`: ``str`` 
185   
186              :return: The imported module or ``None`` on import disabled or 
187                       error 
188              :rtype: ``module`` 
189              """ 
190               
191   
192              return None 
193      module_factory.enabled = enabled  
194      return module_factory 
195   
196   
197  c_override = c_override('WTF_NO_C_OVERRIDE') 
198  _fixcp1252('WTF_NO_CP1252_OVERRIDE') 
199  _extendquotes('WTF_NO_QUOTE_OVERRIDE') 
200  _register_defaults('WTF_NO_REGISTER_DEFAULT') 
201   
202  from wtf import util as _util 
203   
204   
205   
206   
207  version = _util.Version(*__version__) 
208   
209  __all__ = _util.find_public(globals()) 
210  del _util 
211