diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2014-10-26 12:56:28 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2014-10-26 12:56:28 +1300 |
commit | 974bd9d0f9f3d231ff99496c55ae40355398cfc6 (patch) | |
tree | 2f23cf909a4bec2e8e328f8f9aaca2770b939c3b /libpathod/language.py | |
parent | fc1fc80469dca11ff0241c4b263e4b39e5506ddd (diff) | |
download | mitmproxy-974bd9d0f9f3d231ff99496c55ae40355398cfc6.tar.gz mitmproxy-974bd9d0f9f3d231ff99496c55ae40355398cfc6.tar.bz2 mitmproxy-974bd9d0f9f3d231ff99496c55ae40355398cfc6.zip |
Resolve a quoting ambiguity in nested response specs
Diffstat (limited to 'libpathod/language.py')
-rw-r--r-- | libpathod/language.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/libpathod/language.py b/libpathod/language.py index d8e87145..42fffcf8 100644 --- a/libpathod/language.py +++ b/libpathod/language.py @@ -1,4 +1,3 @@ -from __future__ import print_function import operator import string import random @@ -15,6 +14,12 @@ import utils BLOCKSIZE = 1024 TRUNCATE = 1024 +def quote(s): + quotechar = s[0] + s = s[1:-1] + s = s.replace(quotechar, "\\" + quotechar) + return quotechar + s + quotechar + class FileAccessDenied(Exception): pass @@ -272,7 +277,7 @@ class ValueLiteral(_ValueLiteral): return e.setParseAction(lambda x: klass(*x)) def spec(self): - return '"%s"'%self.val.encode("string_escape") + return quote("'%s'"%self.val.encode("string_escape")) class ValueNakedLiteral(_ValueLiteral): @@ -551,17 +556,13 @@ class PathodSpec(_Token): self.value.get_generator(settings), ] - def quote(self, s): - quotechar = s[0] - s = s[1:-1] - s = s.replace(quotechar, "\\" + quotechar) - return quotechar + s + quotechar - def spec(self): - return "s%s"%(self.quote(self.value.spec())) + return "s%s"%(self.value.spec()) def freeze(self, settings): - return PathodSpec(ValueLiteral(self.parsed.freeze(settings).spec())) + f = self.parsed.freeze(settings).spec() + print [f] + return PathodSpec(ValueLiteral(f)) class Path(_Component): |