aboutsummaryrefslogtreecommitdiffstats
path: root/pathod/language
diff options
context:
space:
mode:
Diffstat (limited to 'pathod/language')
-rw-r--r--pathod/language/__init__.py6
-rw-r--r--pathod/language/base.py16
2 files changed, 14 insertions, 8 deletions
diff --git a/pathod/language/__init__.py b/pathod/language/__init__.py
index 32199e08..10da93ba 100644
--- a/pathod/language/__init__.py
+++ b/pathod/language/__init__.py
@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
import itertools
import time
@@ -5,8 +7,8 @@ import pyparsing as pp
from . import http, http2, websockets, writer, exceptions
-from exceptions import *
-from base import Settings
+from .exceptions import *
+from .base import Settings
assert Settings # prevent pyflakes from messing with this
diff --git a/pathod/language/base.py b/pathod/language/base.py
index a4302998..54ca6492 100644
--- a/pathod/language/base.py
+++ b/pathod/language/base.py
@@ -3,9 +3,13 @@ import os
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
+
class Settings(object):
def __init__(
@@ -105,7 +109,7 @@ class Token(object):
class _TokValueLiteral(Token):
def __init__(self, val):
- self.val = val.decode("string_escape")
+ self.val = escaped_str_to_bytes(val)
def get_generator(self, settings_):
return self.val
@@ -130,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 + "'"
@@ -143,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):
@@ -161,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):
@@ -221,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(
@@ -573,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)))