Commit 672494a0 authored by Noé Gaumont's avatar Noé Gaumont 🐙
Browse files

feat: drop python2

BREAKING CHANGE:
parent 11109fc2a52d
......@@ -10,7 +10,6 @@ include:
- "templates/lint/flake8.yml" # will do the equivalent of 'tox -e flake8'
- "templates/lint/check-manifest.yml" # will do the equivalent of 'tox -e check-manifest'
- "templates/lint/yamllint.yml" # will do the equivalent of 'tox -e yamllint'
- "templates/tests/py27.yml" # will do the equivalent of 'tox -e py27'
- "templates/tests/py3.yml" # will do the equivalent of 'tox -e py3'
- "templates/create-release-on-heptapod.yml" # this will create a release on heptapod
- "templates/upload-to-pypi.yml" # on a new mercurial tag (expected to be done with release-new), will push a release on pypi
......
......@@ -17,8 +17,6 @@
"""
import sys
from six import text_type, binary_type
def register_skos_concept_rdf_list_mapping(reg):
"""Register minimal SKOS mapping at the concept level (for use in
......@@ -92,6 +90,6 @@ def to_unicode(obj):
"""Turn some object (usually an exception) to unicode"""
try:
# The exception message might already be a unicode string.
return text_type(obj)
return str(obj)
except UnicodeDecodeError:
return binary_type(obj).decode(sys.getdefaultencoding(), 'ignore')
return bytes(obj).decode(sys.getdefaultencoding(), 'ignore')
......@@ -15,8 +15,7 @@ description = '"SKOS implementation for cubicweb"'
web = 'http://www.cubicweb.org/project/%s' % distname
__depends__ = {
'cubicweb': '>= 3.24.0',
'six': '>= 1.4.0',
'cubicweb': '>= 3.26.0',
}
__recommends__ = {
'rdflib': '>= 4.1',
......@@ -27,5 +26,6 @@ classifiers = [
'Environment :: Web Environment',
'Framework :: CubicWeb',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: JavaScript',
]
......@@ -16,9 +16,6 @@
"""SKOS dataimport utilities."""
from six import text_type
from six.moves import map
from cubicweb import schema
from cubicweb.dataimport.importer import (ExtEntity, ExtEntitiesImporter, RelationMapping,
cwuri2eid, use_extid_as_cwuri)
......@@ -195,7 +192,7 @@ class SKOSExtEntitiesImporter(ExtEntitiesImporter):
for _, object_uri in relations:
if object_uri not in self.extid2eid:
extentity = ExtEntity('ExternalUri', object_uri,
values=dict(uri=text_type(object_uri),
cwuri=text_type(object_uri)))
values=dict(uri=str(object_uri),
cwuri=str(object_uri)))
self.prepare_insert_entity(extentity)
return super(SKOSExtEntitiesImporter, self).prepare_insert_deferred_relations(deferred)
......@@ -15,8 +15,6 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-skos entity classes"""
from six.moves import filter
from logilab.common.decorators import cachedproperty
from cubicweb.predicates import is_instance
......
......@@ -15,8 +15,6 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-skos hooks"""
from six import text_type
from yams import ValidationError
from cubicweb import _
......@@ -128,7 +126,7 @@ class CheckPreferredLabelOp(hook.DataOperationMixIn, hook.Operation):
def precommit_event(self):
concept_labels = dict((label.label_of[0].eid, label) for label in self.get_data())
concept_eids = ',' . join(text_type(concept_eid) for concept_eid in concept_labels)
concept_eids = ',' . join(str(concept_eid) for concept_eid in concept_labels)
rql = ('Any C WHERE EXISTS('
'C preferred_label L, L language_code LC, '
'C preferred_label L2, L2 language_code LC, '
......
......@@ -17,8 +17,6 @@
import csv
from itertools import count
from six import text_type
from cubicweb import _
from cubicweb.dataimport import ucsvreader
......@@ -40,7 +38,7 @@ class LCSV2RDF(object):
"""
def __init__(self, stream, delimiter=None, encoding='utf-8',
uri_generator=None, uri_cls=text_type, default_lang=None):
uri_generator=None, uri_cls=str, default_lang=None):
""" check stream validity and init attribute"""
if delimiter is None:
sample = stream.read(1024).decode('utf-8')
......@@ -52,7 +50,7 @@ class LCSV2RDF(object):
counter = count()
def uri_generator(val):
return text_type(next(counter)) + val
return str(next(counter)) + val
self.uri_gen = uri_generator
self.prefixes = {'skos': 'http://www.w3.org/2004/02/skos/core#',
......
......@@ -16,9 +16,7 @@
"""Utilities for RDF import/export"""
from os.path import abspath, splitext
from six.moves.urllib.parse import urlparse
from six import PY2, text_type, string_types
from urllib.parse import urlparse
from cubicweb.dataimport.importer import ExtEntity
......@@ -27,11 +25,11 @@ TYPE_PREDICATE_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
SAME_AS_PREDICATE_URI = 'http://www.w3.org/2002/07/owl#sameAs'
class unicode_with_language(text_type): # pylint: disable=invalid-name
class unicode_with_language(str): # pylint: disable=invalid-name
"""Extend an unicode string to hold a .lang attribute as well"""
def __new__(cls, content, lang):
self = text_type.__new__(cls, content)
self = str.__new__(cls, content)
self.lang = lang
return self
......@@ -40,14 +38,14 @@ class unicode_with_language(text_type): # pylint: disable=invalid-name
def __eq__(self, other):
if isinstance(other, unicode_with_language):
return (text_type(self), self.lang) == (text_type(other), other.lang)
return (str(self), self.lang) == (str(other), other.lang)
return False
def __ne__(self, other):
return not self == other
def __hash__(self):
return hash((text_type(self), self.lang))
return hash((str(self), self.lang))
def normalize_uri(uri, prefixes, raise_on_error=False):
......@@ -68,7 +66,7 @@ def normalize_uri(uri, prefixes, raise_on_error=False):
def permanent_url(entity):
"""Return permanent URL for the given entity (`<site url>/<eid>`)."""
return entity._cw.build_url(text_type(entity.eid))
return entity._cw.build_url(str(entity.eid))
EXTENSION_FORMAT_MAP = {
......@@ -257,7 +255,7 @@ class AbstractRDFGraph(object):
if not isinstance(obj, self.uri):
if isinstance(obj, unicode_with_language):
try:
obj = self._literal(text_type(obj), lang=obj.lang)
obj = self._literal(str(obj), lang=obj.lang)
# an exception may be raised if the library doesn't like specified
# language (e.g. rdflib check them using a regexp), but we don't
# know at this point which kind of exception so catch Exception
......@@ -280,8 +278,6 @@ class LibRDFRDFGraph(AbstractRDFGraph):
_py_xsd_map = {
int: 'http://www.w3.org/2001/XMLSchema#integer',
}
if PY2:
_py_xsd_map[int] = 'http://www.w3.org/2001/XMLSchema#long' # noqa
_xsd_py_map = dict((v, k) for k, v in _py_xsd_map.items())
......@@ -299,7 +295,7 @@ class LibRDFRDFGraph(AbstractRDFGraph):
def _load(self, source, rdf_format):
"""Add RDF triplets from a file path or URL into the graph."""
assert isinstance(source, string_types), \
assert isinstance(source, str), \
'{0}._load() expect a path or an URL as source'.format(self.__class__.__name__)
if ':/' not in source:
source = 'file://' + abspath(source)
......@@ -323,10 +319,10 @@ class LibRDFRDFGraph(AbstractRDFGraph):
try:
datatype = self._py_xsd_map[type(value)]
except KeyError:
return self._node(literal=text_type(value))
return self._node(literal=str(value))
else:
datatype = self.uri(datatype)
return self._node(literal=text_type(value), datatype=datatype)
return self._node(literal=str(value), datatype=datatype)
return self._node(literal=value, language=str(lang))
def _py_literal(self, node):
......@@ -427,18 +423,18 @@ class RDFLibRDFGraph(AbstractRDFGraph):
def uris_for_type(self, type_uri):
"""Return an iterator on URIs of the given RDF type"""
for subj in self._graph.subjects(self._namespace.RDF.type, self.uri(type_uri)):
yield text_type(subj)
yield str(subj)
def triples(self):
"""Yield every triples in the graph."""
for subj, pred, obj in self._graph.triples((None, None, None)):
if isinstance(obj, self.uri):
obj = text_type(obj)
obj = str(obj)
elif getattr(obj, 'language', None) is not None:
obj = unicode_with_language(obj.toPython(), obj.language)
else:
obj = obj.toPython()
yield text_type(subj), text_type(pred), obj
yield str(subj), str(pred), obj
def objects(self, entity_uri, predicate_uri):
"""Return an iterator on object URIs or literals that are linked to `entity_uri` through
......@@ -446,7 +442,7 @@ class RDFLibRDFGraph(AbstractRDFGraph):
"""
for obj in self._graph.objects(self.uri(entity_uri), self.uri(predicate_uri)):
if isinstance(obj, self.uri):
yield text_type(obj)
yield str(obj)
elif getattr(obj, 'language', None) is not None:
yield unicode_with_language(obj.toPython(), obj.language)
else:
......@@ -457,7 +453,7 @@ class RDFLibRDFGraph(AbstractRDFGraph):
`predicate_uri`.
"""
for subj in self._graph.subjects(self.uri(predicate_uri), self.uri(entity_uri)):
yield text_type(subj)
yield str(subj)
def default_graph():
......
......@@ -28,8 +28,6 @@ This file contains generic import code, the datafeed parser and the repository s
from hashlib import md5
from uuid import uuid4
from six.moves import map
from cubicweb import dataimport
from cubicweb.dataimport.importer import (
ExtEntity,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment