Show More
@@ -35,12 +35,22 b' if ispy3:' | |||||
35 | import builtins |
|
35 | import builtins | |
36 | import functools |
|
36 | import functools | |
37 |
|
37 | |||
|
38 | def sysstr(s): | |||
|
39 | """Return a keyword str to be passed to Python functions such as | |||
|
40 | getattr() and str.encode() | |||
|
41 | ||||
|
42 | This never raises UnicodeDecodeError. Non-ascii characters are | |||
|
43 | considered invalid and mapped to arbitrary but unique code points | |||
|
44 | such that 'sysstr(a) != sysstr(b)' for all 'a != b'. | |||
|
45 | """ | |||
|
46 | if isinstance(s, builtins.str): | |||
|
47 | return s | |||
|
48 | return s.decode(u'latin-1') | |||
|
49 | ||||
38 | def _wrapattrfunc(f): |
|
50 | def _wrapattrfunc(f): | |
39 | @functools.wraps(f) |
|
51 | @functools.wraps(f) | |
40 | def w(object, name, *args): |
|
52 | def w(object, name, *args): | |
41 | if isinstance(name, bytes): |
|
53 | return f(object, sysstr(name), *args) | |
42 | name = name.decode(u'utf-8') |
|
|||
43 | return f(object, name, *args) |
|
|||
44 | return w |
|
54 | return w | |
45 |
|
55 | |||
46 | # these wrappers are automagically imported by hgloader |
|
56 | # these wrappers are automagically imported by hgloader | |
@@ -50,6 +60,10 b' if ispy3:' | |||||
50 | setattr = _wrapattrfunc(builtins.setattr) |
|
60 | setattr = _wrapattrfunc(builtins.setattr) | |
51 | xrange = builtins.range |
|
61 | xrange = builtins.range | |
52 |
|
62 | |||
|
63 | else: | |||
|
64 | def sysstr(s): | |||
|
65 | return s | |||
|
66 | ||||
53 | stringio = io.StringIO |
|
67 | stringio = io.StringIO | |
54 | empty = _queue.Empty |
|
68 | empty = _queue.Empty | |
55 | queue = _queue.Queue |
|
69 | queue = _queue.Queue |
General Comments 0
You need to be logged in to leave comments.
Login now