1 |
On 05/24/2012 12:52 PM, Zac Medico wrote: |
2 |
> On 05/24/2012 12:20 PM, Mike Frysinger wrote: |
3 |
>> + # A normal line will end in the two bytes: <\> <\n>. So decoding |
4 |
>> + # that will result in python thinking the <\n> is being escaped |
5 |
>> + # and eat the single <\> which makes it hard for us to detect. |
6 |
>> + # Instead, strip the newline (which we know all lines have), and |
7 |
>> + # append a <0>. Then when python escapes it, if the line ended |
8 |
>> + # in a <\>, we'll end up with a <\0> marker to key off of. This |
9 |
>> + # shouldn't be a problem with any valid ebuild ... |
10 |
>> + line_escaped = (line.rstrip('\n') + '0').decode('string_escape') |
11 |
> |
12 |
> That decode('string_escape') method won't work in python3, because the |
13 |
> str object doesn't have a decode method. I think something like this |
14 |
> will work with both python3 and python2: |
15 |
> |
16 |
> import codecs |
17 |
> |
18 |
> unicode_escape_codec = codecs.lookup('unicode_escape') |
19 |
> |
20 |
> def unicode_escape(s): |
21 |
> return unicode_escape_codec(s)[0] |
22 |
|
23 |
- return unicode_escape_codec(s)[0] |
24 |
+ return unicode_escape_codec.decode(s)[0] |
25 |
|
26 |
> line_escaped = unicode_escape(line.rstrip('\n') + '0') |
27 |
|
28 |
|
29 |
-- |
30 |
Thanks, |
31 |
Zac |