0

I try to use pypy 2.5.1 replace python 2.7:

I used mechanize 0.2.5 package for pypy:

The problem is on /mechanize/_ulib2_fork.py line 70

try:
    socket._fileobject("fake socket", close=True)
except TypeError:
    ....

here I want to replace the "fake socket" string with some real fake socket. How to do it?

I want to do this because:

the _fileobject function will invoke init function and the init():

 def __init__(self, sock, mode='rb', bufsize=1, close=False):
     socket._resue()  //there will be error

the _reuse() function only defined in socket object not string object

(Actually, for combine with mechanize and pypy, I get AttributeError replace NameEorror. The reason is the socket would be string 'str' replace the reality socket object here. I need a presudo socket object here)

user504909
  • 9,119
  • 12
  • 60
  • 109

1 Answers1

0

According to the source, this is a hack done only to check if we're running a very old version of Python (<= 2.4). You can fix it by completely deleting it (so in the link above, delete lines 69-74 and de-indent the following lines 75-76).

Armin Rigo
  • 12,048
  • 37
  • 48
  • for combine with mechanize and pypy, I get AttributeError replace NameEorror. The reason is the socket would be string 'str' replace the reality socket object here. – user504909 May 01 '15 at 00:30
  • the link provided is down, mechanize project was moved to other project, so the correct link is https://github.com/python-mechanize/mechanize/blob/master/mechanize/_urllib2_fork.py – juliocesar Dec 18 '17 at 10:31