Skip to content

Commit

Permalink
whitespace fixes. one space in classes, else two
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Black committed Apr 17, 2014
1 parent c019c80 commit 9d69029
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 189 deletions.
23 changes: 11 additions & 12 deletions flask_restful/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ def _complete_url(self, url_part, registration_prefix):
:param registration_prefix: The part of the url contributed by the
blueprint. Generally speaking, BlueprintSetupState.url_prefix
"""

parts = {'b' : registration_prefix,
'a' : self.prefix,
'e' : url_part}
parts = {
'b': registration_prefix,
'a': self.prefix,
'e': url_part
}
return ''.join(parts[key] for key in self.url_part_order if parts[key])

@staticmethod
Expand Down Expand Up @@ -230,7 +231,6 @@ def _should_use_fr_error_handler(self):
# Werkzeug throws other kinds of exceptions, such as Redirect
pass


def _has_fr_route(self):
"""Encapsulating the rules for whether the request was to a Flask endpoint"""
# 404's, 405's, which might not have a url_rule
Expand Down Expand Up @@ -300,9 +300,10 @@ def handle_error(self, e):
data["message"] = ""

data['message'] += 'You have requested this URI [' + request.path + \
'] but did you mean ' + \
' or '.join((rules[match]
for match in close_matches)) + ' ?'
'] but did you mean ' + \
' or '.join((
rules[match] for match in close_matches)
) + ' ?'

resp = self.make_response(data, code)

Expand Down Expand Up @@ -345,7 +346,6 @@ def add_resource(self, resource, *urls, **kwargs):
else:
self.resources.append((resource, urls, kwargs))


def _register_view(self, app, resource, *urls, **kwargs):
endpoint = kwargs.pop('endpoint', None) or resource.__name__.lower()
self.endpoints.add(endpoint)
Expand All @@ -364,7 +364,6 @@ def _register_view(self, app, resource, *urls, **kwargs):
for decorator in self.decorators:
resource_func = decorator(resource_func)


for url in urls:
# If this Api has a blueprint
if self.blueprint:
Expand Down Expand Up @@ -528,8 +527,8 @@ def make(cls):
return [marshal(d, fields) for d in data]

items = ((k, marshal(data, v) if isinstance(v, dict)
else make(v).output(k, data))
for k, v in fields.items())
else make(v).output(k, data))
for k, v in fields.items())
return OrderedDict(items)


Expand Down
2 changes: 1 addition & 1 deletion flask_restful/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def __init__(self, endpoint, absolute=False, scheme=None):
def output(self, key, obj):
try:
data = to_marshallable_type(obj)
o = urlparse(url_for(self.endpoint, _external = self.absolute, **data))
o = urlparse(url_for(self.endpoint, _external=self.absolute, **data))
if self.absolute:
scheme = self.scheme if self.scheme is not None else o.scheme
return urlunparse((scheme, o.netloc, o.path, "", "", ""))
Expand Down
1 change: 1 addition & 0 deletions flask_restful/representations/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# function, used below.
settings = {}


def output_json(data, code, headers=None):
"""Makes a Flask response with a JSON encoded body"""

Expand Down
5 changes: 4 additions & 1 deletion flask_restful/reqparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import inspect
import six


class Namespace(dict):
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)

def __setattr__(self, name, value):
self[name] = value

Expand All @@ -24,6 +26,7 @@ def __setattr__(self, name, value):

text_type = lambda x: six.text_type(x)


class Argument(object):

def __init__(self, name, default=None, dest=None, required=False,
Expand Down Expand Up @@ -155,7 +158,7 @@ def parse(self, request):
_friendly_location.get(self.location, self.location)
)
else:
friendly_locations = [_friendly_location.get(loc, loc) \
friendly_locations = [_friendly_location.get(loc, loc)
for loc in self.location]
error_msg = u"Missing required parameter {0} in {1}".format(
self.name,
Expand Down
2 changes: 2 additions & 0 deletions flask_restful/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from werkzeug.http import HTTP_STATUS_CODES


def http_status_message(code):
"""Maps an HTTP status code to the textual status"""
return HTTP_STATUS_CODES.get(code, '')


def error_data(code):
"""Constructs a dictionary with status and message for returning in an
error response"""
Expand Down
1 change: 1 addition & 0 deletions flask_restful/utils/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask import make_response, request, current_app
from functools import update_wrapper


def crossdomain(origin=None, methods=None, headers=None,
max_age=21600, attach_to_all=True,
automatic_options=True):
Expand Down
6 changes: 6 additions & 0 deletions flask_restful/utils/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@
from Crypto.Cipher import AES
from base64 import b64encode, b64decode


__all__ = "encrypt", "decrypt"

BLOCK_SIZE = 16
INTERRUPT = b'\0' # something impossible to put in a string
PADDING = b'\1'


def pad(data):
return data + INTERRUPT + PADDING * (BLOCK_SIZE - (len(data) + 1) % BLOCK_SIZE)


def strip(data):
return data.rstrip(PADDING).rstrip(INTERRUPT)


def create_cipher(key, seed):
if len(seed) != 16:
raise ValueError("Choose a seed of 16 bytes")
if len(key) != 32:
raise ValueError("Choose a key of 32 bytes")
return AES.new(key, AES.MODE_CBC, seed)


def encrypt(plaintext_data, key, seed):
plaintext_data = pickle.dumps(plaintext_data, pickle.HIGHEST_PROTOCOL) # whatever you give me I need to be able to restitute it
return b64encode(create_cipher(key, seed).encrypt(pad(plaintext_data)))


def decrypt(encrypted_data, key, seed):
return pickle.loads(strip(create_cipher(key, seed).decrypt(b64decode(encrypted_data))))
3 changes: 2 additions & 1 deletion flask_restful/utils/ordereddict.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from UserDict import DictMixin
import six


class OrderedDict(dict, DictMixin):

#noinspection PyMissingConstructor
Expand Down Expand Up @@ -120,7 +121,7 @@ def __eq__(self, other):
if isinstance(other, OrderedDict):
if len(self) != len(other):
return False
for p, q in zip(self.items(), other.items()):
for p, q in zip(self.items(), other.items()):
if p != q:
return False
return True
Expand Down
Loading

0 comments on commit 9d69029

Please sign in to comment.