Show More
@@ -35,12 +35,22 b' if ispy3:' | |||
|
35 | 35 | import builtins |
|
36 | 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 | 50 | def _wrapattrfunc(f): |
|
39 | 51 | @functools.wraps(f) |
|
40 | 52 | def w(object, name, *args): |
|
41 | if isinstance(name, bytes): | |
|
42 | name = name.decode(u'utf-8') | |
|
43 | return f(object, name, *args) | |
|
53 | return f(object, sysstr(name), *args) | |
|
44 | 54 | return w |
|
45 | 55 | |
|
46 | 56 | # these wrappers are automagically imported by hgloader |
@@ -50,6 +60,10 b' if ispy3:' | |||
|
50 | 60 | setattr = _wrapattrfunc(builtins.setattr) |
|
51 | 61 | xrange = builtins.range |
|
52 | 62 | |
|
63 | else: | |
|
64 | def sysstr(s): | |
|
65 | return s | |
|
66 | ||
|
53 | 67 | stringio = io.StringIO |
|
54 | 68 | empty = _queue.Empty |
|
55 | 69 | queue = _queue.Queue |
General Comments 0
You need to be logged in to leave comments.
Login now