diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-10-29 16:31:35 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-10-29 16:31:35 +1300 |
commit | 747eafd10703d5a93003e410469771f883df68b5 (patch) | |
tree | 5a5c4d0b35519169f57432461509f1f1ee45b85d /libpathod | |
parent | 8741600ce770ac949550a3d7f3eac7cbbfd7456e (diff) | |
download | mitmproxy-747eafd10703d5a93003e410469771f883df68b5.tar.gz mitmproxy-747eafd10703d5a93003e410469771f883df68b5.tar.bz2 mitmproxy-747eafd10703d5a93003e410469771f883df68b5.zip |
Add a .spec method to the token ABC, and to all tokens.
Diffstat (limited to 'libpathod')
-rw-r--r-- | libpathod/language.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/libpathod/language.py b/libpathod/language.py index 6fa39f6a..2dceefa5 100644 --- a/libpathod/language.py +++ b/libpathod/language.py @@ -309,6 +309,12 @@ class _Spec(object): """ return None + def spec(self): # pragma: no cover + """ + A parseable specification for this token. + """ + return None + class Raw(_Spec): @classmethod @@ -316,6 +322,9 @@ class Raw(_Spec): e = pp.Literal("r").suppress() return e.setParseAction(lambda x: klass(*x)) + def spec(self): + return "r" + class _Component(_Spec): """ @@ -357,6 +366,9 @@ class Header(_Header): e += Value return e.setParseAction(lambda x: klass(*x)) + def spec(self): + return "h%s=%s"%(self.key.spec(), self.value.spec()) + class ShortcutContentType(_Header): def __init__(self, value): @@ -368,6 +380,9 @@ class ShortcutContentType(_Header): e = e + Value return e.setParseAction(lambda x: klass(*x)) + def spec(self): + return "c%s"%(self.value.spec()) + class ShortcutLocation(_Header): def __init__(self, value): @@ -379,6 +394,9 @@ class ShortcutLocation(_Header): e = e + Value return e.setParseAction(lambda x: klass(*x)) + def spec(self): + return "l%s"%(self.value.spec()) + class Body(_Component): def __init__(self, value): @@ -395,6 +413,9 @@ class Body(_Component): self.value.get_generator(settings), ] + def spec(self): + return "b%s"%(self.value.spec()) + class Path(_Component): def __init__(self, value): @@ -412,6 +433,9 @@ class Path(_Component): self.value.get_generator(settings), ] + def spec(self): + return "%s"%(self.value.spec()) + class Method(_Component): methods = [ @@ -445,6 +469,12 @@ class Method(_Component): self.value.get_generator(settings) ] + def spec(self): + s = self.value.spec() + if s[1:-1].lower() in self.methods: + s = s[1:-1].lower() + return "%s"%s + class Code(_Component): def __init__(self, code): @@ -458,12 +488,14 @@ class Code(_Component): def values(self, settings): return [LiteralGenerator(self.code)] + def spec(self): + return "%s"%(self.code) + class Reason(_Component): def __init__(self, value): self.value = value - @classmethod def expr(klass): e = pp.Literal("m").suppress() @@ -473,6 +505,9 @@ class Reason(_Component): def values(self, settings): return [self.value.get_generator(settings)] + def spec(self): + return "m%s"%(self.value.spec()) + class _Action(_Spec): """ |