Patchwork D2688: hgweb: adapt to socket._fileobject changes in Python 3

login
register
mail settings
Submitter phabricator
Date March 5, 2018, 2:20 a.m.
Message ID <differential-rev-PHID-DREV-b4kcozvby55umr3e2cw4-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/29039/
State Superseded
Headers show

Comments

phabricator - March 5, 2018, 2:20 a.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  These are the only uses of socket._fileobject in the codebase, so
  let's just do something inline here rather than adding something to
  pycompat.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2688

AFFECTED FILES
  mercurial/hgweb/server.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - March 6, 2018, 9:37 a.m.
yuja requested changes to this revision.
yuja added a comment.
This revision now requires changes to proceed.


  As long as `self.request` is a socket object, we can use `request.makefile()` on Python 2.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2688

To: durin42, #hg-reviewers, yuja
Cc: yuja, mercurial-devel
phabricator - March 6, 2018, 6:43 p.m.
durin42 added a comment.


  Oh, good catch. Fixed and passes tests on 2.7. :)

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2688

To: durin42, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -257,8 +257,10 @@ 
 
     def setup(self):
         self.connection = self.request
-        self.rfile = socket._fileobject(self.request, "rb", self.rbufsize)
-        self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)
+        fo = getattr(socket, '_fileobject',
+                     lambda s, mode, bufsize: s.makefile(mode, bufsize))
+        self.rfile = fo(self.request, r"rb", self.rbufsize)
+        self.wfile = fo(self.request, r"wb", self.wbufsize)
 
 try:
     import threading