Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
safe names should avoid Python keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Nov 27, 2017
1 parent f698a9d commit 51afe84
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions uproot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 6 additions & 2 deletions uproot/rootio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion uproot/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import re

__version__ = "2.1.0"
__version__ = "2.1.1"
version = __version__
version_info = tuple(re.split(r"[-\.]", __version__))

Expand Down

0 comments on commit 51afe84

Please sign in to comment.