__init__.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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.1"
  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. package = self.__name__.rsplit(".")[0]
  43. mod = import_module(origin, package)
  44. value = getattr(mod, item)
  45. warn(
  46. "The import '{name}.{item}' is deprecated and will be removed in"
  47. " {removed_in}. Use 'from {package}{origin} import {item}'"
  48. " instead.".format(
  49. name=self.__name__,
  50. item=item,
  51. removed_in=self._removed_in,
  52. package=package,
  53. origin=origin,
  54. ),
  55. DeprecationWarning,
  56. stacklevel=2,
  57. )
  58. else:
  59. value = getattr(self._real_module, item)
  60. # Cache the value so it won't go through this process on subsequent accesses.
  61. setattr(self, item, value)
  62. return value
  63. def __dir__(self):
  64. return sorted(dir(self._real_module) + list(self._origin))
  65. del ModuleType
  66. _DeprecatedImportModule(
  67. __name__,
  68. {
  69. ".": ["exceptions", "routing"],
  70. "._internal": ["_easteregg"],
  71. ".datastructures": [
  72. "Accept",
  73. "Authorization",
  74. "CallbackDict",
  75. "CharsetAccept",
  76. "CombinedMultiDict",
  77. "EnvironHeaders",
  78. "ETags",
  79. "FileMultiDict",
  80. "FileStorage",
  81. "Headers",
  82. "HeaderSet",
  83. "ImmutableDict",
  84. "ImmutableList",
  85. "ImmutableMultiDict",
  86. "ImmutableOrderedMultiDict",
  87. "ImmutableTypeConversionDict",
  88. "LanguageAccept",
  89. "MIMEAccept",
  90. "MultiDict",
  91. "OrderedMultiDict",
  92. "RequestCacheControl",
  93. "ResponseCacheControl",
  94. "TypeConversionDict",
  95. "WWWAuthenticate",
  96. ],
  97. ".debug": ["DebuggedApplication"],
  98. ".exceptions": ["abort", "Aborter"],
  99. ".formparser": ["parse_form_data"],
  100. ".http": [
  101. "cookie_date",
  102. "dump_cookie",
  103. "dump_header",
  104. "dump_options_header",
  105. "generate_etag",
  106. "http_date",
  107. "HTTP_STATUS_CODES",
  108. "is_entity_header",
  109. "is_hop_by_hop_header",
  110. "is_resource_modified",
  111. "parse_accept_header",
  112. "parse_authorization_header",
  113. "parse_cache_control_header",
  114. "parse_cookie",
  115. "parse_date",
  116. "parse_dict_header",
  117. "parse_etags",
  118. "parse_list_header",
  119. "parse_options_header",
  120. "parse_set_header",
  121. "parse_www_authenticate_header",
  122. "quote_etag",
  123. "quote_header_value",
  124. "remove_entity_headers",
  125. "remove_hop_by_hop_headers",
  126. "unquote_etag",
  127. "unquote_header_value",
  128. ],
  129. ".local": [
  130. "Local",
  131. "LocalManager",
  132. "LocalProxy",
  133. "LocalStack",
  134. "release_local",
  135. ],
  136. ".middleware.dispatcher": ["DispatcherMiddleware"],
  137. ".middleware.shared_data": ["SharedDataMiddleware"],
  138. ".security": ["check_password_hash", "generate_password_hash"],
  139. ".test": ["create_environ", "EnvironBuilder", "run_wsgi_app"],
  140. ".testapp": ["test_app"],
  141. ".urls": [
  142. "Href",
  143. "iri_to_uri",
  144. "uri_to_iri",
  145. "url_decode",
  146. "url_encode",
  147. "url_fix",
  148. "url_quote",
  149. "url_quote_plus",
  150. "url_unquote",
  151. "url_unquote_plus",
  152. ],
  153. ".useragents": ["UserAgent"],
  154. ".utils": [
  155. "append_slash_redirect",
  156. "ArgumentValidationError",
  157. "bind_arguments",
  158. "cached_property",
  159. "environ_property",
  160. "escape",
  161. "find_modules",
  162. "format_string",
  163. "header_property",
  164. "html",
  165. "HTMLBuilder",
  166. "import_string",
  167. "redirect",
  168. "secure_filename",
  169. "unescape",
  170. "validate_arguments",
  171. "xhtml",
  172. ],
  173. ".wrappers.accept": ["AcceptMixin"],
  174. ".wrappers.auth": ["AuthorizationMixin", "WWWAuthenticateMixin"],
  175. ".wrappers.base_request": ["BaseRequest"],
  176. ".wrappers.base_response": ["BaseResponse"],
  177. ".wrappers.common_descriptors": [
  178. "CommonRequestDescriptorsMixin",
  179. "CommonResponseDescriptorsMixin",
  180. ],
  181. ".wrappers.etag": ["ETagRequestMixin", "ETagResponseMixin"],
  182. ".wrappers.response": ["ResponseStreamMixin"],
  183. ".wrappers.user_agent": ["UserAgentMixin"],
  184. ".wsgi": [
  185. "ClosingIterator",
  186. "extract_path_info",
  187. "FileWrapper",
  188. "get_current_url",
  189. "get_host",
  190. "LimitedStream",
  191. "make_line_iter",
  192. "peek_path_info",
  193. "pop_path_info",
  194. "responder",
  195. "wrap_file",
  196. ],
  197. },
  198. "Werkzeug 1.0",
  199. )
  200. from .serving import run_simple
  201. from .test import Client
  202. from .wrappers import Request
  203. from .wrappers import Response