Anonymous avatar Anonymous committed 66933c5

Removing use of str.partition for Python 2.x in wsgiserver (removing top-level dependency on cherrypy).

Comments (0)

Files changed (2)

py2/cherrypy/py24compat.py

-"""
-Module that provides backward-compatible implementations of Python 2.5
-built-in capability. Named py24compat because when you no longer need Python
-2.4 compatibility, you can remove py24compat.
-"""
-import sys
-
-def _partition_py24(s, sep):
-    """ Returns a three element tuple, (head, sep, tail) where:
-
-        head + sep + tail == s
-        sep == '' or sep is t
-        bool(sep) == (t in s)       # sep indicates if the string was found
-
-    >>> s = 'http://www.python.org'
-    >>> partition(s, '://')
-    ('http', '://', 'www.python.org')
-    >>> partition(s, '?')
-    ('http://www.python.org', '', '')
-    >>> partition(s, 'http://')
-    ('', 'http://', 'www.python.org')
-    >>> partition(s, 'org')
-    ('http://www.python.', 'org', '')
-    """
-    if not isinstance(t, basestring) or not t:
-        raise ValueError('partititon argument must be a non-empty string')
-    parts = s.split(sep, 1)
-    if len(parts) == 1:
-        result = (s, '', '')
-    else:
-        result = (parts[0], sep, parts[1])
-    assert len(result) == 3
-    assert ''.join(result) == s
-    assert result[1] == '' or result[1] is sep
-    return result
-
-if sys.version_info >= (2,5):
-    partition = lambda s, sep: s.partition(sep)
-else:
-    partition = _partition_py24

py2/cherrypy/wsgiserver/__init__.py

 
 import errno
 
-from cherrypy.py24compat import partition
-
 def plat_specific_errors(*errnames):
     """Return error numbers for all errors in errnames on this platform.
     
         if uri == "*":
             return None, None, uri
         
-        scheme, sep, remainder = partition(uri, '://')
-        if sep and '?' not in scheme:
+        i = uri.find('://')
+        if i > 0 and '?' not in uri[:i]:
             # An absoluteURI.
             # If there's a scheme (and it must be http or https), then:
             # http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]
-            authority, path_a, path_b = partition(remainder, '/')
-            return scheme.lower(), authority, path_a+path_b
+            scheme, remainder = uri[:i].lower(), uri[i + 3:]
+            authority, path = remainder.split("/", 1)
+            path = '/' + path
+            return scheme, authority, path
         
         if uri.startswith('/'):
             # An abs_path.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.