1 """cssutils helper
2 """
3 __all__ = ['Deprecated', 'normalize']
4 __docformat__ = 'restructuredtext'
5 __version__ = '$Id: errorhandler.py 1234 2008-05-22 20:26:12Z cthedot $'
6
7 import re
8
10 """This is a decorator which can be used to mark functions
11 as deprecated. It will result in a warning being emitted
12 when the function is used.
13
14 It accepts a single paramter ``msg`` which is shown with the warning.
15 It should contain information which function or method to use instead.
16 """
19
21 def newFunc(*args, **kwargs):
22 import warnings
23 warnings.warn("Call to deprecated method %r. %s" %
24 (func.__name__, self.msg),
25 category=DeprecationWarning,
26 stacklevel=2)
27 return func(*args, **kwargs)
28 newFunc.__name__ = func.__name__
29 newFunc.__doc__ = func.__doc__
30 newFunc.__dict__.update(func.__dict__)
31 return newFunc
32
33
34 _simpleescapes = re.compile(ur'(\\[^0-9a-fA-F])').sub
35
37 """
38 normalizes x, namely:
39
40 - remove any \ before non unicode sequences (0-9a-zA-Z) so for
41 x=="c\olor\" return "color" (unicode escape sequences should have
42 been resolved by the tokenizer already)
43 - lowercase
44 """
45 if x:
46 def removeescape(matchobj):
47 return matchobj.group(0)[1:]
48 x = _simpleescapes(removeescape, x)
49 return x.lower()
50 else:
51 return x
52