Python2 compatibility module

This commit is contained in:
p1c2u 2018-07-28 23:51:36 +01:00
parent f95608493a
commit a9d858e940
17 changed files with 41 additions and 35 deletions

View file

@ -2,6 +2,7 @@ language: python
sudo: false
matrix:
include:
- python: 2.7
- python: 3.4
- python: 3.5
- python: 3.6

View file

@ -1,8 +1,4 @@
# -*- coding: utf-8 -*-
"""Python 2.7 backward compatibility"""
import openapi_core._python27_patch
"""OpenAPI core module"""
from openapi_core.shortcuts import (
create_spec, validate_parameters, validate_body, validate_data,

View file

@ -1,14 +1,12 @@
import functools
"""OpenAPI core python 2.7 compatibility module"""
try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache
functools.lru_cache = lru_cache
try:
from functools import partialmethod
except ImportError:
from backports.functools_partialmethod import partialmethod
functools.partialmethod = partialmethod
__all__ = ['lru_cache', 'partialmethod']

View file

@ -1,5 +1,4 @@
from functools import lru_cache
from openapi_core.compat import lru_cache
from openapi_core.schema.components.models import Components
from openapi_core.schema.schemas.generators import SchemasGenerator

View file

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
"""OpenAPI core operations models module"""
from functools import lru_cache
from six import iteritems
from openapi_spec_validator.validators import PathItemValidator
from openapi_core.compat import lru_cache
from openapi_core.schema.operations.models import Operation
from openapi_core.schema.parameters.generators import ParametersGenerator
from openapi_core.schema.request_bodies.factories import RequestBodyFactory

View file

@ -1,8 +1,7 @@
"""OpenAPI core parameters generators module"""
from functools import lru_cache
from six import iteritems
from openapi_core.compat import lru_cache
from openapi_core.schema.parameters.factories import ParameterFactory

View file

@ -1,8 +1,7 @@
"""OpenAPI core paths generators module"""
from functools import lru_cache
from six import iteritems
from openapi_core.compat import lru_cache
from openapi_core.schema.operations.generators import OperationsGenerator
from openapi_core.schema.paths.models import Path

View file

@ -1,6 +1,5 @@
"""OpenAPI core request bodies factories module"""
from functools import lru_cache
from openapi_core.compat import lru_cache
from openapi_core.schema.media_types.generators import MediaTypeGenerator
from openapi_core.schema.request_bodies.models import RequestBody

View file

@ -1,8 +1,7 @@
"""OpenAPI core responses generators module"""
from functools import lru_cache
from six import iteritems
from openapi_core.compat import lru_cache
from openapi_core.schema.media_types.generators import MediaTypeGenerator
from openapi_core.schema.parameters.generators import ParametersGenerator
from openapi_core.schema.responses.models import Response

View file

@ -1,7 +1,7 @@
"""OpenAPI core schemas factories module"""
import logging
from functools import lru_cache
from openapi_core.compat import lru_cache
from openapi_core.schema.properties.generators import PropertiesGenerator
from openapi_core.schema.schemas.models import Schema

View file

@ -1,8 +1,7 @@
"""OpenAPI core servers generators module"""
from functools import lru_cache
from six import iteritems
from openapi_core.compat import lru_cache
from openapi_core.schema.servers.models import Server, ServerVariable

View file

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
"""OpenAPI core specs factories module"""
from functools import lru_cache
from openapi_spec_validator import openapi_v3_spec_validator
from openapi_core.compat import lru_cache
from openapi_core.schema.components.factories import ComponentsFactory
from openapi_core.schema.infos.factories import InfoFactory
from openapi_core.schema.paths.generators import PathsGenerator

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
"""OpenAPI core specs models module"""
import logging
from functools import partialmethod
from openapi_core.compat import partialmethod
from openapi_core.schema.operations.exceptions import InvalidOperation
from openapi_core.schema.servers.exceptions import InvalidServer

View file

@ -1,9 +1,5 @@
"""OpenAPI core validation util module"""
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from six.moves.urllib.parse import urlparse
def is_absolute(url):

View file

@ -1,5 +1,6 @@
openapi-spec-validator
six
lazy-object-proxy
backports.functools-lru-cache
backports.functools-partialmethod
enum34

View file

@ -25,6 +25,11 @@ def get_metadata(init_file):
return dict(re.findall("__([a-z]+)__ = '([^']+)'", init_file))
def install_requires():
py27 = '_2.7' if sys.version_info < (3,) else ''
return read_requirements('requirements{}.txt'.format(py27))
class PyTest(TestCommand):
"""Command to run unit tests after in-place build."""
@ -53,8 +58,6 @@ init_path = os.path.join('openapi_core', '__init__.py')
init_py = read_file(init_path)
metadata = get_metadata(init_py)
py27 = '_2.7' if sys.version_info < (3,) else ''
setup(
name='openapi-core',
@ -70,13 +73,13 @@ setup(
'Intended Audience :: Developers',
"Topic :: Software Development :: Libraries :: Python Modules",
"Operating System :: OS Independent",
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development :: Libraries',
],
install_requires=read_requirements('requirements{}.txt'.format(py27)),
install_requires=install_requires(),
tests_require=read_requirements('requirements_dev.txt'),
extras_require={
'flask': ["werkzeug"],

View file

@ -0,0 +1,18 @@
from openapi_core.validation.util import path_qs
class TestPathQs(object):
def test_path(self):
url = 'https://test.com:1234/path'
result = path_qs(url)
assert result == '/path'
def test_query(self):
url = 'https://test.com:1234/path?query=1'
result = path_qs(url)
assert result == '/path?query=1'