Skip to content

Commit c5d572c

Browse files
hugovkcorydolphin
authored andcommitted
Drop support for EOL Python 2.6
* Drop support for EOL Python 2.6 * Upgrade Python syntax with pyupgrade * Convert docstring to triple double-quoted form
1 parent 0fc5ebe commit c5d572c

12 files changed

+27
-41
lines changed

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ cache:
33
- pip
44
language: python
55
python:
6-
- '2.6'
76
- '2.7'
87
- '3.4'
98
- '3.5'
@@ -34,4 +33,3 @@ deploy:
3433
on:
3534
tags: true
3635
repo: corydolphin/flask-cors
37-
condition: $TRAVIS_PYTHON_VERSION != *2.6* # Ensures we release a 2.7X wheel

examples/app_based_example.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434

3535
@app.route("/")
3636
def helloWorld():
37-
'''
37+
"""
3838
Since the path '/' does not match the regular expression r'/api/*',
3939
this route does not have CORS headers set.
40-
'''
40+
"""
4141
return '''
4242
<html>
4343
<h1>Hello CORS!</h1>
@@ -50,7 +50,7 @@ def helloWorld():
5050

5151
@app.route("/api/v1/users/")
5252
def list_users():
53-
'''
53+
"""
5454
Since the path matches the regular expression r'/api/*', this resource
5555
automatically has CORS headers set. The expected result is as follows:
5656
@@ -68,13 +68,13 @@ def list_users():
6868
"success": true
6969
}
7070
71-
'''
71+
"""
7272
return jsonify(user="joe")
7373

7474

7575
@app.route("/api/v1/users/create", methods=['POST'])
7676
def create_user():
77-
'''
77+
"""
7878
Since the path matches the regular expression r'/api/*', this resource
7979
automatically has CORS headers set.
8080
@@ -112,12 +112,12 @@ def create_user():
112112
"success": true
113113
}
114114
115-
'''
115+
"""
116116
return jsonify(success=True)
117117

118118
@app.route("/api/exception")
119119
def get_exception():
120-
'''
120+
"""
121121
Since the path matches the regular expression r'/api/*', this resource
122122
automatically has CORS headers set.
123123
@@ -137,7 +137,7 @@ def get_exception():
137137
Content-Length: 0
138138
Server: Werkzeug/0.9.6 Python/2.7.9
139139
Date: Sat, 31 Jan 2015 22:25:22 GMT
140-
'''
140+
"""
141141
raise Exception("example")
142142

143143
@app.errorhandler(500)

flask_cors/__init__.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616

1717
# Set default logging handler to avoid "No handler found" warnings.
1818
import logging
19-
try: # Python 2.7+
20-
from logging import NullHandler
21-
except ImportError:
22-
class NullHandler(logging.Handler):
23-
def emit(self, record):
24-
pass
19+
from logging import NullHandler
2520

2621
# Set initial level to WARN. Users must manually enable logging for
2722
# flask_cors to see our logging.

flask_cors/core.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ def get_app_kwarg_dict(appInstance=None):
302302
# In order to support blueprints which do not have a config attribute
303303
app_config = getattr(app, 'config', {})
304304

305-
return dict(
306-
(k.lower().replace('cors_', ''), app_config.get(k))
305+
return {
306+
k.lower().replace('cors_', ''): app_config.get(k)
307307
for k in CONFIG_OPTIONS
308308
if app_config.get(k) is not None
309-
)
309+
}
310310

311311

312312
def flexible_str(obj):

flask_cors/extension.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def init_app(self, app, **kwargs):
147147

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

153153
cors_after_request = make_after_request_function(resources)

setup.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@
4242
'License :: OSI Approved :: MIT License',
4343
'Operating System :: OS Independent',
4444
'Programming Language :: Python',
45-
'Programming Language :: Python :: 2.6',
45+
'Programming Language :: Python :: 2',
4646
'Programming Language :: Python :: 2.7',
4747
'Programming Language :: Python :: 3',
48+
'Programming Language :: Python :: 3.4',
49+
'Programming Language :: Python :: 3.5',
50+
'Programming Language :: Python :: 3.6',
51+
'Programming Language :: Python :: 3.7',
4852
'Programming Language :: Python :: Implementation :: CPython',
4953
'Programming Language :: Python :: Implementation :: PyPy',
5054
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',

tests/base_test.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
:license: MIT, see LICENSE for more details.
1010
"""
1111
from flask import Flask
12-
try:
13-
import unittest2 as unittest
14-
except ImportError:
15-
import unittest
12+
import unittest
1613

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

3128
def iter_verbs(self, c):
3229
''' A simple helper method to iterate through a range of

tests/core/helper_tests.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
:license: MIT, see LICENSE for more details.
1212
"""
1313

14-
try:
15-
import unittest2 as unittest
16-
except ImportError:
17-
import unittest
14+
import unittest
1815

1916
from flask_cors.core import *
2017

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

3027
def test_flexible_str_set(self):
31-
self.assertEquals(flexible_str(set(['Foo', 'Bar', 'Qux'])),
28+
self.assertEquals(flexible_str({'Foo', 'Bar', 'Qux'}),
3229
'Bar, Foo, Qux')
3330

3431
def test_serialize_options(self):

tests/decorator/test_max_age.py

-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
:license: MIT, see LICENSE for more details.
1010
"""
1111
from datetime import timedelta
12-
import sys
1312
from ..base_test import FlaskCorsTestCase
1413
from flask import Flask
1514

@@ -53,10 +52,6 @@ def test_time_delta(self):
5352
''' If the methods parameter is defined, always return the allowed
5453
methods defined by the user.
5554
'''
56-
# timedelta.total_seconds is not available in older versions of Python
57-
if sys.version_info < (2, 7):
58-
return
59-
6055
resp = self.preflight('/test_time_delta', origin='www.example.com')
6156
self.assertEqual(resp.headers.get(ACL_MAX_AGE), '600')
6257

tests/decorator/test_origins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_string():
5252
return 'Welcome!'
5353

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

@@ -164,7 +164,7 @@ def test_compiled_subdomain_regex(self):
164164
def test_regex_list(self):
165165
for parent in 'example.com', 'otherexample.com':
166166
for sub in letters:
167-
domain = "http://%s.%s.com" % (sub, parent)
167+
domain = "http://{}.{}.com".format(sub, parent)
168168
for resp in self.iter_responses('/test_regex_list',
169169
headers={'origin': domain}):
170170
self.assertEqual(domain, resp.headers.get(ACL_ORIGIN))

tests/decorator/test_vary_header.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_consistent_origin_concat(self):
8181

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

8686
if __name__ == "__main__":
8787
unittest.main()

tests/extension/test_app_extension.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def setUp(self):
2525
r'/test_list': {'origins': ["http://foo.com", "http://bar.com"]},
2626
r'/test_string': {'origins': 'http://foo.com'},
2727
r'/test_set': {
28-
'origins': set(["http://foo.com", "http://bar.com"])
28+
'origins': {"http://foo.com", "http://bar.com"}
2929
},
3030
r'/test_subdomain_regex': {
3131
'origins': r"http?://\w*\.?example\.com:?\d*/?.*"
@@ -136,7 +136,7 @@ def test_compiled_subdomain_regex(self):
136136
def test_regex_list(self):
137137
for parent in 'example.com', 'otherexample.com':
138138
for sub in letters:
139-
domain = "http://%s.%s.com" % (sub, parent)
139+
domain = "http://{}.{}.com".format(sub, parent)
140140
for resp in self.iter_responses('/test_regex_list',
141141
headers={'origin': domain}):
142142
self.assertEqual(domain, resp.headers.get(ACL_ORIGIN))

0 commit comments

Comments
 (0)