Skip to content

Commit

Permalink
Merge pull request #241 from macisamuele/maci-reduce-usage-of-depreca…
Browse files Browse the repository at this point in the history
…ted-methods

Reduce usage of deprecated methods
  • Loading branch information
macisamuele committed May 27, 2019
2 parents faa0af7 + 203b577 commit c13bcd3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyramid_swagger/api.py
Expand Up @@ -233,7 +233,7 @@ def __init__(self, info):
def __call__(self, value, system):
response = system['request'].response
response.headers['Content-Type'] = 'application/x-yaml; charset=UTF-8'
return yaml.dump(value).encode('utf-8')
return yaml.safe_dump(value).encode('utf-8')


def build_swagger_20_swagger_schema_views(config):
Expand Down
14 changes: 13 additions & 1 deletion pyramid_swagger/load_schema.py
Expand Up @@ -7,13 +7,16 @@
from __future__ import unicode_literals

from collections import namedtuple
from copy import deepcopy

import jsonschema
import simplejson
from jsonschema import RefResolver
from jsonschema import validators
from jsonschema.exceptions import ValidationError
from jsonschema.validators import Draft3Validator
from jsonschema.validators import Draft4Validator
from six import iteritems

from pyramid_swagger.model import partial_path_match

Expand Down Expand Up @@ -195,9 +198,18 @@ def __init__(self, schema, validator):

@classmethod
def from_schema(cls, schema, resolver, validator_class):
type_checker = deepcopy(validator_class.TYPE_CHECKER)
type_checker.redefine_many({
type_name: lambda checker, value: all(check(value) for check in checks)
for type_name, checks in iteritems(EXTENDED_TYPES)
})
extended_validator_class = jsonschema.validators.extend(
validator_class,
type_checker=type_checker,
)
return cls(
schema,
validator_class(schema, resolver=resolver, types=EXTENDED_TYPES))
extended_validator_class(schema, resolver=resolver))

def validate(self, values):
"""Validate a :class:`dict` of values. If `self.schema` is falsy this
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -44,7 +44,7 @@
include_package_data=True,
install_requires=[
'bravado-core >= 4.8.4',
'jsonschema',
'jsonschema >= 3.0.0',
'pyramid',
'simplejson',
],
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/recursive_app_test.py
Expand Up @@ -13,7 +13,7 @@

DESERIALIZERS = {
'json': lambda r: json.loads(r.body.decode('utf-8')),
'yaml': lambda r: yaml.load(BytesIO(r.body)),
'yaml': lambda r: yaml.safe_load(BytesIO(r.body)),
}


Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/relative_ref_test.py
Expand Up @@ -16,7 +16,7 @@

DESERIALIZERS = {
'json': lambda r: json.loads(r.body.decode('utf-8')),
'yaml': lambda r: yaml.load(BytesIO(r.body)),
'yaml': lambda r: yaml.safe_load(BytesIO(r.body)),
}


Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/yaml_test.py
Expand Up @@ -87,7 +87,7 @@ def validate_json_response(response, expected_dict):

def validate_yaml_response(response, expected_dict):
assert response.headers['content-type'] == 'application/x-yaml; charset=UTF-8'
assert _strip_xmodel(yaml.load(response.body)) == expected_dict
assert _strip_xmodel(yaml.safe_load(response.body)) == expected_dict


def _rewrite_ref(ref, schema_format):
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_swagger_json_api_doc_route(testapp_with_base64, test_file, schema_forma

fname = 'tests/sample_schemas/yaml_app/%s.yaml' % test_file
with open(fname, 'r') as f:
expected_schema = yaml.load(f)
expected_schema = yaml.safe_load(f)

_recursively_rewrite_refs(expected_schema, schema_format)

Expand Down
4 changes: 2 additions & 2 deletions tests/api_test.py
Expand Up @@ -84,7 +84,7 @@ def test_resolve_nested_refs():
"""
os.environ["PYTHONHASHSEED"] = str(1)
with open('tests/sample_schemas/nested_defns/swagger.yaml') as swagger_spec:
spec_dict = yaml.load(swagger_spec)
spec_dict = yaml.safe_load(swagger_spec)
spec = Spec.from_dict(spec_dict, '')
assert spec.flattened_spec

Expand All @@ -108,7 +108,7 @@ def test_extenal_refs_no_empty_keys():
keys swagger specs.
"""
with open('tests/sample_schemas/external_refs/swagger.json') as swagger_spec:
spec_dict = yaml.load(swagger_spec)
spec_dict = yaml.safe_load(swagger_spec)
path = 'file:' + os.getcwd() + '/tests/sample_schemas/external_refs/swagger.json'
spec = Spec.from_dict(spec_dict, path)
flattened_spec = spec.flattened_spec
Expand Down

0 comments on commit c13bcd3

Please sign in to comment.