Hugo Lopes Tavares avatar Hugo Lopes Tavares committed 70c5159

changed names from `similar_pages` to `similar_urls`, changed doctest to simple test called in __main__ section and improved the algorithm to find similar urls

Comments (0)

Files changed (1)


 import os
+import sys
 import re
 import wsgi_intercept
 from wsgi_intercept.urllib2_intercept import install_opener
 PYPI_DEFAULT_STATIC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "pypiserver")
-def get_similar_pages(url):
-    """
-    >>> get_similar_pages('')
-    ''
-    >>> get_similar_pages('')
-    ''
-    >>> get_similar_pages('')
-    ''
-    >>> get_similar_pages('')
-    ''
-    """
+def _test_get_similar_urls():
+    assert get_similar_urls('/simple/initools') == '/simple/INITools'
+    assert get_similar_urls('/simple/initools/0.2') == '/simple/INITools/0.2'
+    assert get_similar_urls('/simple/setuptools_git') == '/simple/setuptools-git'
+    assert get_similar_urls('/simple/setuptools_git/') == '/simple/setuptools-git/'
+    assert get_similar_urls('/simple/setuptools_git/setuptools_git-0.3.4.tar.gz') == '/simple/setuptools-git/setuptools_git-0.3.4.tar.gz'
+def get_similar_urls(url):
     r ='/simple/([^/]+)', url)
     here = os.path.dirname(os.path.abspath(__file__))
     all_packages = os.listdir(os.path.join(here, 'pypiserver', 'simple'))
 def pypi_app():
     def wsgi_app(environ, start_response):
         headers = [('Content-type', 'text/html')]
-        path_tree = environ['PATH_INFO'].split('/')
+        path_tree = get_similar_urls(environ['PATH_INFO']).split('/')
         url = os.path.join(PYPI_DEFAULT_STATIC_PATH, *path_tree)
         filepath = url
         if environ['PATH_INFO'].endswith('.gz'):
             headers = [('Content-type', 'application/x-gtar')]
             filepath = os.path.join(url, 'index.html')
-        filepath = get_similar_pages(filepath)
         start_response('200 OK', headers)
         if not os.path.exists(filepath):
                 return ''
     # allow wsgi_intercept to work with urllib2 fakes
     wsgi_intercept.add_wsgi_intercept('', 80, pypi_app)
+if __name__ == '__main__':
+    _test_get_similar_urls()
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
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.