[Python-modules-commits] [django-uwsgi] 01/02: Imported Upstream version 0.1.3

Michael Fladischer fladi at moszumanska.debian.org
Mon Sep 14 18:52:53 UTC 2015


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch master
in repository django-uwsgi.

commit 3c43c0552f6269504ef1307f133cf65187e59bd4
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Mon Sep 14 17:06:42 2015 +0200

    Imported Upstream version 0.1.3
---
 .editorconfig                                      |  12 +
 .gitignore                                         |  93 +++++
 CONTRIBUTORS                                       |   4 +
 LICENSE                                            |  21 +
 MANIFEST.in                                        |   4 +
 PKG-INFO                                           |  63 +++
 README.rst                                         |  34 ++
 django_uwsgi.egg-info/PKG-INFO                     |  63 +++
 django_uwsgi.egg-info/SOURCES.txt                  |  56 +++
 django_uwsgi.egg-info/dependency_links.txt         |   1 +
 django_uwsgi.egg-info/not-zip-safe                 |   1 +
 django_uwsgi.egg-info/pbr.json                     |   1 +
 django_uwsgi.egg-info/requires.txt                 |   3 +
 django_uwsgi.egg-info/top_level.txt                |   1 +
 django_uwsgi/__init__.py                           |  14 +
 django_uwsgi/apps.py                               |   7 +
 django_uwsgi/cache.py                              |  75 ++++
 django_uwsgi/decorators.py                         | 432 +++++++++++++++++++++
 django_uwsgi/emperor/__init__.py                   |   2 +
 django_uwsgi/emperor/admin.py                      |  10 +
 django_uwsgi/emperor/apps.py                       |   7 +
 django_uwsgi/emperor/models.py                     |  92 +++++
 django_uwsgi/mail.py                               |  18 +
 django_uwsgi/management/__init__.py                |   0
 django_uwsgi/management/commands/__init__.py       |   0
 django_uwsgi/management/commands/runuwsgi.py       | 105 +++++
 django_uwsgi/panels.py                             |  27 ++
 django_uwsgi/stats.py                              |  47 +++
 django_uwsgi/task.py                               |  15 +
 django_uwsgi/template.py                           |  23 ++
 django_uwsgi/templates/uwsgi/panel.html            | 152 ++++++++
 django_uwsgi/templates/uwsgi/uwsgi.html            |  28 ++
 .../templates/uwsgi/wagtail_dashboard_item.html    |  10 +
 django_uwsgi/templates/uwsgi/wagtail_uwsgi.html    | 196 ++++++++++
 django_uwsgi/urls.py                               |   8 +
 django_uwsgi/views.py                              |  63 +++
 django_uwsgi/wagtail_hooks.py                      |  41 ++
 docs/Makefile                                      | 177 +++++++++
 docs/cache.rst                                     |  30 ++
 docs/changelog.rst                                 |   9 +
 docs/command.rst                                   |  32 ++
 docs/conf.py                                       |  63 +++
 docs/configuration.rst                             |  18 +
 docs/contributing.rst                              |  25 ++
 docs/decorators.rst                                | 330 ++++++++++++++++
 docs/email.rst                                     |  58 +++
 docs/features.rst                                  |  19 +
 docs/index.rst                                     |  30 ++
 docs/installation.rst                              |  32 ++
 docs/integrations.rst                              |  37 ++
 docs/requirements-docs.txt                         |   3 +
 docs/screenshots.rst                               |  15 +
 docs/screenshots/screenshot1.png                   | Bin 0 -> 130092 bytes
 docs/screenshots/screenshot2.png                   | Bin 0 -> 77379 bytes
 docs/screenshots/screenshot3.png                   | Bin 0 -> 51354 bytes
 docs/todo.rst                                      |  13 +
 setup.cfg                                          |   5 +
 setup.py                                           |  51 +++
 58 files changed, 2676 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100755
index 0000000..2792d4b
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+# editorconfig.org
+root = true
+
+[*]
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.{py,rst,ini}]
+indent_style = space
+indent_size = 4
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100755
index 0000000..b92b877
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,93 @@
+public/uploads/
+public/assets/
+
+*~
+.DS_Store
+.AppleDouble
+.LSOverride
+.idea
+atlassian-ide-plugin.xml
+# Icon must ends with two \r.
+#Icon
+
+
+# Thumbnails
+._*
+
+# Files that might appear on external disk
+.Spotlight-V100
+.Trashes
+
+*.sublime-workspace
+*.sublime-project
+
+# Virtualenv
+# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
+.Python
+[Bb]in
+[Ii]nclude
+[Ll]ib
+[Ss]cripts
+
+
+
+local_settings.py
+.idea
+
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+#bin/
+build/
+develop-eggs/
+dist/
+eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+.tox/
+.coverage
+.cache
+nosetests.xml
+coverage.xml
+
+# Translations
+*.mo
+
+# Mr Developer
+.mr.developer.cfg
+.project
+.pydevproject
+
+# Rope
+.ropeproject
+
+# Django stuff:
+*.log
+*.pot
+
+# Sphinx documentation
+docs/_build/
+
+.env
+*.db
+*.sqlite
+*.sqlite3
\ No newline at end of file
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
new file mode 100755
index 0000000..5cc5e32
--- /dev/null
+++ b/CONTRIBUTORS
@@ -0,0 +1,4 @@
+Roberto De Ioris, Unbit, <roberto at unbit.it>
+Eugene MechanisM, MechanisM, <eugene at mechanism.name>
+Ionel Cristian Mărieș, <contact at ionelmc.ro>
+Jayson Reis, jaysonsantos, <santosdosreis at gmail.com>
diff --git a/LICENSE b/LICENSE
new file mode 100755
index 0000000..b1a448c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 unbit
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100755
index 0000000..f53c0a7
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,4 @@
+include CONTRIBUTORS LICENSE *.rst
+recursive-include django_uwsgi *
+recursive-exclude * __pycache__
+recursive-exclude * *.py[cod]
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..984d8e4
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,63 @@
+Metadata-Version: 1.1
+Name: django-uwsgi
+Version: 0.1.3
+Summary: uWSGI stuff for Django projects
+Home-page: http://github.com/unbit/django-uwsgi
+Author: Eugene MechanisM
+Author-email: eugene at mechanism.name
+License: MIT
+Description: django-uwsgi
+        ~~~~~~~~~~~~
+        
+        Django related examples/tricks/modules for uWSGI
+        
+        
+        Screenshots
+        ~~~~~~~~~~~
+        
+        `django-debug-toolbar <http://django-debug-toolbar.readthedocs.org/en/latest/>`_ panel
+        
+        .. image:: https://github.com/unbit/django-uwsgi/raw/master/docs/screenshots/screenshot1.png
+        
+        
+        `Wagtail <https://github.com/torchbox/wagtail>`_ admin interface:
+        
+        .. image:: https://github.com/unbit/django-uwsgi/raw/master/docs/screenshots/screenshot2.png
+        
+        .. image:: https://github.com/unbit/django-uwsgi/raw/master/docs/screenshots/screenshot3.png
+        
+        Documentation
+        ~~~~~~~~~~~~~
+        
+        `Read the documentation at rtfd.org <http://django-uwsgi.rtfd.org/>`_
+        
+        Contributors
+        ~~~~~~~~~~~~
+        
+        See `CONTRIBUTORS <https://github.com/unbit/django-uwsgi/CONTRIBUTORS>`_
+        
+        License
+        ~~~~~~~
+        
+        `MIT <https://github.com/unbit/django-uwsgi/LICENSE>`_
+        
+Keywords: uwsgi,django,mail,cache,template
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Framework :: Django
+Classifier: Intended Audience :: Developers
+Classifier: Intended Audience :: System Administrators
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: OS Independent
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
+Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
+Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
+Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
+Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
+Classifier: Topic :: Software Development :: Build Tools
+Classifier: Topic :: Software Development :: Code Generators
+Classifier: Topic :: Communications :: Email
+Classifier: Framework :: Django
diff --git a/README.rst b/README.rst
new file mode 100755
index 0000000..0956710
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,34 @@
+django-uwsgi
+~~~~~~~~~~~~
+
+Django related examples/tricks/modules for uWSGI
+
+
+Screenshots
+~~~~~~~~~~~
+
+`django-debug-toolbar <http://django-debug-toolbar.readthedocs.org/en/latest/>`_ panel
+
+.. image:: https://github.com/unbit/django-uwsgi/raw/master/docs/screenshots/screenshot1.png
+
+
+`Wagtail <https://github.com/torchbox/wagtail>`_ admin interface:
+
+.. image:: https://github.com/unbit/django-uwsgi/raw/master/docs/screenshots/screenshot2.png
+
+.. image:: https://github.com/unbit/django-uwsgi/raw/master/docs/screenshots/screenshot3.png
+
+Documentation
+~~~~~~~~~~~~~
+
+`Read the documentation at rtfd.org <http://django-uwsgi.rtfd.org/>`_
+
+Contributors
+~~~~~~~~~~~~
+
+See `CONTRIBUTORS <https://github.com/unbit/django-uwsgi/CONTRIBUTORS>`_
+
+License
+~~~~~~~
+
+`MIT <https://github.com/unbit/django-uwsgi/LICENSE>`_
diff --git a/django_uwsgi.egg-info/PKG-INFO b/django_uwsgi.egg-info/PKG-INFO
new file mode 100644
index 0000000..984d8e4
--- /dev/null
+++ b/django_uwsgi.egg-info/PKG-INFO
@@ -0,0 +1,63 @@
+Metadata-Version: 1.1
+Name: django-uwsgi
+Version: 0.1.3
+Summary: uWSGI stuff for Django projects
+Home-page: http://github.com/unbit/django-uwsgi
+Author: Eugene MechanisM
+Author-email: eugene at mechanism.name
+License: MIT
+Description: django-uwsgi
+        ~~~~~~~~~~~~
+        
+        Django related examples/tricks/modules for uWSGI
+        
+        
+        Screenshots
+        ~~~~~~~~~~~
+        
+        `django-debug-toolbar <http://django-debug-toolbar.readthedocs.org/en/latest/>`_ panel
+        
+        .. image:: https://github.com/unbit/django-uwsgi/raw/master/docs/screenshots/screenshot1.png
+        
+        
+        `Wagtail <https://github.com/torchbox/wagtail>`_ admin interface:
+        
+        .. image:: https://github.com/unbit/django-uwsgi/raw/master/docs/screenshots/screenshot2.png
+        
+        .. image:: https://github.com/unbit/django-uwsgi/raw/master/docs/screenshots/screenshot3.png
+        
+        Documentation
+        ~~~~~~~~~~~~~
+        
+        `Read the documentation at rtfd.org <http://django-uwsgi.rtfd.org/>`_
+        
+        Contributors
+        ~~~~~~~~~~~~
+        
+        See `CONTRIBUTORS <https://github.com/unbit/django-uwsgi/CONTRIBUTORS>`_
+        
+        License
+        ~~~~~~~
+        
+        `MIT <https://github.com/unbit/django-uwsgi/LICENSE>`_
+        
+Keywords: uwsgi,django,mail,cache,template
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Framework :: Django
+Classifier: Intended Audience :: Developers
+Classifier: Intended Audience :: System Administrators
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: OS Independent
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
+Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
+Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
+Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
+Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
+Classifier: Topic :: Software Development :: Build Tools
+Classifier: Topic :: Software Development :: Code Generators
+Classifier: Topic :: Communications :: Email
+Classifier: Framework :: Django
diff --git a/django_uwsgi.egg-info/SOURCES.txt b/django_uwsgi.egg-info/SOURCES.txt
new file mode 100644
index 0000000..3cbd085
--- /dev/null
+++ b/django_uwsgi.egg-info/SOURCES.txt
@@ -0,0 +1,56 @@
+.editorconfig
+.gitignore
+CONTRIBUTORS
+LICENSE
+MANIFEST.in
+README.rst
+setup.py
+django_uwsgi/__init__.py
+django_uwsgi/apps.py
+django_uwsgi/cache.py
+django_uwsgi/decorators.py
+django_uwsgi/mail.py
+django_uwsgi/panels.py
+django_uwsgi/stats.py
+django_uwsgi/task.py
+django_uwsgi/template.py
+django_uwsgi/urls.py
+django_uwsgi/views.py
+django_uwsgi/wagtail_hooks.py
+django_uwsgi.egg-info/PKG-INFO
+django_uwsgi.egg-info/SOURCES.txt
+django_uwsgi.egg-info/dependency_links.txt
+django_uwsgi.egg-info/not-zip-safe
+django_uwsgi.egg-info/pbr.json
+django_uwsgi.egg-info/requires.txt
+django_uwsgi.egg-info/top_level.txt
+django_uwsgi/emperor/__init__.py
+django_uwsgi/emperor/admin.py
+django_uwsgi/emperor/apps.py
+django_uwsgi/emperor/models.py
+django_uwsgi/management/__init__.py
+django_uwsgi/management/commands/__init__.py
+django_uwsgi/management/commands/runuwsgi.py
+django_uwsgi/templates/uwsgi/panel.html
+django_uwsgi/templates/uwsgi/uwsgi.html
+django_uwsgi/templates/uwsgi/wagtail_dashboard_item.html
+django_uwsgi/templates/uwsgi/wagtail_uwsgi.html
+docs/Makefile
+docs/cache.rst
+docs/changelog.rst
+docs/command.rst
+docs/conf.py
+docs/configuration.rst
+docs/contributing.rst
+docs/decorators.rst
+docs/email.rst
+docs/features.rst
+docs/index.rst
+docs/installation.rst
+docs/integrations.rst
+docs/requirements-docs.txt
+docs/screenshots.rst
+docs/todo.rst
+docs/screenshots/screenshot1.png
+docs/screenshots/screenshot2.png
+docs/screenshots/screenshot3.png
\ No newline at end of file
diff --git a/django_uwsgi.egg-info/dependency_links.txt b/django_uwsgi.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/django_uwsgi.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/django_uwsgi.egg-info/not-zip-safe b/django_uwsgi.egg-info/not-zip-safe
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/django_uwsgi.egg-info/not-zip-safe
@@ -0,0 +1 @@
+
diff --git a/django_uwsgi.egg-info/pbr.json b/django_uwsgi.egg-info/pbr.json
new file mode 100644
index 0000000..8835774
--- /dev/null
+++ b/django_uwsgi.egg-info/pbr.json
@@ -0,0 +1 @@
+{"git_version": "46db2ae", "is_release": false}
\ No newline at end of file
diff --git a/django_uwsgi.egg-info/requires.txt b/django_uwsgi.egg-info/requires.txt
new file mode 100644
index 0000000..add7fb1
--- /dev/null
+++ b/django_uwsgi.egg-info/requires.txt
@@ -0,0 +1,3 @@
+
+[uwsgi]
+uwsgi
diff --git a/django_uwsgi.egg-info/top_level.txt b/django_uwsgi.egg-info/top_level.txt
new file mode 100644
index 0000000..c4b2f9d
--- /dev/null
+++ b/django_uwsgi.egg-info/top_level.txt
@@ -0,0 +1 @@
+django_uwsgi
diff --git a/django_uwsgi/__init__.py b/django_uwsgi/__init__.py
new file mode 100755
index 0000000..de8fad8
--- /dev/null
+++ b/django_uwsgi/__init__.py
@@ -0,0 +1,14 @@
+__version__ = '0.1.3'
+
+
+try:
+    import uwsgi
+except ImportError:
+    uwsgi = None
+
+try:
+    import cPickle as pickle
+except ImportError:
+    import pickle
+
+default_app_config = 'django_uwsgi.apps.DjangoUwsgiConfig'
diff --git a/django_uwsgi/apps.py b/django_uwsgi/apps.py
new file mode 100755
index 0000000..cd69361
--- /dev/null
+++ b/django_uwsgi/apps.py
@@ -0,0 +1,7 @@
+from django.apps import AppConfig
+
+
+class DjangoUwsgiConfig(AppConfig):
+    name = 'django_uwsgi'
+    label = 'django_uwsgi'
+    verbose_name = 'uWSGI for Django'
diff --git a/django_uwsgi/cache.py b/django_uwsgi/cache.py
new file mode 100755
index 0000000..bac2a5e
--- /dev/null
+++ b/django_uwsgi/cache.py
@@ -0,0 +1,75 @@
+try:
+    from django.utils.encoding import force_bytes as stringify
+except ImportError:
+    from django.utils.encoding import smart_str as stringify
+from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
+from django.conf import settings
+
+
+try:
+    from . import uwsgi, pickle
+except ImportError:
+    if getattr(settings, "UWSGI_CACHE_FALLBACK", True):
+        uwsgi = None
+    else:
+        raise InvalidCacheBackendError(
+            "You're not running under uWSGI ! "
+            "Set UWSGI_CACHE_FALLBACK=True in settings if you want to fallback "
+            "to LocMemCache."
+        )
+
+
+if uwsgi:
+    class UwsgiCache(BaseCache):
+        """uWSGI cache backend"""
+        def __init__(self, server, params):
+            BaseCache.__init__(self, params)
+            self._cache = uwsgi
+            self._server = server
+
+        def exists(self, key):
+            return self._cache.cache_exists(stringify(key), self._server)
+
+        def add(self, key, value, timeout=True, version=None):
+            full_key = self.make_key(key, version=version)
+            if self.exists(full_key):
+                return False
+            self._set(full_key, value, timeout)
+            return True
+
+        def get(self, key, default=None, version=None):
+            full_key = self.make_key(key, version=version)
+            val = self._cache.cache_get(stringify(full_key), self._server)
+            if val is None:
+                return default
+            val = stringify(val)
+            return pickle.loads(val)
+
+        def _set(self, full_key, value, timeout):
+            if timeout is True:
+                uwsgi_timeout = self.default_timeout
+            elif timeout is None or timeout is False:
+                # Django 1.6+: Explicitly passing in timeout=None will set a non-expiring timeout.
+                uwsgi_timeout = 0
+            elif timeout == 0:
+                # Django 1.6+: Passing in timeout=0 will set-and-expire-immediately the value.
+                uwsgi_timeout = -1
+            else:
+                uwsgi_timeout = timeout
+            self._cache.cache_update(stringify(full_key), pickle.dumps(value), uwsgi_timeout, self._server)
+
+        def set(self, key, value, timeout=True, version=None):
+            full_key = self.make_key(key, version=version)
+            self._set(full_key, value, timeout)
+
+        def delete(self, key, version=None):
+            full_key = self.make_key(key, version=version)
+            self._cache.cache_del(stringify(full_key), self._server)
+
+        def close(self, **kwargs):
+            pass
+
+        def clear(self):
+            self._cache.cache_clear(self._server)
+else:
+    from django.core.cache.backends.locmem import LocMemCache as UwsgiCache
diff --git a/django_uwsgi/decorators.py b/django_uwsgi/decorators.py
new file mode 100755
index 0000000..4f282f5
--- /dev/null
+++ b/django_uwsgi/decorators.py
@@ -0,0 +1,432 @@
+"""
+uWSGI decorators
+shipped with django-uwsgi in case if uWSGI installed system-wide,
+and django project runs in Emperor mode and using virtualenv,
+so uwsgidecorators module not importable.
+
+"""
+
+from functools import partial
+import sys
+from threading import Thread
+
+from . import uwsgi, pickle
+
+
+if uwsgi is None:
+    raise ImportError("uWSGI is not available")
+
+if uwsgi.masterpid() == 0:
+    raise Exception(
+        "you have to enable the uWSGI master process to use this module")
+
+spooler_functions = {}
+mule_functions = {}
+postfork_chain = []
+
+
+# Python3 compatibility
+def _encode1(val):
+    if sys.version_info >= (3, 0) and isinstance(val, str):
+        return val.encode('utf-8')
+    else:
+        return val
+
+
+def _decode1(val):
+    if sys.version_info >= (3, 0) and isinstance(val, bytes):
+        return val.decode('utf-8')
+    else:
+        return val
+
+
+def _encode_to_spooler(vars):
+    return dict((_encode1(K), _encode1(V)) for (K, V) in vars.items())
+
+
+def _decode_from_spooler(vars):
+    return dict((_decode1(K), _decode1(V)) for (K, V) in vars.items())
+
+
+def get_free_signal():
+    for signum in range(0, 256):
+        if not uwsgi.signal_registered(signum):
+            return signum
+
+    raise Exception("No free uwsgi signal available")
+
+
+def manage_spool_request(vars):
+    # To check whether 'args' is in vals or not - decode the keys first,
+    # because in python3 all keys in 'vals' are have 'byte' types
+    vars = dict((_decode1(K), V) for (K, V) in vars.items())
+    if 'args' in vars:
+        for k in ('args', 'kwargs'):
+            vars[k] = pickle.loads(vars.pop(k))
+
+    vars = _decode_from_spooler(vars)
+    f = spooler_functions[vars['ud_spool_func']]
+
+    if 'args' in vars:
+        ret = f(*vars['args'], **vars['kwargs'])
+    else:
+        ret = f(vars)
+
+    return int(vars.get('ud_spool_ret', ret))
+
+
+def postfork_chain_hook():
+    for f in postfork_chain:
+        f()
+
+uwsgi.spooler = manage_spool_request
+uwsgi.post_fork_hook = postfork_chain_hook
+
+
+class postfork(object):
+
+    def __init__(self, f):
+        if callable(f):
+            self.wid = 0
+            self.f = f
+        else:
+            self.f = None
+            self.wid = f
+        postfork_chain.append(self)
+
+    def __call__(self, *args, **kwargs):
+        if self.f:
+            if self.wid > 0 and self.wid != uwsgi.worker_id():
+                return
+            return self.f()
+        self.f = args[0]
+
+
+class _spoolraw(object):
+
+    def __call__(self, *args, **kwargs):
+        arguments = self.base_dict.copy()
+        if not self.pass_arguments:
+            if len(args) > 0:
+                arguments.update(args[0])
+            if kwargs:
+                arguments.update(kwargs)
+        else:
+            spooler_args = {}
+            for key in ('message_dict', 'spooler', 'priority', 'at', 'body'):
+                if key in kwargs:
+                    spooler_args.update({key: kwargs.pop(key)})
+            arguments.update(spooler_args)
+            arguments.update(
+                {'args': pickle.dumps(args), 'kwargs': pickle.dumps(kwargs)})
+        return uwsgi.spool(_encode_to_spooler(arguments))
+
+    # For backward compatibility (uWSGI < 1.9.13)
+    def spool(self, *args, **kwargs):
+        return self.__class__.__call__(self, *args, **kwargs)
+
+    def __init__(self, f, pass_arguments):
+        if not 'spooler' in uwsgi.opt:
+            raise Exception(
+                "you have to enable the uWSGI spooler to use @%s decorator" % self.__class__.__name__)
+        self.f = f
+        spooler_functions[self.f.__name__] = self.f
+        # For backward compatibility (uWSGI < 1.9.13)
+        self.f.spool = self.__call__
+        self.pass_arguments = pass_arguments
+        self.base_dict = {'ud_spool_func': self.f.__name__}
+
+
+class _spool(_spoolraw):
+
+    def __call__(self, *args, **kwargs):
+        self.base_dict['ud_spool_ret'] = str(uwsgi.SPOOL_OK)
+        return _spoolraw.__call__(self, *args, **kwargs)
+
+
+class _spoolforever(_spoolraw):
+
+    def __call__(self, *args, **kwargs):
+        self.base_dict['ud_spool_ret'] = str(uwsgi.SPOOL_RETRY)
+        return _spoolraw.__call__(self, *args, **kwargs)
+
+
+def spool_decorate(f=None, pass_arguments=False, _class=_spoolraw):
+    if not f:
+        return partial(_class, pass_arguments=pass_arguments)
+    return _class(f, pass_arguments)
+
+
+def spoolraw(f=None, pass_arguments=False):
+    return spool_decorate(f, pass_arguments)
+
+
+def spool(f=None, pass_arguments=False):
+    return spool_decorate(f, pass_arguments, _spool)
+
+
+def spoolforever(f=None, pass_arguments=False):
+    return spool_decorate(f, pass_arguments, _spoolforever)
+
+
+class mulefunc(object):
+
+    def __init__(self, f):
+        if callable(f):
+            self.fname = f.__name__
+            self.mule = 0
+            mule_functions[f.__name__] = f
+        else:
+            self.mule = f
+            self.fname = None
+
+    def real_call(self, *args, **kwargs):
+        uwsgi.mule_msg(pickle.dumps(
+            {
+                'service': 'uwsgi_mulefunc',
+                'func': self.fname,
+                'args': args,
+                'kwargs': kwargs
+            }
+        ), self.mule)
+
+    def __call__(self, *args, **kwargs):
+        if not self.fname:
+            self.fname = args[0].__name__
+            mule_functions[self.fname] = args[0]
+            return self.real_call
+
+        return self.real_call(*args, **kwargs)
+
+
+def mule_msg_dispatcher(message):
+    msg = pickle.loads(message)
+    if msg['service'] == 'uwsgi_mulefunc':
+        return mule_functions[msg['func']](*msg['args'], **msg['kwargs'])
+
+uwsgi.mule_msg_hook = mule_msg_dispatcher
+
+
+class rpc(object):
+
+    def __init__(self, name):
+        self.name = name
+
+    def __call__(self, f):
+        uwsgi.register_rpc(self.name, f)
+        return f
+
+
+class farm_loop(object):
+
+    def __init__(self, f, farm):
+        self.f = f
+        self.farm = farm
+
+    def __call__(self):
+        if uwsgi.mule_id() == 0:
+            return
+        if not uwsgi.in_farm(self.farm):
+            return
+        while True:
+            message = uwsgi.farm_get_msg()
+            if message:
+                self.f(message)
+
+
+class farm(object):
+
+    def __init__(self, name=None, **kwargs):
+        self.name = name
+
+    def __call__(self, f):
+        postfork_chain.append(farm_loop(f, self.name))
+
+
+class mule_brain(object):
+
+    def __init__(self, f, num):
+        self.f = f
+        self.num = num
+
+    def __call__(self):
+        if uwsgi.mule_id() == self.num:
+            try:
+                self.f()
+            except:
+                exc = sys.exc_info()
+                sys.excepthook(exc[0], exc[1], exc[2])
+                sys.exit(1)
+
+
+class mule_brainloop(mule_brain):
+
+    def __call__(self):
+        if uwsgi.mule_id() == self.num:
+            while True:
+                try:
+                    self.f()
+                except:
+                    exc = sys.exc_info()
+                    sys.excepthook(exc[0], exc[1], exc[2])
+                    sys.exit(1)
+
+
+class mule(object):
+
+    def __init__(self, num):
+        self.num = num
+
+    def __call__(self, f):
+        postfork_chain.append(mule_brain(f, self.num))
+
+
+class muleloop(mule):
+
+    def __call__(self, f):
+        postfork_chain.append(mule_brainloop(f, self.num))
+
+
+class mulemsg_loop(object):
+
+    def __init__(self, f, num):
+        self.f = f
+        self.num = num
+
+    def __call__(self):
+        if uwsgi.mule_id() == self.num:
+            while True:
+                message = uwsgi.mule_get_msg()
+                if message:
+                    self.f(message)
+
+
+class mulemsg(object):
+
+    def __init__(self, num):
+        self.num = num
+
+    def __call__(self, f):
+        postfork_chain.append(mulemsg_loop(f, self.num))
+
+
+class signal(object):
+
+    def __init__(self, num, **kwargs):
+        self.num = num
+        self.target = kwargs.get('target', '')
+
+    def __call__(self, f):
+        uwsgi.register_signal(self.num, self.target, f)
+        return f
+
+
+class timer(object):
+
+    def __init__(self, secs, **kwargs):
+        self.num = kwargs.get('signum', get_free_signal())
+        self.secs = secs
+        self.target = kwargs.get('target', '')
+
+    def __call__(self, f):
+        uwsgi.register_signal(self.num, self.target, f)
+        uwsgi.add_timer(self.num, self.secs)
+        return f
+
+
+class cron(object):
+
+    def __init__(self, minute, hour, day, month, dayweek, **kwargs):
+        self.num = kwargs.get('signum', get_free_signal())
+        self.minute = minute
+        self.hour = hour
+        self.day = day
+        self.month = month
+        self.dayweek = dayweek
+        self.target = kwargs.get('target', '')
+
+    def __call__(self, f):
+        uwsgi.register_signal(self.num, self.target, f)
+        uwsgi.add_cron(self.num, self.minute, self.hour,
+                       self.day, self.month, self.dayweek)
+        return f
+
+
+class rbtimer(object):
+
+    def __init__(self, secs, **kwargs):
+        self.num = kwargs.get('signum', get_free_signal())
+        self.secs = secs
+        self.target = kwargs.get('target', '')
+
+    def __call__(self, f):
+        uwsgi.register_signal(self.num, self.target, f)
+        uwsgi.add_rb_timer(self.num, self.secs)
+        return f
+
+
+class filemon(object):
+
... 2094 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-uwsgi.git



More information about the Python-modules-commits mailing list