Development of an internal social media platform with personalised dashboards for students
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.

PKG-INFO 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. Metadata-Version: 1.1
  2. Name: wrapt
  3. Version: 1.10.11
  4. Summary: Module for decorators, wrappers and monkey patching.
  5. Home-page: https://github.com/GrahamDumpleton/wrapt
  6. Author: Graham Dumpleton
  7. Author-email: Graham.Dumpleton@gmail.com
  8. License: BSD
  9. Description: wrapt
  10. =====
  11. |Travis| |Coveralls| |PyPI|
  12. The aim of the **wrapt** module is to provide a transparent object proxy
  13. for Python, which can be used as the basis for the construction of function
  14. wrappers and decorator functions.
  15. The **wrapt** module focuses very much on correctness. It therefore goes
  16. way beyond existing mechanisms such as ``functools.wraps()`` to ensure that
  17. decorators preserve introspectability, signatures, type checking abilities
  18. etc. The decorators that can be constructed using this module will work in
  19. far more scenarios than typical decorators and provide more predictable and
  20. consistent behaviour.
  21. To ensure that the overhead is as minimal as possible, a C extension module
  22. is used for performance critical components. An automatic fallback to a
  23. pure Python implementation is also provided where a target system does not
  24. have a compiler to allow the C extension to be compiled.
  25. Documentation
  26. -------------
  27. For further information on the **wrapt** module see:
  28. * http://wrapt.readthedocs.org/
  29. Quick Start
  30. -----------
  31. To implement your decorator you need to first define a wrapper function.
  32. This will be called each time a decorated function is called. The wrapper
  33. function needs to take four positional arguments:
  34. * ``wrapped`` - The wrapped function which in turns needs to be called by your wrapper function.
  35. * ``instance`` - The object to which the wrapped function was bound when it was called.
  36. * ``args`` - The list of positional arguments supplied when the decorated function was called.
  37. * ``kwargs`` - The dictionary of keyword arguments supplied when the decorated function was called.
  38. The wrapper function would do whatever it needs to, but would usually in
  39. turn call the wrapped function that is passed in via the ``wrapped``
  40. argument.
  41. The decorator ``@wrapt.decorator`` then needs to be applied to the wrapper
  42. function to convert it into a decorator which can in turn be applied to
  43. other functions.
  44. ::
  45. import wrapt
  46. @wrapt.decorator
  47. def pass_through(wrapped, instance, args, kwargs):
  48. return wrapped(*args, **kwargs)
  49. @pass_through
  50. def function():
  51. pass
  52. If you wish to implement a decorator which accepts arguments, then wrap the
  53. definition of the decorator in a function closure. Any arguments supplied
  54. to the outer function when the decorator is applied, will be available to
  55. the inner wrapper when the wrapped function is called.
  56. ::
  57. import wrapt
  58. def with_arguments(myarg1, myarg2):
  59. @wrapt.decorator
  60. def wrapper(wrapped, instance, args, kwargs):
  61. return wrapped(*args, **kwargs)
  62. return wrapper
  63. @with_arguments(1, 2)
  64. def function():
  65. pass
  66. When applied to a normal function or static method, the wrapper function
  67. when called will be passed ``None`` as the ``instance`` argument.
  68. When applied to an instance method, the wrapper function when called will
  69. be passed the instance of the class the method is being called on as the
  70. ``instance`` argument. This will be the case even when the instance method
  71. was called explicitly via the class and the instance passed as the first
  72. argument. That is, the instance will never be passed as part of ``args``.
  73. When applied to a class method, the wrapper function when called will be
  74. passed the class type as the ``instance`` argument.
  75. When applied to a class, the wrapper function when called will be passed
  76. ``None`` as the ``instance`` argument. The ``wrapped`` argument in this
  77. case will be the class.
  78. The above rules can be summarised with the following example.
  79. ::
  80. import inspect
  81. @wrapt.decorator
  82. def universal(wrapped, instance, args, kwargs):
  83. if instance is None:
  84. if inspect.isclass(wrapped):
  85. # Decorator was applied to a class.
  86. return wrapped(*args, **kwargs)
  87. else:
  88. # Decorator was applied to a function or staticmethod.
  89. return wrapped(*args, **kwargs)
  90. else:
  91. if inspect.isclass(instance):
  92. # Decorator was applied to a classmethod.
  93. return wrapped(*args, **kwargs)
  94. else:
  95. # Decorator was applied to an instancemethod.
  96. return wrapped(*args, **kwargs)
  97. Using these checks it is therefore possible to create a universal decorator
  98. that can be applied in all situations. It is no longer necessary to create
  99. different variants of decorators for normal functions and instance methods,
  100. or use additional wrappers to convert a function decorator into one that
  101. will work for instance methods.
  102. In all cases, the wrapped function passed to the wrapper function is called
  103. in the same way, with ``args`` and ``kwargs`` being passed. The
  104. ``instance`` argument doesn't need to be used in calling the wrapped
  105. function.
  106. Repository
  107. ----------
  108. Full source code for the **wrapt** module, including documentation files
  109. and unit tests, can be obtained from github.
  110. * https://github.com/GrahamDumpleton/wrapt
  111. .. |Travis| image:: https://img.shields.io/travis/GrahamDumpleton/wrapt/develop.svg?style=plastic
  112. :target: https://travis-ci.org/GrahamDumpleton/wrapt?branch=develop
  113. .. |Coveralls| image:: https://img.shields.io/coveralls/GrahamDumpleton/wrapt/develop.svg?style=plastic
  114. :target: https://coveralls.io/github/GrahamDumpleton/wrapt?branch=develop
  115. .. |PyPI| image:: https://img.shields.io/pypi/v/wrapt.svg?style=plastic
  116. :target: https://pypi.python.org/pypi/wrapt
  117. Platform: UNKNOWN
  118. Classifier: Development Status :: 5 - Production/Stable
  119. Classifier: License :: OSI Approved :: BSD License
  120. Classifier: Programming Language :: Python :: 2.6
  121. Classifier: Programming Language :: Python :: 2.7
  122. Classifier: Programming Language :: Python :: 3.3
  123. Classifier: Programming Language :: Python :: 3.4
  124. Classifier: Programming Language :: Python :: 3.5
  125. Classifier: Programming Language :: Python :: 3.6
  126. Classifier: Programming Language :: Python :: Implementation :: CPython
  127. Classifier: Programming Language :: Python :: Implementation :: PyPy