diff --git a/examples/look/look/app.py b/examples/look/look/app.py index c395c4446..7b591ce40 100644 --- a/examples/look/look/app.py +++ b/examples/look/look/app.py @@ -2,7 +2,9 @@ import falcon -from .images import Collection, ImageStore, Item +from .images import Collection +from .images import ImageStore +from .images import Item def create_app(image_store): @@ -16,4 +18,3 @@ def get_app(): storage_path = os.environ.get('LOOK_STORAGE_PATH', '.') image_store = ImageStore(storage_path) return create_app(image_store) - diff --git a/examples/look/look/images.py b/examples/look/look/images.py index 8d099d99f..8f2332fc2 100644 --- a/examples/look/look/images.py +++ b/examples/look/look/images.py @@ -1,11 +1,10 @@ import io +import json import mimetypes import os import re import uuid -import json - import falcon @@ -14,13 +13,9 @@ def __init__(self, image_store): self._image_store = image_store def on_get(self, req, resp): - max_size = req.get_param_as_int("maxsize", min_value=1, default=-1) + max_size = req.get_param_as_int('maxsize', min_value=1, default=-1) images = self._image_store.list(max_size) - doc = { - 'images': [ - {'href': '/images/' + image} for image in images - ] - } + doc = {'images': [{'href': '/images/' + image} for image in images]} resp.text = json.dumps(doc, ensure_ascii=False) resp.status = falcon.HTTP_200 @@ -32,7 +27,6 @@ def on_post(self, req, resp): class Item: - def __init__(self, image_store): self._image_store = image_store @@ -82,7 +76,8 @@ def open(self, name): def list(self, max_size): images = [ - image for image in os.listdir(self._storage_path) + image + for image in os.listdir(self._storage_path) if self._IMAGE_NAME_PATTERN.match(image) and ( max_size == -1 @@ -90,4 +85,3 @@ def list(self, max_size): ) ] return images - diff --git a/examples/look/tests/test_app.py b/examples/look/tests/test_app.py index 645969a1d..2202a8ee4 100644 --- a/examples/look/tests/test_app.py +++ b/examples/look/tests/test_app.py @@ -1,14 +1,13 @@ import io import json import os -import uuid from unittest import TestCase from unittest.mock import call from unittest.mock import MagicMock from unittest.mock import mock_open +import uuid from wsgiref.validate import InputWrapper -import msgpack import pytest import falcon @@ -123,8 +122,8 @@ def test_listing_images(): storage_path = '.' file_paths = [f'{storage_path}/{name}' for name in file_names] fake_images_bytes = [ - b'fake-image-bytes', # 17 - b'fake-image-bytes-with-more-length', # 34 + b'fake-image-bytes', # 17 + b'fake-image-bytes-with-more-length', # 34 ] for i in range(2): with open(file_paths[i], 'wb') as image_file: @@ -138,4 +137,3 @@ def test_listing_images(): for file_path in file_paths: os.remove(file_path) -