Skip to content

Commit

Permalink
six: compare.py: headers and unicode --> text_type
Browse files Browse the repository at this point in the history
  • Loading branch information
joernhees committed Nov 18, 2016
1 parent df68f40 commit bdfb9b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
30 changes: 18 additions & 12 deletions rdflib/plugins/parsers/ntriples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

__doc__ = """
N-Triples Parser
License: GPL 2, W3C, BSD, or MIT
Expand All @@ -12,7 +16,15 @@
from rdflib.term import BNode as bNode
from rdflib.term import Literal

from rdflib.py3compat import cast_bytes, decodeUnicodeEscape

from ...py3compat import cast_bytes
from ...py3compat import decodeUnicodeEscape
from ...py3compat import ascii

from ...py3compat import BytesIO
from ...py3compat import string_types
from ...py3compat import text_type
from ...py3compat import unichr

__all__ = ['unquote', 'uriquote', 'Sink', 'NTriplesParser']

Expand All @@ -32,7 +44,7 @@
validate = False


class Node(unicode):
class Node(text_type):
pass


Expand All @@ -46,7 +58,7 @@ def __init__(self):

def triple(self, s, p, o):
self.length += 1
print (s, p, o)
print(s, p, o)

quot = {'t': u'\t', 'n': u'\n', 'r': u'\r', '"': u'"', '\\':
u'\\'}
Expand All @@ -59,7 +71,7 @@ def unquote(s):
"""Unquote an N-Triples string."""
if not validate:

if isinstance(s, unicode): # nquads
if isinstance(s, text_type): # nquads
s = decodeUnicodeEscape(s)
else:
s = s.decode('unicode-escape')
Expand Down Expand Up @@ -94,7 +106,7 @@ def unquote(s):
raise ParseError("Illegal literal character: %r" % s[0])
return u''.join(result)

r_hibyte = re.compile(ur'([\x80-\xFF])')
r_hibyte = re.compile(r'([\x80-\xFF])')


def uriquote(uri):
Expand Down Expand Up @@ -144,14 +156,8 @@ def parse(self, f):

def parsestring(self, s):
"""Parse s as an N-Triples string."""
if not isinstance(s, basestring):
if not isinstance(s, string_types):
raise ParseError("Item to parse must be a string instance.")
try:
from io import BytesIO
assert BytesIO
except ImportError:
from cStringIO import StringIO as BytesIO
assert BytesIO
f = BytesIO()
f.write(cast_bytes(s))
f.seek(0)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def setup_python3():
join(tmp_src, 'rdflib', 'plugins', 'parsers', 'notation3.py'),
join(tmp_src, 'rdflib', 'plugins', 'parsers', 'nquads.py'),
join(tmp_src, 'rdflib', 'plugins', 'parsers', 'nt.py'),
# join(tmp_src, 'rdflib', 'plugins', 'parsers', 'ntriples.py'),
join(tmp_src, 'rdflib', 'plugins', 'parsers', 'ntriples.py'),
# join(tmp_src, 'rdflib', 'plugins', 'parsers', 'pyMicrodata', '__init__.py'),
# join(tmp_src, 'rdflib', 'plugins', 'parsers', 'pyMicrodata', 'microdata.py'),
join(tmp_src, 'rdflib', 'plugins', 'parsers', 'pyMicrodata', 'registry.py'),
Expand Down

0 comments on commit bdfb9b0

Please sign in to comment.