You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. """
  2. werkzeug
  3. ~~~~~~~~
  4. Werkzeug is the Swiss Army knife of Python web development.
  5. It provides useful classes and functions for any WSGI application to
  6. make the life of a Python web developer much easier. All of the provided
  7. classes are independent from each other so you can mix it with any other
  8. library.
  9. :copyright: 2007 Pallets
  10. :license: BSD-3-Clause
  11. """
  12. from types import ModuleType
  13. __version__ = "0.16.0"
  14. __all__ = ["run_simple", "Client", "Request", "Response", "__version__"]
  15. class _DeprecatedImportModule(ModuleType):
  16. """Wrap a module in order to raise """
  17. def __init__(self, name, available, removed_in):
  18. import sys
  19. super(_DeprecatedImportModule, self).__init__(name) # noqa F821
  20. self._real_module = sys.modules[name] # noqa F821
  21. sys.modules[name] = self
  22. self._removed_in = removed_in
  23. self._origin = {item: mod for mod, items in available.items() for item in items}
  24. mod_all = getattr(self._real_module, "__all__", dir(self._real_module))
  25. self.__all__ = sorted(mod_all + list(self._origin))
  26. def __getattr__(self, item):
  27. # Don't export internal variables.
  28. if item in {"_real_module", "_origin", "_removed_in"}:
  29. raise AttributeError(item)
  30. if item in self._origin:
  31. from importlib import import_module
  32. origin = self._origin[item]
  33. if origin == ".":
  34. # No warning for the "submodule as attribute" case, it's way too messy
  35. # and unreliable to try to distinguish 'from werkzueug import
  36. # exceptions' and 'import werkzeug; werkzeug.exceptions'.
  37. value = import_module(origin + item, self.__name__)
  38. else:
  39. from warnings import warn
  40. # Import the module, get the attribute, and show a warning about where
  41. # to correctly import it from.
  42. mod = import_module(origin, self.__name__.rsplit(".")[0])
  43. value = getattr(mod, item)
  44. warn(
  45. "The import '{name}.{item}' is deprecated and will be removed in"
  46. " {removed_in}. Use 'from {name}{origin} import {item}'"
  47. " instead.".format(
  48. name=self.__name__,
  49. item=item,
  50. removed_in=self._removed_in,
  51. origin=origin,
  52. ),
  53. DeprecationWarning,
  54. stacklevel=2,
  55. )
  56. else:
  57. value = getattr(self._real_module, item)
  58. # Cache the value so it won't go through this process on subsequent accesses.
  59. setattr(self, item, value)
  60. return value
  61. def __dir__(self):
  62. return sorted(dir(self._real_module) + list(self._origin))
  63. del ModuleType
  64. _DeprecatedImportModule(
  65. __name__,
  66. {
  67. ".": ["exceptions", "routing"],
  68. "._internal": ["_easteregg"],
  69. ".datastructures": [
  70. "Accept",
  71. "Authorization",
  72. "CallbackDict",
  73. "CharsetAccept",
  74. "CombinedMultiDict",
  75. "EnvironHeaders",
  76. "ETags",
  77. "FileMultiDict",
  78. "FileStorage",
  79. "Headers",
  80. "HeaderSet",
  81. "ImmutableDict",
  82. "ImmutableList",
  83. "ImmutableMultiDict",
  84. "ImmutableOrderedMultiDict",
  85. "ImmutableTypeConversionDict",
  86. "LanguageAccept",
  87. "MIMEAccept",
  88. "MultiDict",
  89. "OrderedMultiDict",
  90. "RequestCacheControl",
  91. "ResponseCacheControl",
  92. "TypeConversionDict",
  93. "WWWAuthenticate",
  94. ],
  95. ".debug": ["DebuggedApplication"],
  96. ".exceptions": ["abort", "Aborter"],
  97. ".formparser": ["parse_form_data"],
  98. ".http": [
  99. "cookie_date",
  100. "dump_cookie",
  101. "dump_header",
  102. "dump_options_header",
  103. "generate_etag",
  104. "http_date",
  105. "HTTP_STATUS_CODES",
  106. "is_entity_header",
  107. "is_hop_by_hop_header",
  108. "is_resource_modified",
  109. "parse_accept_header",
  110. "parse_authorization_header",
  111. "parse_cache_control_header",
  112. "parse_cookie",
  113. "parse_date",
  114. "parse_dict_header",
  115. "parse_etags",
  116. "parse_list_header",
  117. "parse_options_header",
  118. "parse_set_header",
  119. "parse_www_authenticate_header",
  120. "quote_etag",
  121. "quote_header_value",
  122. "remove_entity_headers",
  123. "remove_hop_by_hop_headers",
  124. "unquote_etag",
  125. "unquote_header_value",
  126. ],
  127. ".local": [
  128. "Local",
  129. "LocalManager",
  130. "LocalProxy",
  131. "LocalStack",
  132. "release_local",
  133. ],
  134. ".middleware.dispatcher": ["DispatcherMiddleware"],
  135. ".middleware.shared_data": ["SharedDataMiddleware"],
  136. ".security": ["check_password_hash", "generate_password_hash"],
  137. ".test": ["create_environ", "EnvironBuilder", "run_wsgi_app"],
  138. ".testapp": ["test_app"],
  139. ".urls": [
  140. "Href",
  141. "iri_to_uri",
  142. "uri_to_iri",
  143. "url_decode",
  144. "url_encode",
  145. "url_fix",
  146. "url_quote",
  147. "url_quote_plus",
  148. "url_unquote",
  149. "url_unquote_plus",
  150. ],
  151. ".useragents": ["UserAgent"],
  152. ".utils": [
  153. "append_slash_redirect",
  154. "ArgumentValidationError",
  155. "bind_arguments",
  156. "cached_property",
  157. "environ_property",
  158. "escape",
  159. "find_modules",
  160. "format_string",
  161. "header_property",
  162. "html",
  163. "HTMLBuilder",
  164. "import_string",
  165. "redirect",
  166. "secure_filename",
  167. "unescape",
  168. "validate_arguments",
  169. "xhtml",
  170. ],
  171. ".wrappers.accept": ["AcceptMixin"],
  172. ".wrappers.auth": ["AuthorizationMixin", "WWWAuthenticateMixin"],
  173. ".wrappers.base_request": ["BaseRequest"],
  174. ".wrappers.base_response": ["BaseResponse"],
  175. ".wrappers.common_descriptors": [
  176. "CommonRequestDescriptorsMixin",
  177. "CommonResponseDescriptorsMixin",
  178. ],
  179. ".wrappers.etag": ["ETagRequestMixin", "ETagResponseMixin"],
  180. ".wrappers.response": ["ResponseStreamMixin"],
  181. ".wrappers.user_agent": ["UserAgentMixin"],
  182. ".wsgi": [
  183. "ClosingIterator",
  184. "extract_path_info",
  185. "FileWrapper",
  186. "get_current_url",
  187. "get_host",
  188. "LimitedStream",
  189. "make_line_iter",
  190. "peek_path_info",
  191. "pop_path_info",
  192. "responder",
  193. "wrap_file",
  194. ],
  195. },
  196. "Werkzeug 1.0",
  197. )
  198. from .serving import run_simple
  199. from .test import Client
  200. from .wrappers import Request
  201. from .wrappers import Response