Decode/encode as 'string_escape' when (de)serializing the registry.

Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
James Vega 2010-01-30 23:03:35 -05:00
parent 455b5631bc
commit e13d3d6943
2 changed files with 7 additions and 6 deletions

View File

@ -275,7 +275,7 @@ class Tokenizer(object):
def _handleToken(self, token):
if token[0] == token[-1] and token[0] in self.quotes:
token = token[1:-1]
token = token.decode('string-escape')
token = token.decode('string_escape')
return token
def _insideBrackets(self, lexer):

View File

@ -1,5 +1,6 @@
###
# Copyright (c) 2004-2005, Jeremiah Fincher
# Copyright (c) 2009-2010, James Vega
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -87,7 +88,7 @@ def open(filename, clear=False):
try:
(key, value) = re.split(r'(?<!\\):', acc, 1)
key = key.strip()
value = value.strip().replace('\\\\', '\\')
value = value.strip().decode('string_escape')
acc = ''
except ValueError:
raise InvalidRegistryFile, 'Error unpacking line %r' % acc
@ -143,7 +144,7 @@ def isValidRegistryName(name):
return len(name.split()) == 1 and not name.startswith('_')
def escape(name):
name = name.replace('\\', '\\\\')
name = name.encode('string_escape')
name = name.replace(':', '\\:')
name = name.replace('.', '\\.')
return name
@ -151,7 +152,7 @@ def escape(name):
def unescape(name):
name = name.replace('\\.', '.')
name = name.replace('\\:', ':')
name = name.replace('\\\\', '\\')
name = name.decode('string_escape')
return name
_splitRe = re.compile(r'(?<!\\)\.')
@ -345,7 +346,7 @@ class Value(Group):
return repr(self())
def serialize(self):
return str(self).replace('\\', '\\\\')
return str(self).encode('string_escape')
# We tried many, *many* different syntactic methods here, and this one was
# simply the best -- not very intrusive, easily overridden by subclasses,
@ -501,7 +502,7 @@ class NormalizedString(String):
self.__parent.setValue(s)
def serialize(self):
s = str(self).replace('\\', '\\\\')
s = self.__parent.serialize()
prefixLen = len(self._name) + 2
lines = textwrap.wrap(s, width=76-prefixLen)
last = len(lines)-1