mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Decode/encode as 'string_escape' when (de)serializing the registry.
Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
parent
455b5631bc
commit
e13d3d6943
@ -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):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2004-2005, Jeremiah Fincher
|
# Copyright (c) 2004-2005, Jeremiah Fincher
|
||||||
|
# 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
|
||||||
@ -87,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
|
||||||
@ -143,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
|
||||||
@ -151,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'(?<!\\)\.')
|
||||||
@ -345,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,
|
||||||
@ -501,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
|
||||||
|
Loading…
Reference in New Issue
Block a user