Skip to content

Commit d96baad

Browse files
authored
Merge pull request #430 from MongoEngine/code-cleanup
Remove strings python 2.7 compatibility code
2 parents 50c768e + 6ea4bb1 commit d96baad

File tree

5 files changed

+8
-29
lines changed

5 files changed

+8
-29
lines changed

flask_mongoengine/operation_tracker.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
removes = []
4444
response_sizes = []
4545

46-
if sys.version_info >= (3, 0):
47-
unicode = str
48-
4946

5047
# Wrap helpers._unpack_response for getting response size
5148
@functools.wraps(_original_methods["_unpack_response"])
@@ -581,13 +578,6 @@ def _tidy_stacktrace():
581578
hidden = True
582579
if not text:
583580
text = ""
584-
else:
585-
if sys.version_info >= (3, 0):
586-
text = "".join(text).strip()
587-
else:
588-
try:
589-
text = unicode("".join(text).strip())
590-
except Exception:
591-
pass
581+
text = "".join(text).strip()
592582
trace.append((path, line_no, func_name, text, hidden))
593583
return trace, internal

flask_mongoengine/sessions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import datetime
2-
import sys
32
import uuid
43

54
from bson.tz_util import utc
@@ -8,9 +7,6 @@
87

98
__all__ = ("MongoEngineSession", "MongoEngineSessionInterface")
109

11-
if sys.version_info >= (3, 0):
12-
basestring = str
13-
1410

1511
class MongoEngineSession(CallbackDict, SessionMixin):
1612
def __init__(self, initial=None, sid=None):
@@ -33,8 +29,8 @@ def __init__(self, db, collection="session"):
3329
:param collection: The session collection name defaults to "session"
3430
"""
3531

36-
if not isinstance(collection, basestring):
37-
raise ValueError("collection argument should be string or unicode")
32+
if not isinstance(collection, str):
33+
raise ValueError("Collection argument should be string")
3834

3935
class DBSession(db.Document):
4036
sid = db.StringField(primary_key=True)
@@ -82,6 +78,8 @@ def save_session(self, app, session, response):
8278
domain = self.get_cookie_domain(app)
8379
httponly = self.get_cookie_httponly(app)
8480

81+
# If the session is modified to be empty, remove the cookie.
82+
# If the session is empty, return without setting the cookie.
8583
if not session:
8684
if session.modified:
8785
response.delete_cookie(app.session_cookie_name, domain=domain)

flask_mongoengine/wtf/fields.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Useful form fields for use with the mongoengine.
33
"""
44
import json
5-
import sys
65
from gettext import gettext as _
76

87
from mongoengine.queryset import DoesNotExist
@@ -15,9 +14,6 @@
1514
"QuerySetSelectField",
1615
)
1716

18-
if sys.version_info >= (3, 0):
19-
unicode = str
20-
2117

2218
class QuerySetSelectField(SelectFieldBase):
2319
"""
@@ -171,10 +167,11 @@ def __init__(self, label="", validators=None, model=None, **kwargs):
171167

172168
class JSONField(TextAreaField):
173169
def _value(self):
170+
# TODO: Investigate why raw mentioned.
174171
if self.raw_data:
175172
return self.raw_data[0]
176173
else:
177-
return self.data and unicode(json.dumps(self.data)) or ""
174+
return self.data and json.dumps(self.data) or ""
178175

179176
def process_formdata(self, value):
180177
if value:

flask_mongoengine/wtf/orm.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Tools for generating forms based on mongoengine Document schemas.
33
"""
44
import decimal
5-
import sys
65
from collections import OrderedDict
76

87
from bson import ObjectId
@@ -24,10 +23,6 @@
2423
)
2524

2625

27-
if sys.version_info >= (3, 0):
28-
unicode = str
29-
30-
3126
def converts(*args):
3227
def _inner(func):
3328
func._converter_for = frozenset(args)
@@ -234,7 +229,7 @@ def coerce(self, field_type):
234229
"DecimalField": decimal.Decimal,
235230
"ObjectIdField": ObjectId,
236231
}
237-
return coercions.get(field_type, unicode)
232+
return coercions.get(field_type, str)
238233

239234

240235
def model_fields(model, only=None, exclude=None, field_args=None, converter=None):

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[tool:pytest]
22
addopts = --cov=flask_mongoengine --cov-config=setup.cfg
33
testpaths = tests
4-
env_override_existing_values = 1
54

65
[flake8]
76
ignore=E501,F403,F405,I201,W503,E203

0 commit comments

Comments
 (0)