Use escaped_str functions for TokValueLiteral
This commit is contained in:
parent
daaa672d39
commit
1699592f09
|
@ -4,6 +4,7 @@ import abc
|
||||||
import pyparsing as pp
|
import pyparsing as pp
|
||||||
|
|
||||||
from six.moves import reduce
|
from six.moves import reduce
|
||||||
|
from netlib.utils import escaped_str_to_bytes, bytes_to_escaped_str
|
||||||
|
|
||||||
from .. import utils
|
from .. import utils
|
||||||
from . import generators, exceptions
|
from . import generators, exceptions
|
||||||
|
@ -108,7 +109,7 @@ class Token(object):
|
||||||
class _TokValueLiteral(Token):
|
class _TokValueLiteral(Token):
|
||||||
|
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self.val = val
|
self.val = escaped_str_to_bytes(str(val))
|
||||||
|
|
||||||
def get_generator(self, settings_):
|
def get_generator(self, settings_):
|
||||||
return self.val
|
return self.val
|
||||||
|
@ -133,7 +134,7 @@ class TokValueLiteral(_TokValueLiteral):
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def spec(self):
|
def spec(self):
|
||||||
inner = self.val.encode("string_escape")
|
inner = bytes_to_escaped_str(self.val)
|
||||||
inner = inner.replace(r"\'", r"\x27")
|
inner = inner.replace(r"\'", r"\x27")
|
||||||
return "'" + inner + "'"
|
return "'" + inner + "'"
|
||||||
|
|
||||||
|
@ -146,7 +147,7 @@ class TokValueNakedLiteral(_TokValueLiteral):
|
||||||
return e.setParseAction(lambda x: cls(*x))
|
return e.setParseAction(lambda x: cls(*x))
|
||||||
|
|
||||||
def spec(self):
|
def spec(self):
|
||||||
return self.val.encode("string_escape")
|
return bytes_to_escaped_str(self.val)
|
||||||
|
|
||||||
|
|
||||||
class TokValueGenerate(Token):
|
class TokValueGenerate(Token):
|
||||||
|
@ -164,7 +165,7 @@ class TokValueGenerate(Token):
|
||||||
|
|
||||||
def freeze(self, settings):
|
def freeze(self, settings):
|
||||||
g = self.get_generator(settings)
|
g = self.get_generator(settings)
|
||||||
return TokValueLiteral(g[:].encode("string_escape"))
|
return TokValueLiteral(bytes_to_escaped_str(g[:]))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def expr(cls):
|
def expr(cls):
|
||||||
|
@ -224,7 +225,7 @@ class TokValueFile(Token):
|
||||||
return generators.FileGenerator(s)
|
return generators.FileGenerator(s)
|
||||||
|
|
||||||
def spec(self):
|
def spec(self):
|
||||||
return "<'%s'" % self.path.encode("string_escape")
|
return "<'%s'" % bytes_to_escaped_str(self.path)
|
||||||
|
|
||||||
|
|
||||||
TokValue = pp.MatchFirst(
|
TokValue = pp.MatchFirst(
|
||||||
|
@ -576,4 +577,4 @@ class NestedMessage(Token):
|
||||||
|
|
||||||
def freeze(self, settings):
|
def freeze(self, settings):
|
||||||
f = self.parsed.freeze(settings).spec()
|
f = self.parsed.freeze(settings).spec()
|
||||||
return self.__class__(TokValueLiteral(f.encode("string_escape")))
|
return self.__class__(TokValueLiteral(bytes_to_escaped_str(f)))
|
||||||
|
|
Loading…
Reference in New Issue