changeset eb2fc46a1f86 in tryton-tools:default
details: https://hg.tryton.org/tryton-tools?cmd=changeset;node=eb2fc46a1f86
description:
        Update hglookup for removal of wsgirequest in Mercurial 4.6

        https://www.mercurial-scm.org/repo/hg/rev/f0a851542a05
diffstat:

 hglookup.py |  41 ++++++++++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 17 deletions(-)

diffs (69 lines):

diff -r ced0f284e3e0 -r eb2fc46a1f86 hglookup.py
--- a/hglookup.py       Sun Jan 26 15:44:33 2020 +0100
+++ b/hglookup.py       Tue Jan 28 00:27:46 2020 +0100
@@ -5,12 +5,13 @@
 # Written by Georg Brandl, 2010.
 import re
 
-from mercurial.hgweb.request import wsgirequest
+from mercurial.hgweb.request import parserequestfromenv, wsgiresponse
 from mercurial.hgweb.hgwebdir_mod import findrepos
 from mercurial import hg, ui, node as hgnode, error
 
-HTTP_SEE_OTHER = 303
-HTTP_NOT_FOUND = 404
+HTTP_SEE_OTHER = '303 See Other'
+HTTP_NOT_FOUND = '404 Not Found'
+TEXT_PLAIN = 'text/plain'
 SERIES = re.compile('^([0-9.]+)/')
 
 
@@ -20,17 +21,20 @@
         self.ui = ui.ui()
         self.ui.readconfig(conf, trust=True)
 
-    def __call__(self, env, respond):
-        ctype = 'text/plain'
-        req = wsgirequest(env, respond)
-        node = req.env.get('PATH_INFO', '')[len('/lookup'):].strip('/')
+    def __call__(self, env, start_response):
+        req = parserequestfromenv(env)
+        res = wsgiresponse(req, start_response)
+        node = req.rawenv.get('PATH_INFO', '')[len('/lookup'):].strip('/')
         if not node:
-            req.respond(HTTP_NOT_FOUND, ctype)
-            return ['Usage: /lookup/HGHEXNODE\n']
+            res.status = HTTP_NOT_FOUND
+            res.headers['Content-Type'] = TEXT_PLAIN
+            res.setbodygen(['Usage: /lookup/HGHEXNODE\n'])
+            return res.sendresponse()
         if node in self.cache:
-            req.headers.append(('Location', self.cache[node]))
-            req.respond(HTTP_SEE_OTHER, ctype)
-            return []
+            res.status = HTTP_SEE_OTHER
+            res.headers['Location'] = self.cache[node]
+            res.setbodygen([])
+            return res.sendresponse()
         for name, path in findrepos(self.ui.configitems('paths')):
             if SERIES.match(name):
                 continue
@@ -42,10 +46,13 @@
             else:
                 break
         else:
-            req.respond(HTTP_NOT_FOUND, ctype)
-            return ['Specified changeset %s not found\n' % node]
+            res.status = HTTP_NOT_FOUND
+            res.headers['Content-Type'] = TEXT_PLAIN
+            res.setbodygen(['Specified changeset %s not found\n' % node])
+            return res.sendresponse()
         url = '/%s/rev/%s/' % (name, hgnode.hex(full)[:12])
         self.cache[node] = url
-        req.headers.append(('Location', url))
-        req.respond(HTTP_SEE_OTHER, ctype)
-        return []
+        res.status = HTTP_SEE_OTHER
+        res.headers['Location'] = url
+        res.setbodygen([])
+        return res.sendresponse()

Reply via email to