Skip to content

Commit

Permalink
#65 pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Emrys committed Nov 24, 2021
1 parent 528c7d8 commit 81b6e21
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 63 deletions.
17 changes: 8 additions & 9 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# skosprovider_heritagedata documentation build configuration file, created by
# sphinx-quickstart on Fri Sep 19 10:30:09 2014.
Expand Down Expand Up @@ -49,8 +48,8 @@
master_doc = 'index'

# General information about the project.
project = u'skosprovider_heritagedata'
copyright = u'2014-2017, Flanders Heritage Agency'
project = 'skosprovider_heritagedata'
copyright = '2014-2017, Flanders Heritage Agency'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -202,8 +201,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'skosprovider_heritagedata.tex', u'skosprovider\\_heritagedata Documentation',
u'Flanders Heritage Agency', 'manual'),
('index', 'skosprovider_heritagedata.tex', 'skosprovider\\_heritagedata Documentation',
'Flanders Heritage Agency', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -232,8 +231,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'skosprovider_heritagedata', u'skosprovider_heritagedata Documentation',
[u'Flanders Heritage Agency'], 1)
('index', 'skosprovider_heritagedata', 'skosprovider_heritagedata Documentation',
['Flanders Heritage Agency'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -246,8 +245,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'skosprovider_heritagedata', u'skosprovider_heritagedata Documentation',
u'Flanders Heritage Agency', 'skosprovider_heritagedata', 'One line description of project.',
('index', 'skosprovider_heritagedata', 'skosprovider_heritagedata Documentation',
'Flanders Heritage Agency', 'skosprovider_heritagedata', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
1 change: 0 additions & 1 deletion examples/expand.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
This script demonstrates using the HeritagedataProvider to expand a concept
'''
Expand Down
1 change: 0 additions & 1 deletion examples/find.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
This script demonstrates using the HeritagedataProvider to find the concepts with 'iron' in their label
'''
Expand Down
1 change: 0 additions & 1 deletion examples/period.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
This script demonstrates using the HeritagedataProvider to get the concept of
'POST MEDIEVAL'.
Expand Down
29 changes: 13 additions & 16 deletions skosprovider_heritagedata/providers.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# -*- coding: utf-8 -*-
'''
This module implements a :class:`skosprovider.providers.VocabularyProvider`
for http://www.heritagedata.org.
'''

import requests
from requests.exceptions import ConnectionError

import warnings
import logging
log = logging.getLogger(__name__)
import warnings

import requests
from language_tags import tags
from rdflib.namespace import SKOS

from requests.exceptions import ConnectionError
from skosprovider.exceptions import ProviderUnavailableException
from skosprovider.providers import VocabularyProvider

from skosprovider_heritagedata.utils import (
_split_uri,
uri_to_graph,
conceptscheme_from_uri,
things_from_graph
)
from skosprovider_heritagedata.utils import _split_uri
from skosprovider_heritagedata.utils import conceptscheme_from_uri
from skosprovider_heritagedata.utils import things_from_graph
from skosprovider_heritagedata.utils import uri_to_graph

log = logging.getLogger(__name__)


class HeritagedataProvider(VocabularyProvider):
"""A provider that can work with the Heritagedata services of
Expand Down Expand Up @@ -82,7 +79,7 @@ def get_by_id(self, id):
Returns False if non-existing id
"""
graph = uri_to_graph(
'%s/%s/%s.rdf' % (self.scheme_uri, "concepts", id),
'{}/{}/{}.rdf'.format(self.scheme_uri, "concepts", id),
session=self.session
)
if graph is False:
Expand Down Expand Up @@ -289,9 +286,9 @@ def _get_items(self, service, params, **kwargs):
try:
res = self.session.get(request, params=params)
except ConnectionError as e:
raise ProviderUnavailableException("Request could not be executed - Request: %s - Params: %s" % (request, params))
raise ProviderUnavailableException(f"Request could not be executed - Request: {request} - Params: {params}")
if res.status_code == 404:
raise ProviderUnavailableException("Service not found (status_code 404) - Request: %s - Params: %s" % (request, params))
raise ProviderUnavailableException(f"Service not found (status_code 404) - Request: {request} - Params: {params}")
res.encoding = 'utf-8'
result = res.json()
d = {}
Expand Down
36 changes: 13 additions & 23 deletions skosprovider_heritagedata/utils.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
# -*- coding: utf-8 -*-
'''
Utility functions for :mod:`skosprovider_heritagedata`.
'''

import requests
from skosprovider.skos import (
Concept,
Label,
Note,
ConceptScheme)
from skosprovider.exceptions import ProviderUnavailableException

import logging
import sys
import requests

log = logging.getLogger(__name__)

PY3 = sys.version_info[0] == 3

if PY3: # pragma: no cover
binary_type = bytes
else: # pragma: no cover
binary_type = str

import rdflib
import requests
from rdflib.namespace import DCTERMS
from rdflib.namespace import RDF
from rdflib.namespace import RDFS
from rdflib.namespace import SKOS
from rdflib.term import URIRef
from rdflib.namespace import RDF, SKOS, DC, DCTERMS, RDFS
from skosprovider.exceptions import ProviderUnavailableException
from skosprovider.skos import Concept
from skosprovider.skos import ConceptScheme
from skosprovider.skos import Label
from skosprovider.skos import Note

log = logging.getLogger(__name__)
PROV = rdflib.Namespace('http://www.w3.org/ns/prov#')

def conceptscheme_from_uri(conceptscheme_uri, **kwargs):
Expand Down Expand Up @@ -167,8 +157,8 @@ def uri_to_graph(uri, **kwargs):


def text_(s, encoding='latin-1', errors='strict'):
""" If ``s`` is an instance of ``binary_type``, return
""" If ``s`` is an instance of ``bytes``, return
``s.decode(encoding, errors)``, otherwise return ``s``"""
if isinstance(s, binary_type):
if isinstance(s, bytes):
return s.decode(encoding, errors)
return s
12 changes: 6 additions & 6 deletions tests/test_providers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from skosprovider_heritagedata.providers import (
HeritagedataProvider
)
from skosprovider.exceptions import ProviderUnavailableException
import unittest

from skosprovider.exceptions import ProviderUnavailableException

from skosprovider_heritagedata.providers import HeritagedataProvider


class HeritagedataProviderTests(unittest.TestCase):

def test_set_custom_session(self):
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_find_with_collection(self):

def test_find_collections(self):
r = HeritagedataProvider({'id': 'Heritagedata'}, scheme_uri='http://purl.org/heritagedata/schemes/eh_period').find({'type': 'collection'})
self.assertEquals(r, [])
self.assertEqual(r, [])

def test_find_wrong_type(self):
self.assertRaises(ValueError, HeritagedataProvider({'id': 'Heritagedata'}, scheme_uri='http://purl.org/heritagedata/schemes/eh_period').find, {'type': 'collectie'})
Expand Down
13 changes: 7 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
import unittest

from rdflib import Graph
from skosprovider.exceptions import ProviderUnavailableException

from skosprovider_heritagedata.utils import text_, uri_to_graph
from skosprovider_heritagedata.utils import text_
from skosprovider_heritagedata.utils import uri_to_graph


class UtilsTests(unittest.TestCase):
Expand All @@ -16,15 +17,15 @@ def tearDown(self):

def test_text(self):
res = text_(b'test123')
self.assertEqual(u'test123', res)
self.assertEqual('test123', res)

def test_text_unicode(self):
res = text_(u'test123')
self.assertEqual(u'test123', res)
res = text_('test123')
self.assertEqual('test123', res)

def test_text_utf8(self):
res = text_(b'LaPe\xc3\xb1a', 'utf-8')
self.assertEqual(u'LaPe\xf1a', res)
self.assertEqual('LaPe\xf1a', res)

def test_uri_to_graph(self):
res = uri_to_graph('http://purl.org/heritagedata/schemes/eh_period.rdf')
Expand Down

0 comments on commit 81b6e21

Please sign in to comment.