Skip to content
This repository has been archived by the owner on Oct 22, 2020. It is now read-only.

Commit

Permalink
Support Python 3.7.0
Browse files Browse the repository at this point in the history
PR #9
  • Loading branch information
webknjaz authored Jul 4, 2018
2 parents b7b3e73 + 9cbd52c commit 3374e21
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ htmlcov/
nosetests.xml
coverage.xml
cover
.mypy_cache/
.pytest_cache/

# Translations
*.mo
Expand Down
45 changes: 32 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
conditions: v1

dist: trusty
language: python
python:
- "3.5"
- "3.6"
install:
- pip install tox
- pip install -U setuptools
- pip install -U pip
- pip install -U wheel
- pip install -U tox
script:
- export TOXENV=py`python -c 'import sys; print("".join(map(str, sys.version_info[:2])))'`
- echo "$TOXENV"
- tox
after_success:
- pip install codecov
- codecov
cache: pip
env:
TOXENV: py

jobs:
fast_finish: true
include:
- &py-3_7-base
python: "3.7"
dist: xenial
sudo: required

deploy:
provider: pypi
user: hellysmile
password:
secure: "fUak903kME638wYvLjT9zyl9ANGZleBW5NKscy1EYez/OhahlWeM4BIxbgZTjl+BC/ITPt7G9O7MCuu7lQ74cos1mQOo231tKxqohnVNmFB2P+spxjj2ri3Ws3YeZaCkVrC3Ww70ydAMSA3cfk55hRbM25ZmcfvAOW/ZSVJAv+cWlBk4hqXAmE2gPMChFeSgu/LKWs+gPpIH4w/vlscogLjuNbOtTNnYVj0ml7IuhiBFNE2l5Fn/Qu4eO6eiDXKsPCTYDTETnZ6xA12pEo7GRp84Y3N50LkJE0H6jM6TB6GNSUL0ZLdvTeabBuPneb6Ln0RfgzcUaj1ZbKQ7qp1mBEVB0nUbdfn/52PRTUPb0PDw5bAxwrQWFwSxsNzyau88aJwgmhFajriGtb+erNZ4MGAyMwWKiruvDhj276RAgtm7FtYspW8jKcq2y0B5Yz1v0gdiIyoWMyQD8B2kr1OraGj7HzpmKYp/0jxEi+LbV5GfxGQQDf+ycklL+clQTcxrFKhaOzI2gKqIf9Mz0X23rmwYbpmDsSgr1ceVFboNCJRx+NJJqD5GzJ0ScfC1BF2TEeU52wF+afX2zai6F+KrO/8eLAFq3yYUHEReUNL80Cp4RgRC565NStZzIksEP+8lt1q6T6P3MDOZmZXl9PNhh7n/DjeKpgUxOOWI7/E5INQ="
distributions: "sdist"
on:
tags: true
all_branches: true
python: 3.5
- stage: Deploy to PYPI
if: tag IS present
<<: *py-3_7-base
install: skip
script: skip
after_success: []
deploy:
provider: pypi
user: aio-libs-bot
password:
secure: "UWf6kZQS/dpqGXJaYZrS1EWlsIu7xIEfagrf/Fs2hhP2A+65CqsI8He37Wf9Xr8KudLhDl/ddGjPAGcbm8ZJaFnv688iEazbAzx6kMIBaLwjOV2hZ/5DCj4f6Z8HBxDbwcC/bimbEMY8xoCdmYqegobFR4jdKAHQdwPynigoMtrNuavehREKXTVAljUWLrvD3DZ7HJhfoQM5cotmnN7XrVK1xA1PWK8ey+gJewLphD4DO6N0kk59PP3LnIGZjik96DlAcdZM3x6zoTq7pzhS9ZBoua26zfjE6+kjahrCYlHtN4JO22b4/wHZUho8CXIrd/3KTul5nJzh4B2GcF0YQWpAYTexRIqXHrxBUhUv3iMWOI8GVWCl3//zO0a5C2qarcBq6fQe2vDI5ecfcQDQTqJxOJ5MADRM+QGG03Zi9PgNK+bUjOHi/EAc1z3C2nDeK0DR62c5JHz0bsGMsENSjAoEM2XedP1OfvrnhS8PEbIIVKxixxPmiu+iLrWp7GiTw5T026EOuA2ulzZOCIAN774K5YuDoAB5sebkX3EI3sgm1jygDKsign135BRYnDs4dtZG4ruNn/CzoRtvaGK+O8vBi2xqpx8LWC6tglXM8Ny2TXlqJnntEj/U2PRfDmhI3UIgx8E8M7s+WXyxyT5RxC67VSsnhSnb7Y0F5EXYM3E="
distributions: "sdist"
on:
tags: true
all_branches: true
python: 3.7
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ idna-ssl

:info: Patch ssl.match_hostname for Unicode(idna) domains support

.. image:: https://travis-ci.org/aio-libs/idna_ssl.svg?branch=master
:target: https://travis-ci.org/aio-libs/idna_ssl
.. image:: https://travis-ci.com/aio-libs/idna-ssl.svg?branch=master
:target: https://travis-ci.com/aio-libs/idna-ssl

.. image:: https://img.shields.io/pypi/v/idna_ssl.svg
:target: https://pypi.python.org/pypi/idna_ssl

.. image:: https://codecov.io/gh/aio-libs/idna_ssl/branch/master/graph/badge.svg
:target: https://codecov.io/gh/aio-libs/idna_ssl
.. image:: https://codecov.io/gh/aio-libs/idna-ssl/branch/master/graph/badge.svg
:target: https://codecov.io/gh/aio-libs/idna-ssl

Installation
------------
Expand Down
11 changes: 10 additions & 1 deletion idna_ssl.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import ssl
import sys

import idna

__version__ = '1.0.1'
__version__ = '1.1.0'

real_match_hostname = ssl.match_hostname

PY_370 = sys.version_info >= (3, 7, 0)


def patched_match_hostname(cert, hostname):
try:
Expand All @@ -17,6 +20,9 @@ def patched_match_hostname(cert, hostname):


def patch_match_hostname():
if PY_370:
return

if hasattr(ssl.match_hostname, 'patched'):
return

Expand All @@ -25,6 +31,9 @@ def patch_match_hostname():


def reset_match_hostname():
if PY_370:
return

if not hasattr(ssl.match_hostname, 'patched'):
return

Expand Down
14 changes: 5 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
aiohttp==2.3.1
flake8==3.4.1
ipdb==0.10.3
ipython==6.2.1
pytest==3.2.3
aiohttp==3.3.2
flake8==3.5.0
pytest==3.6.2
pytest-asyncio==0.8.0
pytest-cov==2.5.1
pytest-runner==2.12.1
tox==2.9.1
isort==4.2.15
-e .
pytest-runner==4.2
isort==4.3.4
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def read(*parts):
tests_require=['pytest', 'pytest-asyncio', 'pytest-cov', 'aiohttp>2.3'],
py_modules=['idna_ssl'],
install_requires=['idna>=2.0'],
python_requires='<3.7.0',
include_package_data=True,
zip_safe=False,
classifiers=[
Expand All @@ -48,6 +47,7 @@ def read(*parts):
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
keywords=['ssl', 'Unicode', 'idna', 'match_hostname'],
)
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ def event_loop(request):

yield loop

loop.run_until_complete(loop.shutdown_asyncgens())

loop.call_soon(loop.stop)
loop.run_forever()
loop.close()

gc.collect()
gc.collect() # for pypy


@pytest.fixture
Expand Down
46 changes: 39 additions & 7 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
import aiohttp
import pytest

from idna_ssl import patch_match_hostname, reset_match_hostname
from idna_ssl import PY_370, patch_match_hostname, reset_match_hostname

skip_370 = pytest.mark.skipif(
PY_370,
reason='Python>=3.7.0 do not support monkey patching',
)

only_370 = pytest.mark.skipif(
not PY_370,
reason='Python>=3.7.0 do not need monkey patching',
)


@skip_370
@pytest.mark.asyncio
async def test_aiohttp(loop):
reset_match_hostname()
Expand All @@ -26,6 +37,21 @@ async def test_aiohttp(loop):
assert response.status == 200


@only_370
@pytest.mark.asyncio
async def test_aiohttp_py370(loop):
reset_match_hostname()

url = 'https://цфоут.мвд.рф/news/item/8065038/'

async with aiohttp.ClientSession(loop=loop) as session:
async with session.get(url) as response:
await response.read()

assert response.status == 200


@skip_370
def test_patch():
reset_match_hostname()

Expand Down Expand Up @@ -55,12 +81,6 @@ def test_match_hostname():
cert = {'subject': ((('commonName', 'xn--n1aiccj.xn--b1aew.xn--p1ai'),),)}
ssl.match_hostname(cert, 'xn--n1aiccj.xn--b1aew.xn--p1ai')

cert = {'subject': ((('commonName', 'xn--n1aiccj.xn--b1aew.xn--p1ai'),),)}
ssl.match_hostname(cert, 'цфоут.мвд.рф')

cert = {'subject': ((('commonName', 'xn--einla-pqa.de'),),)}
ssl.match_hostname(cert, 'einlaß.de')

cert = {'subject': ((('commonName', 'xn--einla-pqa.de'),),)}
ssl.match_hostname(cert, 'xn--einla-pqa.de')

Expand All @@ -69,3 +89,15 @@ def test_match_hostname():

cert = {'subject': ((('commonName', '::1'),),)}
ssl.match_hostname(cert, '::1')


@skip_370
def test_match_hostname_not_py370():
reset_match_hostname()
patch_match_hostname()

cert = {'subject': ((('commonName', 'xn--n1aiccj.xn--b1aew.xn--p1ai'),),)} # noqa
ssl.match_hostname(cert, 'цфоут.мвд.рф')

cert = {'subject': ((('commonName', 'xn--einla-pqa.de'),),)}
ssl.match_hostname(cert, 'einlaß.de')
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py3{5,6}
py3{5,6,7}
skip_missing_interpreters = True

[testenv]
Expand Down

0 comments on commit 3374e21

Please sign in to comment.