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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext'
  5. __version__ = '$Id: errorhandler.py 1234 2008-05-22 20:26:12Z cthedot $'
  6. import os
  7. import re
  8. import sys
  9. import urllib
  10.  
  11. class Deprecated(object):
  12.     
  13.     def __init__(self, msg):
  14.         self.msg = msg
  15.  
  16.     
  17.     def __call__(self, func):
  18.         
  19.         def newFunc(*args, **kwargs):
  20.             import warnings
  21.             warnings.warn('Call to deprecated method %r. %s' % (func.__name__, self.msg), category = DeprecationWarning, stacklevel = 2)
  22.             return func(*args, **kwargs)
  23.  
  24.         newFunc.__name__ = func.__name__
  25.         newFunc.__doc__ = func.__doc__
  26.         newFunc.__dict__.update(func.__dict__)
  27.         return newFunc
  28.  
  29.  
  30. _simpleescapes = re.compile(u'(\\\\[^0-9a-fA-F])').sub
  31.  
  32. def normalize(x):
  33.     if x:
  34.         
  35.         def removeescape(matchobj):
  36.             return matchobj.group(0)[1:]
  37.  
  38.         x = _simpleescapes(removeescape, x)
  39.         return x.lower()
  40.     return x
  41.  
  42.  
  43. def path2url(path):
  44.     return u'file:' + urllib.pathname2url(os.path.abspath(path))
  45.  
  46.  
  47. def pushtoken(token, tokens):
  48.     yield token
  49.     for t in tokens:
  50.         yield t
  51.     
  52.  
  53.  
  54. def string(value):
  55.     value = value.replace(u'\n', u'\\a ').replace(u'\r', u'\\d ').replace(u'\x0c', u'\\c ').replace(u'"', u'\\"')
  56.     if value.endswith(u'\\'):
  57.         value = value[:-1] + u'\\\\'
  58.     
  59.     return u'"%s"' % value
  60.  
  61.  
  62. def stringvalue(string):
  63.     return string.replace(u'\\' + string[0], string[0])[1:-1]
  64.  
  65. _match_forbidden_in_uri = re.compile(u'.*?[\\(\\)\\s\\;,\'"]', re.U).match
  66.  
  67. def uri(value):
  68.     if _match_forbidden_in_uri(value):
  69.         value = string(value)
  70.     
  71.     return u'url(%s)' % value
  72.  
  73.  
  74. def urivalue(uri):
  75.     uri = uri[uri.find('(') + 1:-1].strip()
  76.     if uri and uri[0] in '\'"' and uri[0] == uri[-1]:
  77.         return stringvalue(uri)
  78.     return uri
  79.  
  80.