summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2008-06-04 18:03:59 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2008-06-04 18:03:59 +0000
commit9d032b39b001e2c1cddc2d6747e2e242b422252b (patch)
tree9da955aa1542cbf16152ef638c8046907a982b68
parentdb03c8c28ec1a654b1ce9397c2c2be6b67ecc849 (diff)
downloadpyparsing-9d032b39b001e2c1cddc2d6747e2e242b422252b.tar.gz
Removed dependency on xml.sax.saxutils.escape, and implemented it inline as _xml_escape.
Fixed typo in ParseResults.insert, referencing invalid var 'j' (replaced with 'index') Fixed error in replaceHTMLEntity, mapping &quot; to ', now correctly maps to " git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/src@158 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--CHANGES16
-rw-r--r--pyparsing.py25
2 files changed, 33 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index 8bf458f..8ccd35d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,22 @@
Change Log
==========
+Version 1.5.1 - ???, 2008
+--------------------------
+- Added optional parseAll argument to parseFile, to be consistent
+ with parseAll argument to parseString. Posted by pboucher on the
+ pyparsing wiki, thanks!
+
+- Removed dependency on xml.sax.saxutils.escape, and included
+ internal implementation instead - proposed by Mike Droettboom on
+ the pyparsing mailing list, thanks Mike! Also fixed erroneous
+ mapping in replaceHTMLEntity of &quot to ', now correctly maps
+ to ".
+
+- Fixed typo in ParseResults.insert, found by Alejandro Dubrovsky,
+ good catch!
+
+
Version 1.5.0 - June, 2008
--------------------------
This version of pyparsing includes work on two long-standing
diff --git a/pyparsing.py b/pyparsing.py
index e232834..e9a87e7 100644
--- a/pyparsing.py
+++ b/pyparsing.py
@@ -68,7 +68,6 @@ import copy,sys
import warnings
import re
import sre_constants
-import xml.sax.saxutils
#~ sys.stderr.write( "testing pyparsing module, version %s, %s\n" % (__version__,__versionTime__ ) )
__all__ = [
@@ -135,6 +134,16 @@ def _str2dict(strg):
return dict( [(c,0) for c in strg] )
#~ return set( [c for c in strg] )
+def _xml_escape(data):
+ """Escape &, <, >, ', etc. in a string of data."""
+
+ # ampersand must be replaced first
+ from_symbols = '&><"'
+ to_symbols = ['&'+s+';' for s in "amp gt lt quot".split()]
+ for from_,to_ in zip(from_symbols, to_symbols):
+ data = data.replace(from_, to_)
+ return data
+
class _Constants(object):
pass
@@ -375,7 +384,7 @@ class ParseResults(object):
for name in self.__tokdict:
occurrences = self.__tokdict[name]
for k, (value, position) in enumerate(occurrences):
- occurrences[k] = _ParseResultsWithOffset(value, position + (position > j))
+ occurrences[k] = _ParseResultsWithOffset(value, position + (position > index))
def items( self ):
"""Returns all named result keys and values as a list of tuples."""
@@ -518,7 +527,7 @@ class ParseResults(object):
continue
else:
resTag = "ITEM"
- xmlBodyText = xml.sax.saxutils.escape(_ustr(res))
+ xmlBodyText = _xml_escape(_ustr(res))
out += [ nl, nextLevelIndent, "<", resTag, ">",
xmlBodyText,
"</", resTag, ">" ]
@@ -3481,16 +3490,16 @@ def nestedExpr(opener="(", closer=")", content=None, ignoreExpr=quotedString):
return ret
def indentedBlock(blockStatementExpr, indentStack, indent=True):
- """Helper method for defining space-delimited indentation blocks, such as
+ """Helper method for defining space-delimited indentation blocks, such as
those used to define block statements in Python source code.
-
+
Parameters:
- - blockStatementExpr - expression defining syntax of statement that
+ - blockStatementExpr - expression defining syntax of statement that
is repeated within the indented block
- indentStack - list created by caller to manage indentation stack
(multiple statementWithIndentedBlock expressions within a single grammar
should share a common indentStack)
- - indent - boolean indicating whether block must be indented beyond the
+ - indent - boolean indicating whether block must be indented beyond the
the current level; set to False for block of left-most statements
(default=True)
@@ -3537,7 +3546,7 @@ punc8bit = srange(r"[\0xa1-\0xbf\0xd7\0xf7]")
anyOpenTag,anyCloseTag = makeHTMLTags(Word(alphas,alphanums+"_:"))
commonHTMLEntity = Combine(_L("&") + oneOf("gt lt amp nbsp quot").setResultsName("entity") +";")
-_htmlEntityMap = dict(zip("gt lt amp nbsp quot".split(),"><& '"))
+_htmlEntityMap = dict(zip("gt lt amp nbsp quot".split(),'><& "'))
replaceHTMLEntity = lambda t : t.entity in _htmlEntityMap and _htmlEntityMap[t.entity] or None
# it's easy to get these comment structures wrong - they're very common, so may as well make them available