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 288d7c6e02
commit 0540513387
2 changed files with 7 additions and 7 deletions

View File

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

View File

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