diff options
| author | Joern Hees <dev@joernhees.de> | 2015-09-23 19:27:19 +0200 |
|---|---|---|
| committer | Joern Hees <dev@joernhees.de> | 2015-09-23 19:27:19 +0200 |
| commit | ad37869ed8569c51214e76c92c46487ed69a20be (patch) | |
| tree | 29649791d4ac73472c4e4956279b06ddd62f1770 | |
| parent | bdd70e69e37d8335ed3e2f2a2d9269db9c0cb244 (diff) | |
| download | rdflib-ad37869ed8569c51214e76c92c46487ed69a20be.tar.gz | |
introduced py3.5+ handling for better re.sub unmatched group handling
otherwise our workaround for
http://bugs.python.org/issue1519638 fails on py3.5+
| -rw-r--r-- | rdflib/plugins/sparql/operators.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/rdflib/plugins/sparql/operators.py b/rdflib/plugins/sparql/operators.py index 7fa840dc..92c92a6b 100644 --- a/rdflib/plugins/sparql/operators.py +++ b/rdflib/plugins/sparql/operators.py @@ -6,6 +6,7 @@ using setEvalFn """ +import sys import re import math import random @@ -234,7 +235,7 @@ def Builtin_REPLACE(expr, ctx): # Now this is ugly. # Python has a "feature" where unmatched groups return None # then re.sub chokes on this. - # see http://bugs.python.org/issue1519638 + # see http://bugs.python.org/issue1519638 , fixed and errs in py3.5 # this works around and hooks into the internal of the re module... @@ -260,7 +261,10 @@ def Builtin_REPLACE(expr, ctx): cFlag = reduce(pyop.or_, [flagMap.get(f, 0) for f in flags]) # @@FIXME@@ either datatype OR lang, NOT both - return Literal(re.sub(unicode(pattern), _r, text, cFlag), + + compat_r = unicode(replacement) if sys.version_info[:2] >= (3, 5) else _r + + return Literal(re.sub(unicode(pattern), compat_r, text, cFlag), datatype=text.datatype, lang=text.language) |
