Skip to content

Commit

Permalink
Merge pull request #405 from OpenDataServices/2022-11-15
Browse files Browse the repository at this point in the history
2022 11 15
  • Loading branch information
James (ODSC) authored Nov 16, 2022
2 parents c2e5de7 + 9ac2f7b commit 2c6bda3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
strategy:
matrix:
python-version: [ '3.6', '3.7', '3.8', '3.9']
jsonref-version: ["==0.3", ">1"]
steps:
- uses: actions/checkout@v2
- name: Setup python
Expand All @@ -21,6 +22,7 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
- run: pip install --upgrade -r requirements_dev.txt
- run: pip install 'jsonref${{ matrix.jsonref-version }}'
- run: py.test --cov .
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Make work with multiple versions of jsonref

## [0.18.1] - 2022-10-28

### Fixed
Expand Down
21 changes: 10 additions & 11 deletions flattentool/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,16 @@ class JsonLoaderLocalRefUsedWhenLocalRefsDisabled(Exception):
pass


class JsonLoaderLocalRefsDisabled(jsonref.JsonLoader):
def __call__(self, uri, **kwargs):
if self.is_ref_local(uri):
raise JsonLoaderLocalRefUsedWhenLocalRefsDisabled(
"Local Ref Used When Local Refs Disabled: " + uri
)
else:
return super(JsonLoaderLocalRefsDisabled, self).__call__(uri, **kwargs)
def jsonloader_local_refs_disabled(uri, **kwargs):
if is_ref_local(uri):
raise JsonLoaderLocalRefUsedWhenLocalRefsDisabled(
"Local Ref Used When Local Refs Disabled: " + uri
)
return jsonref.jsonloader(uri, **kwargs)


def is_ref_local(self, uri):
return uri[:7].lower() != "http://" and uri[:8].lower() != "https://"
def is_ref_local(uri):
return uri[:7].lower() != "http://" and uri[:8].lower() != "https://"


class SchemaParser(object):
Expand Down Expand Up @@ -159,7 +158,7 @@ def __init__(
self.root_schema_dict = jsonref.load(
schema_file,
object_pairs_hook=OrderedDict,
loader=JsonLoaderLocalRefsDisabled(),
loader=jsonloader_local_refs_disabled,
)
else:
if sys.version_info[:2] > (3, 0):
Expand Down
10 changes: 3 additions & 7 deletions flattentool/tests/test_schema_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import pytest

from flattentool.schema import (
JsonLoaderLocalRefsDisabled,
SchemaParser,
get_property_type_set,
)
from flattentool.schema import SchemaParser, get_property_type_set, is_ref_local
from flattentool.sheet import Sheet

type_string = {"type": "string"}
Expand Down Expand Up @@ -767,7 +763,7 @@ def test_schema_from_uri(httpserver):
"data", test_json_loader_local_refs_disabled_is_ref_local_data_returns_true
)
def test_json_loader_local_refs_disabled_is_ref_local_true(data):
assert True == JsonLoaderLocalRefsDisabled().is_ref_local(data)
assert True == is_ref_local(data)


test_json_loader_local_refs_disabled_is_ref_local_data_returns_false = [
Expand All @@ -784,4 +780,4 @@ def test_json_loader_local_refs_disabled_is_ref_local_true(data):
"data", test_json_loader_local_refs_disabled_is_ref_local_data_returns_false
)
def test_json_loader_local_refs_disabled_is_ref_local_true(data): # noqa
assert False == JsonLoaderLocalRefsDisabled().is_ref_local(data)
assert False == is_ref_local(data)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run(self):


install_requires = [
"jsonref<1",
"jsonref",
"schema",
"openpyxl>=2.6,!=3.0.2",
"pytz",
Expand Down

0 comments on commit 2c6bda3

Please sign in to comment.