Completed
Push — master ( d36755...584f50 )
by Jace
14s
created

InvalidImageLink

Complexity

Total Complexity 0

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
wmc 0
1 1
import os
2 1
import logging
3 1
from urllib.parse import urlencode, unquote
4
5 1
from flask import request, current_app
0 ignored issues
show
Configuration introduced by
The import flask could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
6 1
from flask_api import FlaskAPI
0 ignored issues
show
Configuration introduced by
The import flask_api could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
7 1
from flask_api.exceptions import APIException, NotFound
0 ignored issues
show
Configuration introduced by
The import flask_api.exceptions could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
8
9 1
from . import services
10 1
from . import stores
11 1
from . import routes
12 1
from . import extensions
13
14 1
log = logging.getLogger('api')
15
16
17 1
class TemplateNotFound(NotFound):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
18 1
    detail = "Template not found."
19
20
21 1
class InvalidMaskedCode(NotFound):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
22 1
    detail = "Masked URL does not match any image."
23
24
25 1
class FilenameTooLong(APIException):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
26 1
    status_code = 414
27 1
    detail = "Filename too long."
28
29
30 1
class InvalidImageLink(APIException):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
31 1
    status_code = 415
32 1
    detail = "Unsupported image type."
33
34
35 1
def create_app(config):
36 1
    app = FlaskAPI(__name__)
37 1
    app.config.from_object(config)
38
39 1
    configure_logging(app)
40
41 1
    register_extensions(app)
42
43 1
    register_services(app)
44 1
    register_blueprints(app)
45
46 1
    return app
47
48
49 1
def configure_logging(app):
50 1
    if app.config['DEBUG']:
51 1
        level = logging.DEBUG
52
    else:
53 1
        level = logging.INFO
54 1
    logging.basicConfig(level=level, format="%(levelname)s: %(message)s")
55 1
    logging.getLogger('yorm').setLevel(logging.WARNING)
56 1
    logging.getLogger('requests').setLevel(logging.WARNING)
57 1
    logging.getLogger('PIL').setLevel(logging.INFO)
58
59
60 1
def register_extensions(app):
61 1
    extensions.db.init_app(app)
62 1
    extensions.migrate.init_app(app, extensions.db)
63
64
65 1
def register_services(app):
66 1
    exceptions = services.Exceptions(
67
        TemplateNotFound,
68
        InvalidMaskedCode,
69
        FilenameTooLong,
70
        InvalidImageLink,
71
    )
72
73 1
    templates_root = os.path.join(app.config['ROOT'], 'data', 'templates')
74 1
    template_store = stores.template.TemplateStore(templates_root)
75 1
    images_root = os.path.join(app.config['ROOT'], 'data', 'images')
76 1
    image_store = stores.image.ImageStore(images_root, app.config)
77
78 1
    app.link_service = services.link.LinkService(
79
        exceptions=exceptions,
80
        template_store=template_store,
81
    )
82 1
    app.template_service = services.template.TemplateService(
83
        exceptions=exceptions,
84
        template_store=template_store,
85
    )
86 1
    app.image_service = services.image.ImageService(
87
        exceptions=exceptions,
88
        template_store=template_store,
89
        image_store=image_store,
90
    )
91
92 1
    def log_request(response):
93 1
        if current_app.debug:
94 1
            path = request.path
95 1
            if request.args:
96 1
                path += "?%s" % unquote(urlencode(request.args))
97 1
            log.info("%s: %s - %i", request.method, path,
98
                     response.status_code)
99 1
        return response
100 1
    app.after_request(log_request)
101
102
103 1
def register_blueprints(app):
104 1
    app.register_blueprint(routes.aliases.blueprint)
105 1
    app.register_blueprint(routes.image.blueprint)
106 1
    app.register_blueprint(routes.index.blueprint)
107 1
    app.register_blueprint(routes.latest.blueprint)
108 1
    app.register_blueprint(routes.links.blueprint)
109 1
    app.register_blueprint(routes.magic.blueprint)
110 1
    app.register_blueprint(routes.root.blueprint)
111 1
    app.register_blueprint(routes.static.blueprint)
112
    app.register_blueprint(routes.templates.blueprint)
113