summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenn Knowles <kenn.knowles@gmail.com>2013-05-29 11:17:05 -0400
committerKenn Knowles <kenn.knowles@gmail.com>2013-05-29 11:17:05 -0400
commitc46d04f4099fbbf55bf4194932cdc09d5a50827b (patch)
treecff7a9f5a08faad2993a545471a262462c3f47e2
parent9a05daf81960092af081383d60269f2df221c8d3 (diff)
downloadjsonpath-rw-c46d04f4099fbbf55bf4194932cdc09d5a50827b.tar.gz
Raise an informative error when docstrings have been stripped
-rw-r--r--.gitignore1
-rw-r--r--jsonpath_rw/lexer.py2
-rw-r--r--jsonpath_rw/parser.py7
3 files changed, 10 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index a1e3ce0..4185370 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.pyc
+*.pyo
*~
# Emacs
diff --git a/jsonpath_rw/lexer.py b/jsonpath_rw/lexer.py
index 35a4305..40ae898 100644
--- a/jsonpath_rw/lexer.py
+++ b/jsonpath_rw/lexer.py
@@ -13,6 +13,8 @@ class JsonPathLexer(object):
def __init__(self, debug=False):
self.debug = debug
+ if self.__doc__ == None:
+ raise Exception('Docstrings have been removed! By design of PLY, jsonpath-rw requires docstrings. You must not use PYTHONOPTIMIZE=2 or python -OO.')
def tokenize(self, string):
'''
diff --git a/jsonpath_rw/parser.py b/jsonpath_rw/parser.py
index 85d05d9..21bd5d3 100644
--- a/jsonpath_rw/parser.py
+++ b/jsonpath_rw/parser.py
@@ -14,9 +14,16 @@ def parse(string):
return JsonPathParser().parse(string)
class JsonPathParser(object):
+ '''
+ An LALR-parser for JsonPath
+ '''
+
tokens = JsonPathLexer.tokens
def __init__(self, debug=False, lexer_class=None):
+ if self.__doc__ == None:
+ raise Exception('Docstrings have been removed! By design of PLY, jsonpath-rw requires docstrings. You must not use PYTHONOPTIMIZE=2 or python -OO.')
+
self.debug = debug
self.lexer_class = lexer_class or JsonPathLexer # Crufty but works around statefulness in PLY