On 05/24/2012 12:20 PM, Mike Frysinger wrote:
> +                     # A normal line will end in the two bytes: <\> <\n>.  
> So decoding
> +                     # that will result in python thinking the <\n> is being 
> escaped
> +                     # and eat the single <\> which makes it hard for us to 
> detect.
> +                     # Instead, strip the newline (which we know all lines 
> have), and
> +                     # append a <0>.  Then when python escapes it, if the 
> line ended
> +                     # in a <\>, we'll end up with a <\0> marker to key off 
> of.  This
> +                     # shouldn't be a problem with any valid ebuild ...
> +                     line_escaped = (line.rstrip('\n') + 
> '0').decode('string_escape')

That decode('string_escape') method won't work in python3, because the
str object doesn't have a decode method. I think something like this
will work with both python3 and python2:

import codecs

unicode_escape_codec = codecs.lookup('unicode_escape')

def unicode_escape(s):
        return unicode_escape_codec(s)[0]

line_escaped = unicode_escape(line.rstrip('\n') + '0')
-- 
Thanks,
Zac

Reply via email to