summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-08-14 08:49:38 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-08-14 08:49:38 +0000
commitaa8d421bbcf5e218c611e444d0297f6855148964 (patch)
treea099c16b3329f5f9cf494736fc7c204e97975c9a
parent3e8e5bbe2489138460cd65c021107ccf6c607e25 (diff)
downloadpyparsing-aa8d421bbcf5e218c611e444d0297f6855148964.tar.gz
enhanced runTests to better handle non-parsing exceptions
modified pyparsing_common.convertToDate and convertToDatetime parse actions to convert ValueErrors raised by strptime to ParseExceptions git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@419 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/pyparsing.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/pyparsing.py b/src/pyparsing.py
index a99140c..8935cb8 100644
--- a/src/pyparsing.py
+++ b/src/pyparsing.py
@@ -58,7 +58,7 @@ The pyparsing module handles some of the problems that are typically vexing when
"""
__version__ = "2.1.8"
-__versionTime__ = "13 Aug 2016 02:22 UTC"
+__versionTime__ = "14 Aug 2016 08:43 UTC"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -2284,6 +2284,10 @@ class ParserElement(object):
out.append("FAIL: " + str(pe))
success = success and failureTests
result = pe
+ except Exception as exc:
+ out.append("FAIL-EXCEPTION: " + str(exc))
+ success = success and failureTests
+ result = exc
if printResults:
if fullDump:
@@ -5443,7 +5447,12 @@ class pyparsing_common:
prints::
[datetime.date(1999, 12, 31)]
"""
- return lambda s,l,t: datetime.strptime(t[0], fmt).date()
+ def cvt_fn(s,l,t):
+ try:
+ return datetime.strptime(t[0], fmt).date()
+ except ValueError as ve:
+ raise ParseException(s, l, str(ve))
+ return cvt_fn
@staticmethod
def convertToDatetime(fmt="%Y-%m-%dT%H:%M:%S.%f"):
@@ -5460,7 +5469,12 @@ class pyparsing_common:
prints::
[datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)]
"""
- return lambda s,l,t: datetime.strptime(t[0], fmt)
+ def cvt_fn(s,l,t):
+ try:
+ return datetime.strptime(t[0], fmt)
+ except ValueError as ve:
+ raise ParseException(s, l, str(ve))
+ return cvt_fn
iso8601_date = Regex(r'(?P<year>\d{4})(?:-(?P<month>\d\d)(?:-(?P<day>\d\d))?)?').setName("ISO8601 date")
"ISO8601 date (C{yyyy-mm-dd})"