Nicolas Évrard avatar Nicolas Évrard committed c4c6f39

Authenticate the user if fetch fails

Comments (0)

Files changed (2)

+    Tries to authenticate the user if fetch fails
 * Version 0.3 - 2012-09-27
     Allow use of private rietveld instances
     Follow mercurial version while keeping compatibility


         url = '%s/%s' % (server, issue_id)
         msg = 'Looking after issue %s patch' % url
         ui.status(msg, '\n')
-        url_opener = rpc_server._GetOpener()
-        cp = CodereviewParser()
-        cp.feed(
+        url_opener = rpc_server.opener
+        tries = 0
+        while tries < 2:
+            try:
+                cp = CodereviewParser()
+                html =
+                cp.feed(html)
+                break
+            except urllib2.HTTPError as e:
+                if e.code in (401, 302, 301):
+                    rpc_server._Authenticate()
+                else:
+                    ui.status('Unable to fetch the patch: {}'.format(e), '\n')
+                    return
+            tries += 1
         if not cp.patch_url:
             ui.status('No raw patch URL found', '\n')
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.