Skip to content

Commit

Permalink
Run python-modernize commands:
Browse files Browse the repository at this point in the history
* python-modernize -n -w --no-diffs -f unicode_type .  # avoid PyCQA/modernize#133
* python-modernize --future-unicode -n -w --no-diffs -f unicode_future .
* python-modernize -n -w --no-diffs -f default -f libmodernize.fixes.fix_open .
  • Loading branch information
brondsem committed Jul 12, 2019
1 parent 7f4aa8b commit b29e53d
Show file tree
Hide file tree
Showing 29 changed files with 120 additions and 54 deletions.
18 changes: 10 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

from __future__ import unicode_literals
from __future__ import absolute_import
import sys
import os

Expand Down Expand Up @@ -43,8 +45,8 @@
master_doc = 'index'

# General information about the project.
project = u'Switchboard'
copyright = u'2015, Kyle Adams'
project = 'Switchboard'
copyright = '2015, Kyle Adams'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -196,8 +198,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'Switchboard.tex', u'Switchboard Documentation',
u'Kyle Adams', 'manual'),
('index', 'Switchboard.tex', 'Switchboard Documentation',
'Kyle Adams', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -226,8 +228,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'switchboard', u'Switchboard Documentation',
[u'Kyle Adams'], 1)
('index', 'switchboard', 'Switchboard Documentation',
['Kyle Adams'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -240,8 +242,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Switchboard', u'Switchboard Documentation',
u'Kyle Adams', 'Switchboard', 'One line description of project.',
('index', 'Switchboard', 'Switchboard Documentation',
'Kyle Adams', 'Switchboard', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
2 changes: 2 additions & 0 deletions example/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from bottle import Bottle, redirect, run

from switchboard import operator, configure
Expand Down
2 changes: 2 additions & 0 deletions example/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import unicode_literals
from __future__ import absolute_import
from nose.tools import assert_true, assert_false
from splinter import Browser

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import unicode_literals
from __future__ import absolute_import
import setuptools
import sys

Expand Down
3 changes: 2 additions & 1 deletion switchboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import unicode_literals
from .manager import operator, configure

__all__ = ('operator', 'configure', 'VERSION')

try:
VERSION = __import__('pkg_resources') \
.get_distribution('switchboard').version
except Exception, e: # pragma: nocover
except Exception as e: # pragma: nocover
VERSION = 'unknown'
7 changes: 5 additions & 2 deletions switchboard/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import unicode_literals
from __future__ import absolute_import
from datetime import datetime
import logging
from operator import attrgetter
Expand All @@ -22,6 +24,7 @@
valid_sort_orders
)
from ..settings import settings
import six

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -121,7 +124,7 @@ def update():
)

changes = {}
for k, v in values.iteritems():
for k, v in six.iteritems(values):
old_value = getattr(switch, k)
if old_value != v:
changes[k] = (v, old_value)
Expand All @@ -138,7 +141,7 @@ def update():

log.info('Switch %r updated %%s' % switch.key,
', '.join('%s=%r->%r' % (k, v[0], v[1]) for k, v in
sorted(changes.iteritems())))
sorted(six.iteritems(changes))))

signals.switch_updated.send(switch)

Expand Down
6 changes: 4 additions & 2 deletions switchboard/admin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import unicode_literals
from __future__ import absolute_import
import json

from switchboard.conditions import Invalid
Expand All @@ -24,7 +26,7 @@ def wrapper(*args, **kwargs):
"success": True,
"data": func(*args, **kwargs)
}
except SwitchboardException, e:
except SwitchboardException as e:
response = {
"success": False,
"data": e.message
Expand All @@ -34,7 +36,7 @@ def wrapper(*args, **kwargs):
"success": False,
"data": "Switch cannot be found"
}
except Invalid, e:
except Invalid as e:
response = {
"success": False,
"data": e.message,
Expand Down
15 changes: 9 additions & 6 deletions switchboard/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import unicode_literals
from __future__ import absolute_import
import time
import logging
import threading

from .models import MongoModel
from .signals import request_finished
from .settings import settings
import six

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,25 +71,25 @@ def __repr__(self): # pragma: nocover

def iteritems(self): # pragma: nocover
self._populate()
return self._cache.iteritems()
return six.iteritems(self._cache)

def itervalues(self): # pragma: nocover
self._populate()
return self._cache.itervalues()
return six.itervalues(self._cache)

def iterkeys(self): # pragma: nocover
self._populate()
return self._cache.iterkeys()
return six.iterkeys(self._cache)

def keys(self): # pragma: nocover
return list(self.iterkeys())
return list(six.iterkeys(self))

def values(self): # pragma: nocover
return list(self.itervalues())
return list(six.itervalues(self))

def items(self): # pragma: nocover
self._populate()
return self._cache.items()
return list(self._cache.items())

def get(self, key, default=None):
self._populate()
Expand Down
5 changes: 4 additions & 1 deletion switchboard/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
:copyright: (c) 2015 Kyle Adams.
:license: Apache License 2.0, see LICENSE for more details.
"""
from __future__ import unicode_literals
from __future__ import absolute_import
import socket

from . import operator
Expand All @@ -18,6 +20,7 @@
Invalid,
)
from .settings import settings
import six


class IPAddress(String):
Expand All @@ -27,7 +30,7 @@ def clean(self, value):
import ipaddress
# The third-party ipaddress lib (not the builtin Python 3 library)
# requires a unicode string.
ipaddress.ip_address(unicode(value))
ipaddress.ip_address(six.text_type(value))
except ImportError: # pragma: nocover
pass
except ValueError:
Expand Down
20 changes: 11 additions & 9 deletions switchboard/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

# Credit to Haystack for abstraction concepts

from __future__ import unicode_literals
from __future__ import absolute_import
import datetime
import re

from .models import EXCLUDE
import six
from six.moves import map


class Invalid(Exception): # pragma: nocover
Expand Down Expand Up @@ -57,7 +61,7 @@ def validate(self, data):
value = data.get(self.name)
if value:
value = self.clean(value)
is_string = isinstance(value, basestring)
is_string = isinstance(value, six.string_types)
assert is_string, 'clean methods must return strings'
return value

Expand Down Expand Up @@ -116,13 +120,13 @@ def is_active(self, value, actual_value):
def validate(self, data):
min_limit = data.get(self.name + '[min]')
max_limit = data.get(self.name + '[max]')
value = filter(None, [min_limit, max_limit]) or None
value = [_f for _f in [min_limit, max_limit] if _f] or None
return self.clean(value)

def clean(self, value):
if value:
try:
map(int, value)
list(map(int, value))
except (TypeError, ValueError):
raise Invalid('You must enter valid integer values.')
else:
Expand Down Expand Up @@ -153,7 +157,7 @@ class Percent(Range):
default_help_text = 'Enter two ranges, e.g. 0-50 is lower 50%.'

def is_active(self, value, actual_value):
value = map(int, value.split('-'))
value = list(map(int, value.split('-')))
mod = actual_value % 100
return super(Percent, self).is_active(value, mod)

Expand Down Expand Up @@ -217,7 +221,7 @@ def display(self, value):
def clean(self, value):
try:
date = self.str_to_date(value)
except ValueError, e:
except ValueError as e:
msg = ("Date must be a valid date in the format YYYY-MM-DD.\n(%s)"
% e.message)
raise Invalid(msg)
Expand Down Expand Up @@ -284,9 +288,7 @@ def __new__(cls, name, bases, attrs):
return super(ConditionSetBase, cls).__new__(cls, name, bases, attrs)


class ConditionSet(object):
__metaclass__ = ConditionSetBase

class ConditionSet(six.with_metaclass(ConditionSetBase, object)):
def __repr__(self): # pragma: nocover
return '<%s>' % (self.__class__.__name__,)

Expand Down Expand Up @@ -350,7 +352,7 @@ def is_active(self, instance, condition):
a boolean representing if the feature is active.
"""
return_value = None
for name, field_conditions in condition.iteritems():
for name, field_conditions in six.iteritems(condition):
field = self.fields.get(name)
if field:
value = self.get_field_value(instance, name)
Expand Down
2 changes: 2 additions & 0 deletions switchboard/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import unicode_literals
from __future__ import absolute_import
from functools import wraps

from webob.exc import HTTPNotFound, HTTPFound
Expand Down
9 changes: 6 additions & 3 deletions switchboard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import unicode_literals
from __future__ import absolute_import
import logging
from collections import defaultdict
from copy import deepcopy
import six

log = logging.getLogger(__name__)

Expand All @@ -24,7 +27,7 @@ def __init__(self, name=''):
self.database = defaultdict(lambda: MockCollection(), name=self)

def _matches(self, spec, document):
for k, v in spec.iteritems():
for k, v in six.iteritems(spec):
if k not in document or document[k] != v:
return False
return True
Expand All @@ -45,7 +48,7 @@ def find(self, spec=None):
return results or None

def _update_partial(self, old, new):
for k, v in new.iteritems():
for k, v in six.iteritems(new):
old[k] = v

def update(self, spec, update, upsert=False):
Expand All @@ -61,7 +64,7 @@ def update(self, spec, update, upsert=False):
'ok': 1.0,
'updatedExisting': True
}
for k, v in update.iteritems():
for k, v in six.iteritems(update):
if k == '$set':
self._update_partial(current, v)
else:
Expand Down
Loading

0 comments on commit b29e53d

Please sign in to comment.