Skip to content

Commit 8e828c9

Browse files
committed
fixed some identantion issue based on contribution from #143
1 parent d55719f commit 8e828c9

File tree

6 files changed

+56
-46
lines changed

6 files changed

+56
-46
lines changed

SPARQLWrapper/KeyCaseInsensitiveDict.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
:license: `W3C® Software notice and license <http://www.w3.org/Consortium/Legal/copyright-software>`_
2020
"""
2121

22+
2223
class KeyCaseInsensitiveDict(dict):
2324
"""
2425
A simple implementation of a key case-insensitive dictionary

SPARQLWrapper/SPARQLExceptions.py

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(self, response=None):
4040

4141
super(SPARQLWrapperException, self).__init__(formatted_msg)
4242

43+
4344
class EndPointInternalError(SPARQLWrapperException):
4445
"""
4546
Exception type for Internal Server Error responses. Usually HTTP response status code ``500``.
@@ -63,6 +64,7 @@ class EndPointNotFound(SPARQLWrapperException):
6364

6465
msg = "it was impossible to connect with the endpoint in that address, check if it is correct"
6566

67+
6668
class Unauthorized(SPARQLWrapperException):
6769
"""
6870
Access is denied due to invalid credentials (unauthorized). Usually HTTP response status code ``401``.
@@ -72,6 +74,7 @@ class Unauthorized(SPARQLWrapperException):
7274

7375
msg = "access is denied due to invalid credentials (unauthorized). Check the credentials"
7476

77+
7578
class URITooLong(SPARQLWrapperException):
7679
"""
7780
The URI requested by the client is longer than the server is willing to interpret. Usually HTTP response status code ``414``.

SPARQLWrapper/SmartWrapper.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
######################################################################################
2828

29+
2930
class Value(object):
3031
"""
3132
Class encapsulating a single binding for a variable.
@@ -120,8 +121,8 @@ def __init__(self, retval):
120121
self.bindings = []
121122
try:
122123
for b in self.fullResult['results']['bindings']:
123-
# this is a single binding. It is a dictionary per variable; each value is a dictionary again that has to be
124-
# converted into a Value instance
124+
# This is a single binding. It is a dictionary per variable; each value is a dictionary again
125+
# that has to be converted into a Value instance
125126
newBind = {}
126127
for key in self.variables:
127128
if key in b:
@@ -246,7 +247,7 @@ def _nonSliceCase(key):
246247
continue
247248
if True in [k in b for k in no_keys]:
248249
continue
249-
# if we got that far, we shouild be all right!
250+
# if we got that far, we should be all right!
250251
retval.append(b)
251252
# if retval is of zero length, no hit; an exception should be raised to stay within the python style
252253
if len(retval) == 0:

SPARQLWrapper/Wrapper.py

+24-22
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
_allowedFormats.append(JSONLD)
137137
_RDF_POSSIBLE = _RDF_POSSIBLE + _RDF_JSONLD
138138
except ImportError:
139-
#warnings.warn("JSON-LD disabled because no suitable support has been found", RuntimeWarning)
139+
# warnings.warn("JSON-LD disabled because no suitable support has been found", RuntimeWarning)
140140
pass
141141

142142
# This is very ugly. The fact is that the key for the choice of the output format is not defined.
@@ -233,7 +233,7 @@ def __init__(self, endpoint, updateEndpoint=None, returnFormat=XML, defaultGraph
233233
self.passwd = None
234234
self.http_auth = BASIC
235235
self._defaultGraph = defaultGraph
236-
self.onlyConneg = False # Only Content Negotiation
236+
self.onlyConneg = False # Only Content Negotiation
237237
self.customHttpHeaders = {}
238238

239239
if returnFormat in _allowedFormats:
@@ -538,7 +538,7 @@ def _parseQueryType(self, query):
538538
if r_queryType in _allowedQueryTypes:
539539
return r_queryType
540540
else:
541-
#raise Exception("Illegal SPARQL Query; must be one of SELECT, ASK, DESCRIBE, or CONSTRUCT")
541+
# raise Exception("Illegal SPARQL Query; must be one of SELECT, ASK, DESCRIBE, or CONSTRUCT")
542542
warnings.warn("unknown query type '%s'" % r_queryType, RuntimeWarning)
543543
return SELECT
544544

@@ -624,9 +624,9 @@ def _getRequestEncodedParameters(self, query=None):
624624
# "tsv", "rdf+xml" and "json-ld" are not supported as a correct "output"/"format" parameter value but "text/tab-separated-values" or "application/rdf+xml" are a valid values,
625625
# and there is no problem to send both (4store does not support unexpected values).
626626
if self.returnFormat in [TSV, JSONLD, RDFXML]:
627-
acceptHeader = self._getAcceptHeader() # to obtain the mime-type "text/tab-separated-values" or "application/rdf+xml"
627+
acceptHeader = self._getAcceptHeader() # to obtain the mime-type "text/tab-separated-values" or "application/rdf+xml"
628628
if "*/*" in acceptHeader:
629-
acceptHeader = "" # clear the value in case of "*/*"
629+
acceptHeader = "" # clear the value in case of "*/*"
630630
query_parameters[f] += [acceptHeader]
631631

632632
pairs = (
@@ -648,9 +648,9 @@ def _getAcceptHeader(self):
648648
acceptHeader = ",".join(_SPARQL_XML)
649649
elif self.returnFormat == JSON:
650650
acceptHeader = ",".join(_SPARQL_JSON)
651-
elif self.returnFormat == CSV: # Allowed for SELECT and ASK (https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/#query-success) but only described for SELECT (https://www.w3.org/TR/sparql11-results-csv-tsv/)
651+
elif self.returnFormat == CSV: # Allowed for SELECT and ASK (https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/#query-success) but only described for SELECT (https://www.w3.org/TR/sparql11-results-csv-tsv/)
652652
acceptHeader = ",".join(_CSV)
653-
elif self.returnFormat == TSV: # Allowed for SELECT and ASK (https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/#query-success) but only described for SELECT (https://www.w3.org/TR/sparql11-results-csv-tsv/)
653+
elif self.returnFormat == TSV: # Allowed for SELECT and ASK (https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/#query-success) but only described for SELECT (https://www.w3.org/TR/sparql11-results-csv-tsv/)
654654
acceptHeader = ",".join(_TSV)
655655
else:
656656
acceptHeader = ",".join(_ALL)
@@ -688,7 +688,7 @@ def _createRequest(self):
688688
request = None
689689

690690
if self.isSparqlUpdateRequest():
691-
#protocol details at http://www.w3.org/TR/sparql11-protocol/#update-operation
691+
# protocol details at http://www.w3.org/TR/sparql11-protocol/#update-operation
692692
uri = self.updateEndpoint
693693

694694
if self.method != POST:
@@ -703,7 +703,7 @@ def _createRequest(self):
703703
request.add_header("Content-Type", "application/x-www-form-urlencoded")
704704
request.data = self._getRequestEncodedParameters(("update", self.queryString)).encode('ascii')
705705
else:
706-
#protocol details at http://www.w3.org/TR/sparql11-protocol/#query-operation
706+
# protocol details at http://www.w3.org/TR/sparql11-protocol/#query-operation
707707
uri = self.endpoint
708708

709709
if self.method == POST:
@@ -844,6 +844,7 @@ class QueryResult(object):
844844
:type requestedFormat: string
845845
846846
"""
847+
847848
def __init__(self, result):
848849
"""
849850
:param result: HTTP response stemming from a :func:`SPARQLWrapper.query` call, or a tuple with the expected format: (response, format).
@@ -916,7 +917,7 @@ def _convertRDF(self):
916917
retval = ConjunctiveGraph()
917918
# (DEPRECATED) this is a strange hack. If the publicID is not set, rdflib (or the underlying xml parser) makes a funny
918919
# (DEPRECATED) (and, as far as I could see, meaningless) error message...
919-
retval.load(self.response) # (DEPRECATED) publicID=' ')
920+
retval.load(self.response) # (DEPRECATED) publicID=' ')
920921
return retval
921922

922923
def _convertN3(self):
@@ -959,7 +960,7 @@ def _convertJSONLD(self):
959960
"""
960961
from rdflib import ConjunctiveGraph
961962
retval = ConjunctiveGraph()
962-
retval.load(self.response, format='json-ld')# (DEPRECATED), publicID=' ')
963+
retval.load(self.response, format='json-ld') # (DEPRECATED), publicID=' ')
963964
return retval
964965

965966
def convert(self):
@@ -976,6 +977,7 @@ def convert(self):
976977
977978
:return: the converted query result. See the conversion methods for more details.
978979
"""
980+
979981
def _content_type_in_list(real, expected):
980982
""" Internal method for checking if the content-type header received matches any of the content types of the expected list.
981983
@@ -1006,7 +1008,7 @@ def _validate_format(format_name, allowed, mime, requested):
10061008

10071009
# TODO. In order to compare properly, the requested QueryType (SPARQL Query Form) is needed. For instance, the unexpected N3 requested for a SELECT would return XML
10081010
if "content-type" in self.info():
1009-
ct = self.info()["content-type"] # returned Content-Type value
1011+
ct = self.info()["content-type"] # returned Content-Type value
10101012

10111013
if _content_type_in_list(ct, _SPARQL_XML):
10121014
_validate_format("XML", [XML], ct, self.requestedFormat)
@@ -1060,7 +1062,7 @@ def _content_type_in_list(real, expected):
10601062
return True in [real.find(mime) != -1 for mime in expected]
10611063

10621064
if "content-type" in self.info():
1063-
ct = self.info()["content-type"] # returned Content-Type value
1065+
ct = self.info()["content-type"] # returned Content-Type value
10641066

10651067
if _content_type_in_list(ct, _SPARQL_XML):
10661068
return XML
@@ -1106,22 +1108,22 @@ def print_results(self, minWidth=None):
11061108
width = self.__get_results_width(results)
11071109
index = 0
11081110
for var in results["head"]["vars"]:
1109-
print ("?" + var).ljust(width[index]), "|",
1111+
print(("?" + var).ljust(width[index]), "|",)
11101112
index += 1
1111-
print
1112-
print "=" * (sum(width) + 3 * len(width))
1113+
print()
1114+
print("=" * (sum(width) + 3 * len(width)))
11131115
for result in results["results"]["bindings"]:
11141116
index = 0
11151117
for var in results["head"]["vars"]:
11161118
result_value = self.__get_prettyprint_string_sparql_var_result(result[var])
1117-
print result_value.ljust(width[index]), "|",
1119+
print(result_value.ljust(width[index]), "|",)
11181120
index += 1
1119-
print
1121+
print()
11201122

11211123
def __get_results_width(self, results, minWidth=2):
11221124
width = []
11231125
for var in results["head"]["vars"]:
1124-
width.append(max(minWidth, len(var)+1))
1126+
width.append(max(minWidth, len(var) + 1))
11251127
for result in results["results"]["bindings"]:
11261128
index = 0
11271129
for var in results["head"]["vars"]:
@@ -1135,9 +1137,9 @@ def __get_prettyprint_string_sparql_var_result(self, result):
11351137
lang = result.get("xml:lang", None)
11361138
datatype = result.get("datatype", None)
11371139
if lang is not None:
1138-
value += "@"+lang
1140+
value += "@" + lang
11391141
if datatype is not None:
1140-
value += " ["+datatype+"]"
1142+
value += " [" + datatype + "]"
11411143
return value
11421144

11431145
def __str__(self):
@@ -1148,7 +1150,7 @@ def __str__(self):
11481150
.. versionadded:: 1.8.3
11491151
"""
11501152
fullname = self.__module__ + "." + self.__class__.__name__
1151-
str_requestedFormat = '"requestedFormat" : '+repr(self.requestedFormat)
1153+
str_requestedFormat = '"requestedFormat" : ' + repr(self.requestedFormat)
11521154
str_url = self.response.url
11531155
str_code = self.response.code
11541156
str_headers = self.response.info()

custom_fixers/fix_urllib2.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from lib2to3.fixer_base import BaseFix
22
from lib2to3.fixer_util import Name
33

4+
45
class FixUrllib2(BaseFix):
56
PATTERN = "power< fixprefix='urllib2' trailer< '.' '_opener' > >|power< fixprefix='urllib2' trailer< '.' '_opener' > trailer< '.' handlers='handlers' > >"
67

setup.py

+23-21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
try:
77
from ez_setup import use_setuptools
8+
89
use_setuptools()
910
except:
1011
pass
@@ -13,12 +14,14 @@
1314

1415
try:
1516
import six
17+
1618
py3 = six.PY3
1719
except:
1820
py3 = sys.version_info[0] >= 3
1921

2022
# metadata
2123
import re
24+
2225
_version_re = re.compile(r'__version__\s*=\s*"(.*)"')
2326
_authors_re = re.compile(r'__authors__\s*=\s*"(.*)"')
2427
_url_re = re.compile(r'__url__\s*=\s*"(.*)"')
@@ -41,23 +44,22 @@
4144
with open('requirements.txt', 'r') as f:
4245
_install_requires = [line.rstrip('\n') for line in f]
4346

44-
4547
setup(
46-
name = 'SPARQLWrapper',
47-
version = version,
48-
description = 'SPARQL Endpoint interface to Python',
49-
long_description = 'This is a wrapper around a SPARQL service. It helps in creating the query URI and, possibly, convert the result into a more manageable format.',
50-
license = 'W3C SOFTWARE NOTICE AND LICENSE',
51-
author = authors,
52-
url = url,
53-
download_url = 'https://github.com/RDFLib/sparqlwrapper/releases',
54-
platforms = ['any'],
55-
packages = ['SPARQLWrapper'],
56-
install_requires = _install_requires,
57-
extras_require = {
48+
name='SPARQLWrapper',
49+
version=version,
50+
description='SPARQL Endpoint interface to Python',
51+
long_description='This is a wrapper around a SPARQL service. It helps in creating the query URI and, possibly, convert the result into a more manageable format.',
52+
license='W3C SOFTWARE NOTICE AND LICENSE',
53+
author=authors,
54+
url=url,
55+
download_url='https://github.com/RDFLib/sparqlwrapper/releases',
56+
platforms=['any'],
57+
packages=['SPARQLWrapper'],
58+
install_requires=_install_requires,
59+
extras_require={
5860
'keepalive': ['keepalive>=0.5'],
59-
},
60-
classifiers = [
61+
},
62+
classifiers=[
6163
'Development Status :: 5 - Production/Stable',
6264
'Intended Audience :: Developers',
6365
'License :: OSI Approved :: W3C License',
@@ -73,14 +75,14 @@
7375
'Programming Language :: Python :: Implementation :: CPython',
7476
'Programming Language :: Python :: Implementation :: PyPy',
7577
'Topic :: Software Development :: Libraries :: Python Modules',
76-
],
77-
keywords = ['python', 'sparql', 'rdf', 'rdflib'],
78-
use_2to3 = True,
79-
use_2to3_fixers = ['custom_fixers'],
80-
project_urls={
78+
],
79+
keywords=['python', 'sparql', 'rdf', 'rdflib'],
80+
use_2to3=True,
81+
use_2to3_fixers=['custom_fixers'],
82+
project_urls={
8183
'Home': 'https://rdflib.github.io/sparqlwrapper/',
8284
'Documentation': 'https://sparqlwrapper.readthedocs.io',
8385
'Source': 'https://github.com/RDFLib/sparqlwrapper',
8486
'Tracker': 'https://github.com/RDFLib/sparqlwrapper/issues',
85-
}
87+
}
8688
)

0 commit comments

Comments
 (0)