Gilles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/261340

Change subject: Request storage
......................................................................

Request storage

This makes the original cached only for the current request.
This is needed to make pre-rendering efficient, by having
the request storage shared between the different sub-requests.

Bug: T122573
Change-Id: I87dea2de25e40d940fb00b3f3b80818f856c8915
---
A LICENSE
A requirements.txt
A setup.cfg
A setup.py
A tox.ini
A wikimedia_thumbor_request_storage/__init__.py
6 files changed, 124 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/thumbor/request-storage 
refs/changes/40/261340/1

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..133846d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Gilles Dubuc, Wikimedia Foundation
+
+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/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..ef29d7d
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+thumbor
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..b88034e
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,2 @@
+[metadata]
+description-file = README.md
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..8bb65d6
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+
+from setuptools import setup, find_packages
+
+
+setup(
+    name='wikimedia_thumbor_request_storage',
+    version='0.1.1',
+    url='https://github.com/wikimedia/thumbor-request-storage',
+    license='MIT',
+    author='Gilles Dubuc, Wikimedia Foundation',
+    description='Thumbor request storage',
+    packages=find_packages(),
+    include_package_data=True,
+    zip_safe=False,
+    platforms='any',
+    install_requires=[
+        'thumbor',
+    ],
+    extras_require={
+        'tests': [
+            'pyvows',
+            'coverage',
+        ],
+    },
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: MIT License',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Topic :: Software Development :: Libraries :: Python Modules'
+    ]
+)
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..157253d
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,12 @@
+[tox]
+minversion = 1.6
+skipsdist = True
+envlist = flake8, py27
+
+[testenv]
+setenv = VIRTUAL_ENV={envdir}
+deps = -r{toxinidir}/requirements.txt
+
+[testenv:flake8]
+commands = flake8 {posargs}
+deps = flake8
diff --git a/wikimedia_thumbor_request_storage/__init__.py 
b/wikimedia_thumbor_request_storage/__init__.py
new file mode 100644
index 0000000..699e773
--- /dev/null
+++ b/wikimedia_thumbor_request_storage/__init__.py
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Licensed under the MIT license:
+# http://www.opensource.org/licenses/mit-license
+# Copyright (c) 2015 Wikimedia Foundation
+#
+# Simply stores originals in a local dictionary
+# In practice this deliberately shouldn't work
+# across requests, unless the same instance of this class
+# is passed between requests (which is the case for /multi)
+
+from tornado.concurrent import return_future
+
+from thumbor.storages import BaseStorage
+from thumbor.utils import logger
+
+
+class Storage(BaseStorage):
+    def __init__(self, context):
+        BaseStorage.__init__(self, context)
+        self.dict = {}
+
+    def put(self, path, contents):
+        logger.debug("[REQUEST_STORAGE] put: %s" % path)
+        self.dict[path] = contents
+        return path
+
+    def put_crypto(self, path):
+        if not self.context.config.STORES_CRYPTO_KEY_FOR_EACH_IMAGE:
+            return
+
+        if not self.context.server.security_key:
+            raise RuntimeError(
+                "STORES_CRYPTO_KEY_FOR_EACH_IMAGE can't be True"
+                + " if no SECURITY_KEY specified"
+            )
+
+        return path
+
+    @return_future
+    def exists(self, path, callback):
+        callback(path in self.dict)
+
+    @return_future
+    def get(self, path, callback):
+        logger.debug("[REQUEST_STORAGE] get: %s" % path)
+        try:
+            logger.debug("[REQUEST_STORAGE] found")
+            callback(self.dict[path])
+        except KeyError:
+            logger.debug("[REQUEST_STORAGE] missing")
+            callback(None)

-- 
To view, visit https://gerrit.wikimedia.org/r/261340
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I87dea2de25e40d940fb00b3f3b80818f856c8915
Gerrit-PatchSet: 1
Gerrit-Project: thumbor/request-storage
Gerrit-Branch: master
Gerrit-Owner: Gilles <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to