# Path: vilya/core.py
# class VilyaError(Exception):
# class VilyaFormError(Exception):
# class Service(object):
#     def __init__(self, msg):
#     def __init__(self, errors=None):
#     def _isinstance(self, model, raise_error=True):
#     def _preprocess_params(self, kwargs):
#     def save(self, model):
#     def all(self):
#     def get(self, id):
#     def get_all(self, *ids):
#     def find(self, **kwargs):
#     def first(self, **kwargs):
#     def get_or_404(self, id):
#     def new(self, **kwargs):
#     def create(self, **kwargs):
#     def update(self, model, **kwargs):
#     def delete(self, model):
#     def transaction(cls, func):
#         def transaction_block(*args, **kwargs):
# 
# Path: vilya/helpers.py
# def register_blueprints(app, package_name, package_path):
#     """Register all Blueprint instances on the specified Flask application found
#     in all modules for the specified package.
# 
#     :param app: the Flask application
#     :param package_name: the package name
#     :param package_path: the package path
#     """
#     rv = []
#     for _, name, _ in pkgutil.iter_modules(package_path):
#         m = importlib.import_module('%s.%s' % (package_name, name))
#         for item in dir(m):
#             item = getattr(m, item)
#             if isinstance(item, Blueprint):
#                 app.register_blueprint(item)
#             rv.append(item)
#     return rv
# 
# Path: vilya/middleware.py
# class HTTPMethodOverrideMiddleware(object):
#     """The HTTPMethodOverrideMiddleware middleware implements the hidden HTTP
#     method technique. Not all web browsers support every HTTP method, such as
#     DELETE and PUT. This middleware class allows clients to provide a method
#     override parameter via an HTTP header value or a querystring parameter. This
#     middleware will look for the header paramter first followed by the
#     querystring. The default HTTP header name is `X-HTTP-METHOD-OVERRIDE` and
#     the default querystring parameter name is `__METHOD__`. These can be changed
#     via the constructor parameters `header_name` and `querystring_param`
#     respectively. Additionally, a list of allowed HTTP methods may be specified
#     via the `allowed_methods` constructor parameter. The default allowed methods
#     are GET, HEAD, POST, DELETE, PUT, PATCH, and OPTIONS.
#     """
# 
#     bodyless_methods = frozenset(['GET', 'HEAD', 'OPTIONS', 'DELETE'])
# 
#     def __init__(self, app, header_name=None,
#                  querystring_param=None, allowed_methods=None):
#         header_name = header_name or 'X-HTTP-METHOD-OVERRIDE'
# 
#         self.app = app
#         self.header_name = 'HTTP_' + header_name.replace('-', '_')
#         self.querystring_param = querystring_param or '__METHOD__'
#         self.allowed_methods = frozenset(allowed_methods or
#             ['GET', 'HEAD', 'POST', 'DELETE', 'PUT', 'PATCH', 'OPTIONS'])
# 
#     def _get_from_querystring(self, environ):
#         if self.querystring_param in environ.get('QUERY_STRING', ''):
#             args = url_decode(environ['QUERY_STRING'])
#             return args.get(self.querystring_param)
#         return None
# 
#     def _get_method_override(self, environ):
#         return environ.get(self.header_name, None) or \
#                self._get_from_querystring(environ) or ''
# 
#     def __call__(self, environ, start_response):
#         method = self._get_method_override(environ).upper()
# 
#         if method in self.allowed_methods:
#             method = method.encode('ascii', 'replace')
#             environ['REQUEST_METHOD'] = method
# 
#         if method in self.bodyless_methods:
#             environ['CONTENT_LENGTH'] = '0'
# 
#         return self.app(environ, start_response)
# 
# Path: vilya/models.py



import os
from celery import Celery
from flask import Flask
from flask_security import SQLAlchemyUserDatastore
from .core import db, mail, security
from .helpers import register_blueprints
from .middleware import HTTPMethodOverrideMiddleware
from .models import User, Role
# -*- coding: utf-8 -*-





def create_app(package_name, package_path, settings_override=None,
               register_security_blueprint=True):
    """Returns a :class:`Flask` application instance configured with common
    functionality for the Vilya platform.

    :param package_name: application package name
    :param package_path: application package path
    :param settings_override: a dictionary of settings to override
    :param register_security_blueprint: flag to specify if the Flask-Security
                                        Blueprint should be registered. Defaults
                                        to `True`.
    """
    app = Flask(package_name, instance_relative_config=True)

    app.config.from_object('vilya.settings')
    app.config.from_pyfile('settings.cfg', silent=True)
    app.config.from_object(settings_override)

    db.init_app(app)
    mail.init_app(app)

# Path: vilya/core.py
# class VilyaError(Exception):
# class VilyaFormError(Exception):
# class Service(object):
#     def __init__(self, msg):
#     def __init__(self, errors=None):
#     def _isinstance(self, model, raise_error=True):
#     def _preprocess_params(self, kwargs):
#     def save(self, model):
#     def all(self):
#     def get(self, id):
#     def get_all(self, *ids):
#     def find(self, **kwargs):
#     def first(self, **kwargs):
#     def get_or_404(self, id):
#     def new(self, **kwargs):
#     def create(self, **kwargs):
#     def update(self, model, **kwargs):
#     def delete(self, model):
#     def transaction(cls, func):
#         def transaction_block(*args, **kwargs):
# 
# Path: vilya/helpers.py
# def register_blueprints(app, package_name, package_path):
#     """Register all Blueprint instances on the specified Flask application found
#     in all modules for the specified package.
# 
#     :param app: the Flask application
#     :param package_name: the package name
#     :param package_path: the package path
#     """
#     rv = []
#     for _, name, _ in pkgutil.iter_modules(package_path):
#         m = importlib.import_module('%s.%s' % (package_name, name))
#         for item in dir(m):
#             item = getattr(m, item)
#             if isinstance(item, Blueprint):
#                 app.register_blueprint(item)
#             rv.append(item)
#     return rv
# 
# Path: vilya/middleware.py
# class HTTPMethodOverrideMiddleware(object):
#     """The HTTPMethodOverrideMiddleware middleware implements the hidden HTTP
#     method technique. Not all web browsers support every HTTP method, such as
#     DELETE and PUT. This middleware class allows clients to provide a method
#     override parameter via an HTTP header value or a querystring parameter. This
#     middleware will look for the header paramter first followed by the
#     querystring. The default HTTP header name is `X-HTTP-METHOD-OVERRIDE` and
#     the default querystring parameter name is `__METHOD__`. These can be changed
#     via the constructor parameters `header_name` and `querystring_param`
#     respectively. Additionally, a list of allowed HTTP methods may be specified
#     via the `allowed_methods` constructor parameter. The default allowed methods
#     are GET, HEAD, POST, DELETE, PUT, PATCH, and OPTIONS.
#     """
# 
#     bodyless_methods = frozenset(['GET', 'HEAD', 'OPTIONS', 'DELETE'])
# 
#     def __init__(self, app, header_name=None,
#                  querystring_param=None, allowed_methods=None):
#         header_name = header_name or 'X-HTTP-METHOD-OVERRIDE'
# 
#         self.app = app
#         self.header_name = 'HTTP_' + header_name.replace('-', '_')
#         self.querystring_param = querystring_param or '__METHOD__'
#         self.allowed_methods = frozenset(allowed_methods or
#             ['GET', 'HEAD', 'POST', 'DELETE', 'PUT', 'PATCH', 'OPTIONS'])
# 
#     def _get_from_querystring(self, environ):
#         if self.querystring_param in environ.get('QUERY_STRING', ''):
#             args = url_decode(environ['QUERY_STRING'])
#             return args.get(self.querystring_param)
#         return None
# 
#     def _get_method_override(self, environ):
#         return environ.get(self.header_name, None) or \
#                self._get_from_querystring(environ) or ''
# 
#     def __call__(self, environ, start_response):
#         method = self._get_method_override(environ).upper()
# 
#         if method in self.allowed_methods:
#             method = method.encode('ascii', 'replace')
#             environ['REQUEST_METHOD'] = method
# 
#         if method in self.bodyless_methods:
#             environ['CONTENT_LENGTH'] = '0'
# 
#         return self.app(environ, start_response)
# 
# Path: vilya/models.py



# Path: vilya/factory.py
import os
from celery import Celery
from flask import Flask
from flask_security import SQLAlchemyUserDatastore
from .core import db, mail, security
from .helpers import register_blueprints
from .middleware import HTTPMethodOverrideMiddleware
from .models import User, Role

# -*- coding: utf-8 -*-





def create_app(package_name, package_path, settings_override=None,
               register_security_blueprint=True):
    """Returns a :class:`Flask` application instance configured with common
    functionality for the Vilya platform.

    :param package_name: application package name
    :param package_path: application package path
    :param settings_override: a dictionary of settings to override
    :param register_security_blueprint: flag to specify if the Flask-Security
                                        Blueprint should be registered. Defaults
                                        to `True`.
    """
    app = Flask(package_name, instance_relative_config=True)

    app.config.from_object('vilya.settings')
    app.config.from_pyfile('settings.cfg', silent=True)
    app.config.from_object(settings_override)

    db.init_app(app)
    mail.init_app(app)

    security.init_app(app, SQLAlchemyUserDatastore(db, User, Role),