You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by di...@apache.org on 2021/01/11 21:56:48 UTC

[allura] branch master updated (3bedd33 -> 81d9f05)

This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git.


    from 3bedd33  Youtube oembed test: be ok with different but similar outcomes
     new d16d935  [#8382] avoid a py3 ming error (on py2 I think flush silently misses the task until the next request flushes)
     new 14a622a  [#8382] simpler version of smart_str, handles already encoded/binary better too
     new f1322d8  [#8382] encoding fixes in import_api used by trac wiki importer
     new 81d9f05  [#8382] py3: avoid error if global 'c' isn't set yet

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Allura/allura/config/middleware.py     |  2 ++
 Allura/allura/lib/custom_middleware.py | 34 ++++++++++++++++++++++++++++--
 Allura/allura/lib/import_api.py        |  9 ++++----
 Allura/allura/lib/utils.py             | 38 ++++++++++------------------------
 Allura/allura/tests/test_utils.py      |  8 +++++++
 5 files changed, 57 insertions(+), 34 deletions(-)


[allura] 02/04: [#8382] simpler version of smart_str, handles already encoded/binary better too

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 14a622a6c050ddf5913794fc5cb7343001f8a1cc
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Thu Dec 31 16:47:52 2020 -0500

    [#8382] simpler version of smart_str, handles already encoded/binary better too
---
 Allura/allura/lib/utils.py        | 38 +++++++++++---------------------------
 Allura/allura/tests/test_utils.py |  8 ++++++++
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 9dd2a75..dca2d3b 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -783,38 +783,22 @@ def is_nofollow_url(url):
     return url_domain and url_domain not in ok_domains
 
 
-def smart_str(s, encoding='utf-8', strings_only=False, errors='strict'):
-    """
-    Returns a bytestring version of 's', encoded as specified in 'encoding'.
-
-    If strings_only is True, don't convert (some) non-string-like objects.
-
-    This function was borrowed from Django
-    """
-    if strings_only and isinstance(s, (type(None), int)):
+def smart_str(s):
+    '''
+    Returns a bytestring version of 's' from any type
+    '''
+    if isinstance(s, six.binary_type):
         return s
-    elif not isinstance(s, six.string_types):
-        try:
-            return str(s)
-        except UnicodeEncodeError:
-            if isinstance(s, Exception):
-                # An Exception subclass containing non-ASCII data that doesn't
-                # know how to print itself properly. We shouldn't raise a
-                # further exception.
-                return ' '.join([smart_str(arg, encoding, strings_only,
-                                           errors) for arg in s])
-            return six.text_type(s).encode(encoding, errors)
-    elif isinstance(s, six.text_type):
-        r = s.encode(encoding, errors)
-        return r
-    elif s and encoding != 'utf-8':
-        return s.decode('utf-8', errors).encode(encoding, errors)
     else:
-        return s
+        return six.text_type(s).encode('utf-8')
 
 
 def generate_smart_str(params):
-    for (key, value) in six.iteritems(params):
+    if isinstance(params, collections.Mapping):
+        params_list = six.iteritems(params)
+    else:
+        params_list = params
+    for key, value in params_list:
         yield smart_str(key), smart_str(value)
 
 
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index cff7a5d..98f5b12 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -421,3 +421,11 @@ def test_close_ipv4_addrs():
     assert utils.close_ipv4_addrs('1.2.3.4', '1.2.3.255')
     assert not utils.close_ipv4_addrs('1.2.3.4', '1.2.4.4')
 
+
+def test_urlencode():
+    # dict - a simple one so arbitrary ordering doesn't cause problems on py2
+    assert_equal(utils.urlencode({'a': 'hello'}),
+                 'a=hello')
+    # list of pairs - including unicode and bytes
+    assert_equal(utils.urlencode([('a', 1), ('b', 'ƒ'), ('c', 'ƒ'.encode('utf8'))]),
+                 'a=1&b=%C6%92&c=%C6%92')


[allura] 01/04: [#8382] avoid a py3 ming error (on py2 I think flush silently misses the task until the next request flushes)

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit d16d935db0149c89d813d3d6c1cd5e7a981a0bbc
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Thu Dec 31 14:19:02 2020 -0500

    [#8382] avoid a py3 ming error (on py2 I think flush silently misses the task until the next request flushes)
---
 Allura/allura/config/middleware.py     |  2 ++
 Allura/allura/lib/custom_middleware.py | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/Allura/allura/config/middleware.py b/Allura/allura/config/middleware.py
index 2e06bb7..a4f8132 100644
--- a/Allura/allura/config/middleware.py
+++ b/Allura/allura/config/middleware.py
@@ -65,6 +65,7 @@ from allura.lib.custom_middleware import CORSMiddleware
 from allura.lib.custom_middleware import LoginRedirectMiddleware
 from allura.lib.custom_middleware import RememberLoginMiddleware
 from allura.lib.custom_middleware import SetRequestHostFromConfig
+from allura.lib.custom_middleware import MingTaskSessionSetupMiddleware
 from allura.lib import helpers as h
 
 __all__ = ['make_app']
@@ -191,6 +192,7 @@ def _make_core_app(root, global_conf, full_stack=True, **app_conf):
     # Handle static files (by tool)
     app = StaticFilesMiddleware(app, app_conf.get('static.script_name'))
     # Handle setup and flushing of Ming ORM sessions
+    app = MingTaskSessionSetupMiddleware(app)
     app = MingMiddleware(app)
     # Set up the registry for stacked object proxies (SOPs).
     #    streaming=true ensures they won't be cleaned up till
diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index 2422981..b38b0b9 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -31,6 +31,7 @@ from timermiddleware import Timer, TimerMiddleware
 from webob import exc, Request
 import pysolr
 import six
+from ming.odm import session
 
 from allura.lib import helpers as h
 from allura import model as M
@@ -434,3 +435,28 @@ class RememberLoginMiddleware(object):
             return start_response(status, headers, exc_info)
 
         return self.app(environ, remember_login_start_response)
+
+
+class MingTaskSessionSetupMiddleware(object):
+    '''
+    This middleware ensures there is a "task" session always established.  This avoids:
+
+          File ".../ming/odm/middleware.py", line 31, in __call__
+            self._cleanup_request()
+          File ".../ming/odm/middleware.py", line 45, in _cleanup_request
+            ThreadLocalODMSession.flush_all()
+          File ".../ming/odm/odmsession.py", line 414, in flush_all
+            for sess in cls._session_registry.values():
+        RuntimeError: dictionary changed size during iteration
+
+    Which would happen when IndexerSessionExtension establishes the first "task" session during a flush of a
+    different session
+    '''
+
+    def __init__(self, app):
+        self.app = app
+
+    def __call__(self, environ, start_response):
+        # this is sufficient to ensure an ODM session is always established
+        session(M.MonQTask).impl
+        return self.app(environ, start_response)


[allura] 04/04: [#8382] py3: avoid error if global 'c' isn't set yet

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 81d9f05aa5010fb57503caa9d750c9a6dec46781
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Thu Dec 31 16:55:21 2020 -0500

    [#8382] py3: avoid error if global 'c' isn't set yet
---
 Allura/allura/lib/custom_middleware.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index b38b0b9..bf6ce72 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -387,8 +387,12 @@ class AlluraTimerMiddleware(TimerMiddleware):
         return timers
 
     def before_logging(self, stat_record):
-        if hasattr(c, "app") and hasattr(c.app, "config"):
-            stat_record.add('request_category', c.app.config.tool_name.lower())
+        try:
+            app_config = c.app.config
+        except (TypeError, AttributeError):
+            pass
+        else:
+            stat_record.add('request_category', app_config.tool_name.lower())
         return stat_record
 
     @classmethod


[allura] 03/04: [#8382] encoding fixes in import_api used by trac wiki importer

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit f1322d804de4269527263bac912dd8a41ff6425f
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Thu Dec 31 16:48:15 2020 -0500

    [#8382] encoding fixes in import_api used by trac wiki importer
---
 Allura/allura/lib/import_api.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/Allura/allura/lib/import_api.py b/Allura/allura/lib/import_api.py
index 481264e..3560f38 100644
--- a/Allura/allura/lib/import_api.py
+++ b/Allura/allura/lib/import_api.py
@@ -20,11 +20,10 @@ from __future__ import absolute_import
 import six.moves.urllib.request
 import six.moves.urllib.parse
 import six.moves.urllib.error
-import hmac
-import hashlib
 import json
 import logging
-from datetime import datetime
+
+from allura.lib.utils import urlencode
 
 log = logging.getLogger(__name__)
 
@@ -50,14 +49,14 @@ class AlluraImportApiClient(object):
 
         while True:
             try:
-                result = six.moves.urllib.request.urlopen(url, six.moves.urllib.parse.urlencode(params))
+                result = six.moves.urllib.request.urlopen(url, six.ensure_binary(urlencode(params)))
                 resp = result.read()
                 return json.loads(resp)
             except six.moves.urllib.error.HTTPError as e:
                 e.msg += ' ({0})'.format(url)
                 if self.verbose:
                     error_content = e.read()
-                    e.msg += '. Error response:\n' + error_content
+                    e.msg += '. Error response:\n' + six.ensure_text(error_content)
                 raise e
             except (six.moves.urllib.error.URLError, IOError):
                 if self.retry: