From 1699592f092b5f616ef1aa33b611ec6dabe7b255 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Sun, 15 May 2016 23:27:07 +0530 Subject: Use escaped_str functions for TokValueLiteral --- pathod/language/base.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'pathod') diff --git a/pathod/language/base.py b/pathod/language/base.py index c53e6b20..bc6da6ab 100644 --- a/pathod/language/base.py +++ b/pathod/language/base.py @@ -4,6 +4,7 @@ import abc import pyparsing as pp from six.moves import reduce +from netlib.utils import escaped_str_to_bytes, bytes_to_escaped_str from .. import utils from . import generators, exceptions @@ -108,7 +109,7 @@ class Token(object): class _TokValueLiteral(Token): def __init__(self, val): - self.val = val + self.val = escaped_str_to_bytes(str(val)) def get_generator(self, settings_): return self.val @@ -133,7 +134,7 @@ class TokValueLiteral(_TokValueLiteral): return v def spec(self): - inner = self.val.encode("string_escape") + inner = bytes_to_escaped_str(self.val) inner = inner.replace(r"\'", r"\x27") return "'" + inner + "'" @@ -146,7 +147,7 @@ class TokValueNakedLiteral(_TokValueLiteral): return e.setParseAction(lambda x: cls(*x)) def spec(self): - return self.val.encode("string_escape") + return bytes_to_escaped_str(self.val) class TokValueGenerate(Token): @@ -164,7 +165,7 @@ class TokValueGenerate(Token): def freeze(self, settings): g = self.get_generator(settings) - return TokValueLiteral(g[:].encode("string_escape")) + return TokValueLiteral(bytes_to_escaped_str(g[:])) @classmethod def expr(cls): @@ -224,7 +225,7 @@ class TokValueFile(Token): return generators.FileGenerator(s) def spec(self): - return "<'%s'" % self.path.encode("string_escape") + return "<'%s'" % bytes_to_escaped_str(self.path) TokValue = pp.MatchFirst( @@ -576,4 +577,4 @@ class NestedMessage(Token): def freeze(self, settings): f = self.parsed.freeze(settings).spec() - return self.__class__(TokValueLiteral(f.encode("string_escape"))) + return self.__class__(TokValueLiteral(bytes_to_escaped_str(f))) -- cgit v1.2.3