Skip to content

Commit

Permalink
Drop support for EOL Python 2.6
Browse files Browse the repository at this point in the history
* Drop support for EOL Python 2.6

* Upgrade Python syntax with pyupgrade

* Convert docstring to triple double-quoted form
  • Loading branch information
hugovk authored and corydolphin committed Aug 27, 2018
1 parent 0fc5ebe commit c5d572c
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 41 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cache:
- pip
language: python
python:
- '2.6'
- '2.7'
- '3.4'
- '3.5'
Expand Down Expand Up @@ -34,4 +33,3 @@ deploy:
on:
tags: true
repo: corydolphin/flask-cors
condition: $TRAVIS_PYTHON_VERSION != *2.6* # Ensures we release a 2.7X wheel
16 changes: 8 additions & 8 deletions examples/app_based_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@

@app.route("/")
def helloWorld():
'''
"""
Since the path '/' does not match the regular expression r'/api/*',
this route does not have CORS headers set.
'''
"""
return '''
<html>
<h1>Hello CORS!</h1>
Expand All @@ -50,7 +50,7 @@ def helloWorld():

@app.route("/api/v1/users/")
def list_users():
'''
"""
Since the path matches the regular expression r'/api/*', this resource
automatically has CORS headers set. The expected result is as follows:
Expand All @@ -68,13 +68,13 @@ def list_users():
"success": true
}
'''
"""
return jsonify(user="joe")


@app.route("/api/v1/users/create", methods=['POST'])
def create_user():
'''
"""
Since the path matches the regular expression r'/api/*', this resource
automatically has CORS headers set.
Expand Down Expand Up @@ -112,12 +112,12 @@ def create_user():
"success": true
}
'''
"""
return jsonify(success=True)

@app.route("/api/exception")
def get_exception():
'''
"""
Since the path matches the regular expression r'/api/*', this resource
automatically has CORS headers set.
Expand All @@ -137,7 +137,7 @@ def get_exception():
Content-Length: 0
Server: Werkzeug/0.9.6 Python/2.7.9
Date: Sat, 31 Jan 2015 22:25:22 GMT
'''
"""
raise Exception("example")

@app.errorhandler(500)
Expand Down
7 changes: 1 addition & 6 deletions flask_cors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@

# Set default logging handler to avoid "No handler found" warnings.
import logging
try: # Python 2.7+
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
from logging import NullHandler

# Set initial level to WARN. Users must manually enable logging for
# flask_cors to see our logging.
Expand Down
6 changes: 3 additions & 3 deletions flask_cors/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ def get_app_kwarg_dict(appInstance=None):
# In order to support blueprints which do not have a config attribute
app_config = getattr(app, 'config', {})

return dict(
(k.lower().replace('cors_', ''), app_config.get(k))
return {
k.lower().replace('cors_', ''): app_config.get(k)
for k in CONFIG_OPTIONS
if app_config.get(k) is not None
)
}


def flexible_str(obj):
Expand Down
2 changes: 1 addition & 1 deletion flask_cors/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def init_app(self, app, **kwargs):

# Create a human readable form of these resources by converting the compiled
# regular expressions into strings.
resources_human = dict([(get_regexp_pattern(pattern), opts) for (pattern,opts) in resources])
resources_human = {get_regexp_pattern(pattern): opts for (pattern,opts) in resources}
LOG.debug("Configuring CORS with resources: %s", resources_human)

cors_after_request = make_after_request_function(resources)
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
Expand Down
7 changes: 2 additions & 5 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
:license: MIT, see LICENSE for more details.
"""
from flask import Flask
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest

from flask_cors import *
from flask_cors.core import *
Expand All @@ -26,7 +23,7 @@ def shortDescription(self):
http://erikzaadi.com/2012/09/13/inheritance-within-python-unit-tests/
"""
doc = self.id()[self.id().rfind('.')+1:]
return "%s.%s" % (self.__class__.__name__, doc)
return "{}.{}".format(self.__class__.__name__, doc)

def iter_verbs(self, c):
''' A simple helper method to iterate through a range of
Expand Down
7 changes: 2 additions & 5 deletions tests/core/helper_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
:license: MIT, see LICENSE for more details.
"""

try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest

from flask_cors.core import *

Expand All @@ -28,7 +25,7 @@ def test_flexible_str_str(self):
self.assertEquals(flexible_str('Bar, Foo, Qux'), 'Bar, Foo, Qux')

def test_flexible_str_set(self):
self.assertEquals(flexible_str(set(['Foo', 'Bar', 'Qux'])),
self.assertEquals(flexible_str({'Foo', 'Bar', 'Qux'}),
'Bar, Foo, Qux')

def test_serialize_options(self):
Expand Down
5 changes: 0 additions & 5 deletions tests/decorator/test_max_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
:license: MIT, see LICENSE for more details.
"""
from datetime import timedelta
import sys
from ..base_test import FlaskCorsTestCase
from flask import Flask

Expand Down Expand Up @@ -53,10 +52,6 @@ def test_time_delta(self):
''' If the methods parameter is defined, always return the allowed
methods defined by the user.
'''
# timedelta.total_seconds is not available in older versions of Python
if sys.version_info < (2, 7):
return

resp = self.preflight('/test_time_delta', origin='www.example.com')
self.assertEqual(resp.headers.get(ACL_MAX_AGE), '600')

Expand Down
4 changes: 2 additions & 2 deletions tests/decorator/test_origins.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_string():
return 'Welcome!'

@self.app.route('/test_set')
@cross_origin(origins=set(["http://foo.com", "http://bar.com"]))
@cross_origin(origins={"http://foo.com", "http://bar.com"})
def test_set():
return 'Welcome!'

Expand Down Expand Up @@ -164,7 +164,7 @@ def test_compiled_subdomain_regex(self):
def test_regex_list(self):
for parent in 'example.com', 'otherexample.com':
for sub in letters:
domain = "http://%s.%s.com" % (sub, parent)
domain = "http://{}.{}.com".format(sub, parent)
for resp in self.iter_responses('/test_regex_list',
headers={'origin': domain}):
self.assertEqual(domain, resp.headers.get(ACL_ORIGIN))
Expand Down
2 changes: 1 addition & 1 deletion tests/decorator/test_vary_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_consistent_origin_concat(self):

resp = self.get('/test_existing_vary_headers', origin="http://foo.com")
self.assertEqual(set(resp.headers.getlist('Vary')),
set(['Origin', 'Accept-Encoding']))
{'Origin', 'Accept-Encoding'})

if __name__ == "__main__":
unittest.main()
4 changes: 2 additions & 2 deletions tests/extension/test_app_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setUp(self):
r'/test_list': {'origins': ["http://foo.com", "http://bar.com"]},
r'/test_string': {'origins': 'http://foo.com'},
r'/test_set': {
'origins': set(["http://foo.com", "http://bar.com"])
'origins': {"http://foo.com", "http://bar.com"}
},
r'/test_subdomain_regex': {
'origins': r"http?://\w*\.?example\.com:?\d*/?.*"
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_compiled_subdomain_regex(self):
def test_regex_list(self):
for parent in 'example.com', 'otherexample.com':
for sub in letters:
domain = "http://%s.%s.com" % (sub, parent)
domain = "http://{}.{}.com".format(sub, parent)
for resp in self.iter_responses('/test_regex_list',
headers={'origin': domain}):
self.assertEqual(domain, resp.headers.get(ACL_ORIGIN))
Expand Down

0 comments on commit c5d572c

Please sign in to comment.