From 51afe847100a0846f7f8cb636a99ed61f0c0d028 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Mon, 27 Nov 2017 13:25:51 -0600 Subject: [PATCH] safe names should avoid Python keywords --- uproot/__init__.py | 4 ++++ uproot/rootio.py | 8 ++++++-- uproot/version.py | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/uproot/__init__.py b/uproot/__init__.py index d63bd4a4..2515d7df 100644 --- a/uproot/__init__.py +++ b/uproot/__init__.py @@ -31,6 +31,7 @@ # high-level entry points from uproot.rootio import open, xrootd from uproot.tree import iterate +from uproot.version import version from uproot.source.memmap import MemmapSource from uproot.source.file import FileSource @@ -42,3 +43,6 @@ # in the code, and are built programmatically to avoid duplication; Python's # inline docstring method doesn't accept non-literals) import uproot._help + +# don't expose uproot.uproot; it's ugly +del uproot diff --git a/uproot/rootio.py b/uproot/rootio.py index 6c874c29..63f5e39b 100644 --- a/uproot/rootio.py +++ b/uproot/rootio.py @@ -28,10 +28,11 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import keyword +import numbers import re import struct import sys -import numbers try: from urlparse import urlparse except ImportError: @@ -524,7 +525,10 @@ def _ftype2struct(fType): raise NotImplementedError(fType) def _safename(name): - return re.sub(b"[^a-zA-Z0-9]+", lambda bad: b"_" + b"".join(b"%02x" % ord(x) for x in bad.group(0)) + b"_", name).decode("ascii") + out = re.sub(b"[^a-zA-Z0-9]+", lambda bad: b"_" + b"".join(b"%02x" % ord(x) for x in bad.group(0)) + b"_", name).decode("ascii") + if keyword.iskeyword(out): + out = out + "__" + return out def _raise_notimplemented(streamertype, streamerdict, source, cursor): raise NotImplementedError("\n\nUnimplemented streamer type: {0}\n\nmembers: {1}\n\nfile contents:\n\n{2}".format(streamertype, streamerdict, cursor.hexdump(source))) diff --git a/uproot/version.py b/uproot/version.py index 10fae176..4571ba8d 100644 --- a/uproot/version.py +++ b/uproot/version.py @@ -30,7 +30,7 @@ import re -__version__ = "2.1.0" +__version__ = "2.1.1" version = __version__ version_info = tuple(re.split(r"[-\.]", __version__))