Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 support #129

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions flask_sqlalchemy.py
Expand Up @@ -76,7 +76,7 @@ def newfn(*args, **kwargs):
_set_default_query_class(kwargs)
if "backref" in kwargs:
backref = kwargs['backref']
if isinstance(backref, basestring):
if isinstance(backref, str):
backref = (backref, {})
_set_default_query_class(backref[1])
return fn(*args, **kwargs)
Expand Down Expand Up @@ -345,7 +345,7 @@ def iter_pages(self, left_edge=2, left_current=2,
{% endmacro %}
"""
last = 0
for num in xrange(1, self.pages + 1):
for num in range(1, self.pages + 1):
if num <= left_edge or \
(num > self.page - left_current - 1 and \
num < self.page + right_current) or \
Expand Down Expand Up @@ -469,7 +469,7 @@ def get_engine(self):

def _defines_primary_key(d):
"""Figures out if the given dictonary defines a primary key column."""
return any(v.primary_key for k, v in d.iteritems()
return any(v.primary_key for k, v in d.items()
if isinstance(v, sqlalchemy.Column))


Expand Down Expand Up @@ -801,7 +801,7 @@ def get_app(self, reference_app=None):
def get_tables_for_bind(self, bind=None):
"""Returns a list of all tables relevant for a bind."""
result = []
for table in self.Model.metadata.tables.itervalues():
for table in self.Model.metadata.tables.values():
if table.info.get('bind_key') == bind:
result.append(table)
return result
Expand All @@ -825,7 +825,7 @@ def _execute_for_all_tables(self, app, bind, operation):

if bind == '__all__':
binds = [None] + list(app.config.get('SQLALCHEMY_BINDS') or ())
elif isinstance(bind, basestring) or bind is None:
elif isinstance(bind, str) or bind is None:
binds = [bind]
else:
binds = bind
Expand Down
6 changes: 3 additions & 3 deletions test_sqlalchemy.py
Expand Up @@ -59,7 +59,7 @@ def test_basic_insert(self):
c.post('/add', data=dict(title='First Item', text='The text'))
c.post('/add', data=dict(title='2nd Item', text='The text'))
rv = c.get('/')
assert rv.data == 'First Item\n2nd Item'
assert rv.data == b'First Item\n2nd Item'

def test_query_recording(self):
with self.app.test_request_context():
Expand Down Expand Up @@ -446,12 +446,12 @@ def create():
def test_commit_on_success(self):
resp = self.client.post('/create')
self.assertEqual(resp.status_code, 200)
self.assertEqual(self.client.get('/').data, 'Test one')
self.assertEqual(self.client.get('/').data, b'Test one')

def test_roll_back_on_failure(self):
resp = self.client.post('/create', data={'fail': 'on'})
self.assertEqual(resp.status_code, 500)
self.assertEqual(self.client.get('/').data, '')
self.assertEqual(self.client.get('/').data, b'')


def suite():
Expand Down