/usr/local/lib64/python3.6/site-packages/flask/__pycache__
NameSizeModeActions
app.cpython-36.pyc628380644editdlrm
blueprints.cpython-36.pyc218950644editdlrm
cli.cpython-36.pyc268820644editdlrm
config.cpython-36.pyc115620644editdlrm
ctx.cpython-36.pyc154410644editdlrm
debughelpers.cpython-36.pyc63770644editdlrm
globals.cpython-36.pyc17420644editdlrm
helpers.cpython-36.pyc270040644editdlrm
logging.cpython-36.pyc24000644editdlrm
scaffold.cpython-36.pyc247450644editdlrm
sessions.cpython-36.pyc135440644editdlrm
signals.cpython-36.pyc23320644editdlrm
templating.cpython-36.pyc54490644editdlrm
testing.cpython-36.pyc90890644editdlrm
typing.cpython-36.pyc13630644editdlrm
views.cpython-36.pyc49100644editdlrm
wrappers.cpython-36.pyc49010644editdlrm
__init__.cpython-36.pyc18390644editdlrm
__main__.cpython-36.pyc1700644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/flask/__pycache__/scaffold.cpython-36.pyc (24745B)
3 ^TBg@sddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl m Z ddlmZddlmZddlmZd d lmZd d lmZd d lmZd d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlm Z d dlm!Z!d dlm"Z"d dlm#Z#d dlm$Z$ej%rDd dl&m'Z'd dlm(Z(e)Z*ej+dej,dej-fdZ.e.e.dddZ/Gd d!d!Z0ej,e1d"d#d$Z2d%d&Z3d'd(Z4e1d)d*d+Z5dS),N) defaultdict)update_wrapper) JSONDecoder) JSONEncoder)FileSystemLoader)default_exceptions) HTTPException)AppGroup) current_app) get_root_path)locked_cached_property)send_from_directory)_default_template_ctx_processor)AfterRequestCallable)AppOrBlueprintKey)BeforeRequestCallable)GenericException)TeardownCallable) TemplateContextProcessorCallable)URLDefaultCallable)URLValuePreprocessorCallable)Response)ErrorHandlerCallableF.)Zbound)freturncs.tjtjtjdfdd }tjtt|S)zkWraps a method so that it performs a check in debug mode if the first request was already handled. )argskwargsrcs |jrtd|f||S)NamA setup function was called after the first request was handled. This usually indicates a bug in the application where a module was not imported and decorators or other functionality was called too late. To fix this make sure to import all your view modules, database models, and everything related at a central place before the application starts serving requests.)_is_setup_finishedAssertionError)selfrr)r//tmp/pip-build-0s3hx122/flask/flask/scaffold.py wrapper_func-s z!setupmethod..wrapper_func)tAnycastrr)rr$r")rr# setupmethod(sr(c @seZdZUdZedZejedZ eje dZ ejej e  dZ ejej e dMeejejeejfejeejeejedddZedddZedd d Zeejedd d Zejejejeejfdd dd ZeedddZeejedddZejejedd ddZejeejedddZeddddZeejedddZ dNeeej!ej"dddZ#eee$ej%d d!d"Z&eej'ej%d#d$d%Z(eej'ej%d#d&d'Z)eej'ej%d#d(d)Z*eej'ej%d#d*d+Z+eej'ej%d#d,d-Z,eej'ej%d#d.d/Z-e.dOeejeejej%ejeej'dd0d1d2Z/eej%d3d4d5Z0e.e1e1d6d7d8Z2e.e3e3d6d9d:Z4e.e5e5d6d;d<Z6e.e7e7d6d=d>Z8e.e9e9d6d?d@Z:e.e;e;d6dAdBZe.ejej e=efdCddGdHdIZ?e@ejej eAefejBej eAejefdJdKdLZCdS)PScaffoldaCommon behavior shared between :class:`~flask.Flask` and :class:`~flask.blueprints.Blueprint`. :param import_name: The import name of the module where this object is defined. Usually :attr:`__name__` should be used. :param static_folder: Path to a folder of static files to serve. If this is set, a static route will be added. :param static_url_path: URL prefix for the static route. :param template_folder: Path to a folder containing template files. for rendering. If this is set, a Jinja loader will be added. :param root_path: The path that static, template, and resource files are relative to. Typically not set, it is discovered based on the ``import_name``. .. versionadded:: 2.0 N) import_name static_folderstatic_url_pathtemplate_folder root_pathcCs||_||_||_||_|dkr*t|j}||_t|_i|_t dd|_ t t |_ t t |_ t t |_t t dtgi|_t t |_t t |_dS)NcSsttS)N)rdictr"r"r"r#sz#Scaffold.__init__..)r*r+r,r-r r.r cliview_functionsrerror_handler_speclistbefore_request_funcsafter_request_funcsteardown_request_funcsrtemplate_context_processorsurl_value_preprocessorsurl_default_functions)r!r*r+r,r-r.r"r"r#__init__\s      zScaffold.__init__)rcCsdt|jd|jdS)N< >)type__name__name)r!r"r"r#__repr__szScaffold.__repr__cCstdS)N)NotImplementedError)r!r"r"r#rszScaffold._is_setup_finishedcCs$|jdk rtjj|j|jSdSdS)zhThe absolute path to the configured static folder. ``None`` if no static folder is set. N)_static_folderospathjoinr.)r!r"r"r#r+s zScaffold.static_folder)valuercCs"|dk rtj|jd}||_dS)Nz\/)rEfspathrstriprD)r!rHr"r"r#r+scCs |jdk S)zQ``True`` if :attr:`static_folder` is set. .. versionadded:: 0.5 N)r+)r!r"r"r#has_static_folder szScaffold.has_static_foldercCs<|jdk r|jS|jdk r8tjj|j}d|jdSdS)zThe URL prefix that the static route will be accessible from. If it was not configured during init, it is derived from :attr:`static_folder`. N/)_static_url_pathr+rErFbasenamerJ)r!rNr"r"r#r,s   zScaffold.static_url_pathcCs|dk r|jd}||_dS)NrL)rJrM)r!rHr"r"r#r,"s )filenamercCstj}|dkrdSt|jS)aUsed by :func:`send_file` to determine the ``max_age`` cache value for a given file path if it wasn't passed. By default, this returns :data:`SEND_FILE_MAX_AGE_DEFAULT` from the configuration of :data:`~flask.current_app`. This defaults to ``None``, which tells the browser to use conditional requests instead of a timed cache, which is usually preferable. .. versionchanged:: 2.0 The default configuration is ``None`` instead of 12 hours. .. versionadded:: 0.9 N)r Zsend_file_max_age_defaultint total_seconds)r!rOrHr"r"r#get_send_file_max_age)szScaffold.get_send_file_max_agercCs0|jstd|j|}ttjt|j||dS)zThe view function used to serve files from :attr:`static_folder`. A route is automatically registered for this view at :attr:`static_url_path` if :attr:`static_folder` is set. .. versionadded:: 0.5 z2'static_folder' must be set to serve static_files.)max_age)rK RuntimeErrorrRrr%r'strr+)r!rOrSr"r"r#send_static_file>s  zScaffold.send_static_filecCs(|jdk r ttjj|j|jSdSdS)zThe Jinja loader for this object's templates. By default this is a class :class:`jinja2.loaders.FileSystemLoader` to :attr:`template_folder` if it is set. .. versionadded:: 0.5 N)r-rrErFrGr.)r!r"r"r# jinja_loaderPs zScaffold.jinja_loaderrb)resourcemodercCs&|dkrtdttjj|j||S)aKOpen a resource file relative to :attr:`root_path` for reading. For example, if the file ``schema.sql`` is next to the file ``app.py`` where the ``Flask`` app is defined, it can be opened with: .. code-block:: python with app.open_resource("schema.sql") as f: conn.executescript(f.read()) :param resource: Path to the resource relative to :attr:`root_path`. :param mode: Open the file in this mode. Only reading is supported, valid values are "r" (or "rt") and "rb". rrtrXz)Resources can only be opened for reading.>rXr\r[) ValueErroropenrErFrGr.)r!rYrZr"r"r# open_resource]szScaffold.open_resource)methodruleoptionsrcCs(d|krtd|j|fd|gi|S)Nmethodsz8Use the 'route' decorator to use the 'methods' argument.) TypeErrorroute)r!r`rarbr"r"r# _method_routetszScaffold._method_route)rarbrcKs|jd||S)z\Shortcut for :meth:`route` with ``methods=["GET"]``. .. versionadded:: 2.0 GET)rf)r!rarbr"r"r#getzsz Scaffold.getcKs|jd||S)z]Shortcut for :meth:`route` with ``methods=["POST"]``. .. versionadded:: 2.0 POST)rf)r!rarbr"r"r#postsz Scaffold.postcKs|jd||S)z\Shortcut for :meth:`route` with ``methods=["PUT"]``. .. versionadded:: 2.0 PUT)rf)r!rarbr"r"r#putsz Scaffold.putcKs|jd||S)z_Shortcut for :meth:`route` with ``methods=["DELETE"]``. .. versionadded:: 2.0 DELETE)rf)r!rarbr"r"r#deleteszScaffold.deletecKs|jd||S)z^Shortcut for :meth:`route` with ``methods=["PATCH"]``. .. versionadded:: 2.0 PATCH)rf)r!rarbr"r"r#patchszScaffold.patchc s tjtjdfdd }|S)aDecorate a view function to register it with the given URL rule and options. Calls :meth:`add_url_rule`, which has more details about the implementation. .. code-block:: python @app.route("/") def index(): return "Hello, World!" See :ref:`url-route-registrations`. The endpoint name for the route defaults to the name of the view function if the ``endpoint`` parameter isn't passed. The ``methods`` parameter defaults to ``["GET"]``. ``HEAD`` and ``OPTIONS`` are added automatically. :param rule: The URL rule string. :param options: Extra options passed to the :class:`~werkzeug.routing.Rule` object. )rrcs"jdd}j||f|S)Nendpoint)pop add_url_rule)rrq)rbrar!r"r# decorators z!Scaffold.route..decorator)r%Callable)r!rarbrtr")rbrar!r#reszScaffold.route)rarq view_funcprovide_automatic_optionsrbrcKstdS)a;Register a rule for routing incoming requests and building URLs. The :meth:`route` decorator is a shortcut to call this with the ``view_func`` argument. These are equivalent: .. code-block:: python @app.route("/") def index(): ... .. code-block:: python def index(): ... app.add_url_rule("/", view_func=index) See :ref:`url-route-registrations`. The endpoint name for the route defaults to the name of the view function if the ``endpoint`` parameter isn't passed. An error will be raised if a function has already been registered for the endpoint. The ``methods`` parameter defaults to ``["GET"]``. ``HEAD`` is always added automatically, and ``OPTIONS`` is added automatically by default. ``view_func`` does not necessarily need to be passed, but if the rule should participate in routing an endpoint name must be associated with a view function at some point with the :meth:`endpoint` decorator. .. code-block:: python app.add_url_rule("/", endpoint="index") @app.endpoint("index") def index(): ... If ``view_func`` has a ``required_methods`` attribute, those methods are added to the passed and automatic methods. If it has a ``provide_automatic_methods`` attribute, it is used as the default if the parameter is not passed. :param rule: The URL rule string. :param endpoint: The endpoint name to associate with the rule and view function. Used when routing and building URLs. Defaults to ``view_func.__name__``. :param view_func: The view function to associate with the endpoint name. :param provide_automatic_options: Add the ``OPTIONS`` method and respond to ``OPTIONS`` requests automatically. :param options: Extra options passed to the :class:`~werkzeug.routing.Rule` object. N)rC)r!rarqrvrwrbr"r"r#rssBzScaffold.add_url_rule)rqrcsfdd}|S)aDecorate a view function to register it for the given endpoint. Used if a rule is added without a ``view_func`` with :meth:`add_url_rule`. .. code-block:: python app.add_url_rule("/ex", endpoint="example") @app.endpoint("example") def example(): ... :param endpoint: The endpoint name to associate with the view function. cs|j<|S)N)r2)r)rqr!r"r#rts z$Scaffold.endpoint..decoratorr")r!rqrtr")rqr!r#rqszScaffold.endpoint)rrcCs|jjdgj||S)a`Register a function to run before each request. For example, this can be used to open a database connection, or to load the logged in user from the session. .. code-block:: python @app.before_request def load_user(): if "user_id" in session: g.user = db.session.get(session["user_id"]) The function will be called without any arguments. If it returns a non-``None`` value, the value is handled as if it was the return value from the view, and further request handling is stopped. N)r5 setdefaultappend)r!rr"r"r#before_requestszScaffold.before_requestcCs|jjdgj||S)a Register a function to run after each request to this object. The function is called with the response object, and must return a response object. This allows the functions to modify or replace the response before it is sent. If a function raises an exception, any remaining ``after_request`` functions will not be called. Therefore, this should not be used for actions that must execute, such as to close resources. Use :meth:`teardown_request` for that. N)r6rxry)r!rr"r"r# after_request-s zScaffold.after_requestcCs|jjdgj||S)arRegister a function to be run at the end of each request, regardless of whether there was an exception or not. These functions are executed when the request context is popped, even if not an actual request was performed. Example:: ctx = app.test_request_context() ctx.push() ... ctx.pop() When ``ctx.pop()`` is executed in the above example, the teardown functions are called just before the request context moves from the stack of active contexts. This becomes relevant if you are using such constructs in tests. Teardown functions must avoid raising exceptions, since they . If they execute code that might fail they will have to surround the execution of these code by try/except statements and log occurring errors. When a teardown function was called because of an exception it will be passed an error object. The return values of teardown functions are ignored. .. admonition:: Debug Note In debug mode Flask will not tear down a request on an exception immediately. Instead it will keep it alive so that the interactive debugger can still access it. This behavior can be controlled by the ``PRESERVE_CONTEXT_ON_EXCEPTION`` configuration variable. N)r7rxry)r!rr"r"r#teardown_request=s$zScaffold.teardown_requestcCs|jdj||S)z0Registers a template context processor function.N)r8ry)r!rr"r"r#context_processordszScaffold.context_processorcCs|jdj||S)a#Register a URL value preprocessor function for all view functions in the application. These functions will be called before the :meth:`before_request` functions. The function can modify the values captured from the matched url before they are passed to the view. For example, this can be used to pop a common language code value and place it in ``g`` rather than pass it to every view. The function is passed the endpoint name and values dict. The return value is ignored. N)r9ry)r!rr"r"r#url_value_preprocessorlszScaffold.url_value_preprocessorcCs|jdj||S)zCallback function for URL defaults for all view functions of the application. It's called with the endpoint and values and should update the values passed in place. N)r:ry)r!rr"r"r# url_defaultsszScaffold.url_defaultsz&ErrorHandlerCallable[GenericException])code_or_exceptionrcsdddfdd }|S)a7Register a function to handle errors by code or exception class. A decorator that is used to register a function given an error code. Example:: @app.errorhandler(404) def page_not_found(error): return 'This page does not exist', 404 You can also register handlers for arbitrary exceptions:: @app.errorhandler(DatabaseError) def special_exception_handler(error): return 'Database connection failed', 500 .. versionadded:: 0.7 Use :meth:`register_error_handler` instead of modifying :attr:`error_handler_spec` directly, for application wide error handlers. .. versionadded:: 0.7 One can now additionally also register custom exception types that do not necessarily have to be a subclass of the :class:`~werkzeug.exceptions.HTTPException` class. :param code_or_exception: the code as integer for the handler, or an arbitrary exception z&ErrorHandlerCallable[GenericException])rrcsj||S)N)register_error_handler)r)rr!r"r#rts z(Scaffold.errorhandler..decoratorr")r!rrtr")rr!r# errorhandlers%zScaffold.errorhandler)rrrc Csrt|trtd|dy|j|\}}Wn&tk rRtd|ddYnXtjd||jd||<dS)zAlternative error attach function to the :meth:`errorhandler` decorator that is more straightforward to use for non decorator usage. .. versionadded:: 0.7 z6Tried to register a handler for an exception instance zL. Handlers can only be registered for exception classes or HTTP error codes.'z^' is not a recognized HTTP error code. Use a subclass of HTTPException with that code instead.NzErrorHandlerCallable[Exception]) isinstancerr]_get_exc_class_and_codeKeyErrorr%r'r3)r!rr exc_classcoder"r"r#rs   zScaffold.register_error_handler)exc_class_or_codercCsJt|trt|}n|}t|ts*tdt|tr>||jfS|dfSdS)a Get the exception class being handled. For HTTP status codes or ``HTTPException`` subclasses, return both the exception and status code. :param exc_class_or_code: Any exception class, or an HTTP status code as an integer. z2Custom exceptions must be subclasses of Exception.N)rrPr issubclass Exceptionr rr)rrr"r"r#rs     z Scaffold._get_exc_class_and_code)NNNN)rX)NNN)Dr@ __module__ __qualname____doc__rUrArDr%OptionalrMZ json_encoderTyperZ json_decoderrUnionrEPathLiker;rBboolrpropertyr+setterrKr,rPrRrVr rrWZIOZAnyStrr_r/rurfr&rhrjrlrnrprer(rsrqrrzrr{rr|rr}rr~rrrrr staticmethodrZTuplerr"r"r"r#r)>s < $ <&'r))rvrcCs|dk std|jS)zsInternal helper that returns the default endpoint for a given function. This always is the function name. Nz/expected view func if endpoint is not provided.)r r@)rvr"r"r#_endpoint_from_view_funcsrcCsJt|dr|j|St|}|jdkr4|jdkr4dStd|jddS)zAttempt to figure out if the given name is a package or a module. :param: loader: The loader that handled the name. :param mod_name: The name of the package or module. is_package_frozen_importlibZNamespaceLoaderTrz<.is_package()' must be implemented for PEP 302 import hooks.N)hasattrrr?rr@AttributeError)loaderZmod_nameclsr"r"r#)_matching_loader_thinks_module_is_packages  rc Cs y tjj|}|dkrtdWnttfk r8YnLX|jdkrZtjjt t |j S|j rvtjjtjj|jStjj|jSt j |}|dks|dkrtjSt|dr|j|}nt|dr|j}n tj|j}tjjtjj|}t||rtjj|}|S)z2Find the path that contains the package or module.Nz not found namespace__main__ get_filenamearchive>rN) importlibutil find_specr] ImportErrororiginrErFdirnamenextitersubmodule_search_locationspkgutil get_loadergetcwdrrr import_module__file__abspathr) root_mod_namespecrrO package_pathr"r"r#_find_package_paths.          r)r*c Cs|jd\}}}t|}tjjtj}|j|r8||fStjj|\}}|j dkrtjj|\}}|j dkrx||fStjj |j dkrtjj ||fS||fSd|fS)aFind the prefix that a package is installed under, and the path that it would be imported from. The prefix is the directory containing the standard directory hierarchy (lib, bin, etc.). If the package is not installed to the system (:attr:`sys.prefix`) or a virtualenv (``site-packages``), ``None`` is returned. The path is the entry in :attr:`sys.path` that contains the package for import. If the package is not installed, it's assumed that the package was imported from the current working directory. .z site-packageslibN) partitionrrErFrsysprefix startswithsplitlowerrNr) r*r_rZ py_prefixZ site_parentZ site_folderparentZfolderr"r"r# find_packageDs    r)6importlib.utilrrErrZtypingr% collectionsr functoolsrjsonrrZjinja2rZwerkzeug.exceptionsrrr1r globalsr helpersr r rZ templatingrrrrrrrrrZ TYPE_CHECKINGZwrappersrrobject _sentinelZTypeVarrur&rr(r)rUrrrrr"r"r"r#sR                       64