Skip to content

Commit

Permalink
Merge pull request #44 from remorses/master
Browse files Browse the repository at this point in the history
Substituted requests package with urllib
  • Loading branch information
horejsek committed Mar 4, 2019
2 parents a185faa + a94b832 commit b45004e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
16 changes: 5 additions & 11 deletions fastjsonschema/ref_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from urllib.parse import unquote
from urllib.request import urlopen

import requests

from .exceptions import JsonSchemaException

Expand Down Expand Up @@ -47,21 +46,16 @@ def resolve_remote(uri, handlers):
.. note::
Requests_ library is used to fetch ``http`` or ``https``
requests from the remote ``uri``, if handlers does not
define otherwise.
For unknown schemes urlib is used with UTF-8 encoding.
.. _Requests: http://pypi.python.org/pypi/requests/
urllib library is used to fetch requests from the remote ``uri``
if handlers does notdefine otherwise.
"""
scheme = urlparse.urlsplit(uri).scheme
if scheme in handlers:
result = handlers[scheme](uri)
elif scheme in ['http', 'https']:
result = requests.get(uri).json()
else:
result = json.loads(urlopen(uri).read().decode('utf-8'))
req = urlopen(uri)
encoding = req.info().get_content_charset() or 'utf-8'
result = json.loads(req.read().decode(encoding),)
return result


Expand Down
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
name='fastjsonschema',
version=VERSION,
packages=['fastjsonschema'],

install_requires=[
'requests',
],
extras_require={
'devel': [
'colorama',
Expand Down
6 changes: 4 additions & 2 deletions tests/json_schema/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path

import pytest
import requests
from urllib.request import urlopen

from fastjsonschema import RefResolver, JsonSchemaException, compile, _get_code_generator_class

Expand All @@ -26,7 +26,9 @@
def remotes_handler(uri):
if uri in REMOTES:
return REMOTES[uri]
return requests.get(uri).json()
req = urlopen(uri)
encoding = req.info().get_content_charset() or 'utf-8'
return json.loads(req.read().decode(encoding),)


def resolve_param_values_and_ids(schema_version, suite_dir, ignored_suite_files=[], ignore_tests=[]):
Expand Down

0 comments on commit b45004e

Please sign in to comment.