Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Just use autopep8 as part of the build
Browse files Browse the repository at this point in the history
If a computer is going to moan at me about whitespace, a computer can
fix it.
  • Loading branch information
jabley committed Oct 3, 2014
1 parent cd2996b commit fdfef20
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 16 deletions.
2 changes: 2 additions & 0 deletions backdrop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@


class StatsClient(object):

"""Wrap statsd.StatsClient to allow data_set to be added to stat"""

def __init__(self, statsd):
self._statsd = statsd

Expand Down
18 changes: 9 additions & 9 deletions backdrop/admin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ def _store_data(data_set_config):


def log_upload_error(message, app, e, data_set_config):
app.logger.error(
'{}: {}'.format(message, e.message),
extra={
'backdrop_upload_error': type(e).__name__,
'data_group': data_set_config['data_group'],
'data_type': data_set_config['data_type'],
},
exc_info=True
)
app.logger.error(
'{}: {}'.format(message, e.message),
extra={
'backdrop_upload_error': type(e).__name__,
'data_group': data_set_config['data_group'],
'data_type': data_set_config['data_type'],
},
exc_info=True
)


def start(port):
Expand Down
2 changes: 1 addition & 1 deletion backdrop/admin/config/development.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LOG_LEVEL = "DEBUG"
BACKDROP_ADMIN_UI_HOST = "http://admin.development.performance.service.gov.uk"
ALLOW_TEST_SIGNIN=True
ALLOW_TEST_SIGNIN = True
SECRET_KEY = "something unique and secret"

DATABASE_NAME = "backdrop"
Expand Down
2 changes: 2 additions & 0 deletions backdrop/admin/scanned_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@


class VirusSignatureError(StandardError):

def __init__(self, message):
self.message = message


class ScannedFile(object):

def __init__(self, file_object):
self.file_object = file_object
self._virus_signature = False
Expand Down
1 change: 1 addition & 0 deletions backdrop/admin/signonotron2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class Signonotron2(object):

def __init__(self, client_id, client_secret, base_url,
redirect_url):
self.signon = OAuth2Service(
Expand Down
1 change: 1 addition & 0 deletions backdrop/admin/uploaded_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class FileUploadError(IOError):

def __init__(self, message):
self.message = message

Expand Down
1 change: 1 addition & 0 deletions backdrop/core/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


class DataSet(object):

def __init__(self, storage, config):
self.storage = storage
self.config = config
Expand Down
1 change: 1 addition & 0 deletions backdrop/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class InvalidSortError(ValueError):


class InvalidOperationError(ValueError):

"""Raised if an invalid collect function is provided, or if an error
is raised from a collect function"""
pass
1 change: 1 addition & 0 deletions backdrop/core/flaskutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


class DataSetConverter(BaseConverter):

def to_python(self, value):
if not data_set_is_valid(value):
raise ValidationError()
Expand Down
2 changes: 1 addition & 1 deletion backdrop/core/log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ def log_response(response):


def create_logging_extra_dict():
return { 'request_id': request.headers.get('Request-Id')}
return {'request_id': request.headers.get('Request-Id')}
1 change: 1 addition & 0 deletions backdrop/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


class Query(_Query):

@classmethod
def create(cls,
start_at=None, end_at=None, duration=None, delta=None,
Expand Down
6 changes: 6 additions & 0 deletions backdrop/core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def first_nonempty(data, is_reversed):


class SimpleData(object):

def __init__(self, cursor):
self._data = []
for doc in cursor:
Expand All @@ -60,6 +61,7 @@ def amount_to_shift(self, delta):


class PeriodData(object):

def __init__(self, cursor, period):
self.period = period
self._data = []
Expand Down Expand Up @@ -97,6 +99,7 @@ def amount_to_shift(self, delta):


class GroupedData(object):

def __init__(self, cursor):
self._data = []
for doc in cursor:
Expand All @@ -114,6 +117,7 @@ def amount_to_shift(self, delta):


class FlatData(object):

def __init__(self, cursor):
self._data = []
for doc in cursor:
Expand All @@ -131,6 +135,7 @@ def amount_to_shift(self, delta):


class PeriodGroupedData(object):

def __init__(self, cursor, period):
self._period = period
self._data = []
Expand Down Expand Up @@ -180,6 +185,7 @@ def amount_to_shift(self, delta):


class PeriodFlatData(object):

def __init__(self, cursor, period):
self._period = period
self._data = []
Expand Down
1 change: 1 addition & 0 deletions backdrop/core/storage/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def reconnecting_save(collection, record, tries=3):


class MongoStorageEngine(object):

@classmethod
def create(cls, hosts, port, database):
return cls(get_mongo_client(hosts, port), database)
Expand Down
7 changes: 7 additions & 0 deletions backdrop/core/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class Period(object):

@property
def delta(self):
return self._delta
Expand Down Expand Up @@ -41,6 +42,7 @@ def valid_start_at(self, timestamp):


class Hour(Period):

def __init__(self):
self.name = "hour"
self._delta = timedelta(hours=1)
Expand All @@ -56,6 +58,7 @@ def valid_start_at(self, timestamp):


class Day(Period):

def __init__(self):
self.name = "day"
self._delta = timedelta(days=1)
Expand All @@ -68,6 +71,7 @@ def valid_start_at(self, timestamp):


class Week(Period):

def __init__(self):
self.name = "week"
self._delta = timedelta(days=7)
Expand All @@ -80,6 +84,7 @@ def valid_start_at(self, timestamp):


class Month(Period):

def __init__(self):
self.name = "month"
self._delta = relativedelta(months=1)
Expand All @@ -93,6 +98,7 @@ def valid_start_at(self, timestamp):


class Quarter(Period):

def __init__(self):
self.name = "quarter"
self._delta = relativedelta(months=3)
Expand All @@ -111,6 +117,7 @@ def valid_start_at(self, timestamp):


class Year(Period):

def __init__(self):
self.name = "year"
self._delta = relativedelta(years=1)
Expand Down
2 changes: 1 addition & 1 deletion backdrop/core/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def create_parser(data_set_config):
format_parser = load_format_parser(data_set_config['upload_format'])
upload_filters = map(load_filter, data_set_config.get('upload_filters',
DEFAULT_UPLOAD_FILTERS))
DEFAULT_UPLOAD_FILTERS))

def parser(file_stream):
data = format_parser(file_stream)
Expand Down
2 changes: 1 addition & 1 deletion backdrop/read/config/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
MONGO_PORT = 27017
LOG_LEVEL = "ERROR"

DATA_SET_RATE_LIMIT='10000/second'
DATA_SET_RATE_LIMIT = '10000/second'

from development import STAGECRAFT_URL, STAGECRAFT_DATA_SET_QUERY_TOKEN, SIGNON_API_USER_TOKEN
19 changes: 19 additions & 0 deletions backdrop/read/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


class Validator(object):

def __init__(self, request_args, **context):
self.errors = []
self.validate(request_args, context)
Expand All @@ -24,6 +25,7 @@ def validate(self, request_args, context):


class MultiValueValidator(Validator):

def param_name(self, context):
return context.get('param_name')

Expand All @@ -38,6 +40,7 @@ def validate(self, request_args, context):


class ParameterValidator(Validator):

def __init__(self, request_args):
self.allowed_parameters = set([
'start_at',
Expand All @@ -62,6 +65,7 @@ def validate(self, request_args, context):


class DatetimeValidator(Validator):

def validate(self, request_args, context):
if context['param_name'] in request_args:
if not value_is_valid_datetime_string(
Expand All @@ -71,6 +75,7 @@ def validate(self, request_args, context):


class PeriodQueryValidator(Validator):

def validate(self, request_args, context):
if 'period' not in request_args:
return
Expand All @@ -89,6 +94,7 @@ def validate(self, request_args, context):


class PositiveIntegerValidator(Validator):

def validate(self, request_args, context):
if context['param_name'] in request_args:
try:
Expand All @@ -100,6 +106,7 @@ def validate(self, request_args, context):


class BooleanValidator(Validator):

def validate(self, request_args, context):
if context['param_name'] in request_args:
if request_args[context['param_name']] not in ['true', 'false']:
Expand All @@ -108,6 +115,7 @@ def validate(self, request_args, context):


class FilterByValidator(Validator):

def validate(self, request_args, context):
MultiValueValidator(
request_args,
Expand All @@ -129,6 +137,7 @@ def validate_field_value(self, value, request_args, context):


class ParameterMustBeOneOfTheseValidator(Validator):

def validate(self, request_args, context):
param_to_check = context['param_name']
allowed_params = context['must_be_one_of_these']
Expand All @@ -142,6 +151,7 @@ def validate(self, request_args, context):


class SortByValidator(Validator):

def _unrecognised_direction(self, sort_by):
return not re.match(r'^.+:(ascending|descending)$', sort_by)

Expand All @@ -163,6 +173,7 @@ def validate(self, request_args, context):


class GroupByValidator(Validator):

def validate(self, request_args, context):
if 'group_by' in request_args:
if not key_is_valid(request_args['group_by']):
Expand All @@ -173,6 +184,7 @@ def validate(self, request_args, context):


class ParamDependencyValidator(Validator):

def validate(self, request_args, context):
if context['param_name'] in request_args:
if all(param not in request_args
Expand All @@ -183,6 +195,7 @@ def validate(self, request_args, context):


class CollectValidator(Validator):

def validate(self, request_args, context):
MultiValueValidator(
request_args,
Expand All @@ -207,6 +220,7 @@ def validate_field_value(self, value, request_args, _):


class RawQueryValidator(Validator):

def _is_a_raw_query(self, request_args):
if 'group_by' in request_args:
return False
Expand All @@ -224,6 +238,7 @@ def _is_valid_date(string):


class TimeSpanValidator(Validator):

def validate(self, request_args, context):
if self._is_valid_date_query(request_args):
start_at = parser.parse(request_args['start_at'])
Expand All @@ -239,6 +254,7 @@ def _is_valid_date_query(self, request_args):


class MidnightValidator(Validator):

def validate(self, request_args, context):
timestamp = request_args.get(context['param_name'])
if _is_valid_date(timestamp) and request_args.get('period') != 'hour':
Expand All @@ -248,6 +264,7 @@ def validate(self, request_args, context):


class MondayValidator(Validator):

def validate(self, request_args, context):
if request_args.get('period') == 'week':
timestamp = request_args.get(context['param_name'])
Expand All @@ -258,6 +275,7 @@ def validate(self, request_args, context):


class FirstOfMonthValidator(Validator):

def validate(self, request_args, context):

if request_args.get('period') == 'month':
Expand All @@ -270,6 +288,7 @@ def validate(self, request_args, context):


class RelativeTimeValidator(Validator):

def validate(self, request_args, context):

start_at = request_args.get('start_at')
Expand Down
Loading

0 comments on commit fdfef20

Please sign in to comment.