« RESTful JSONWriting High-Efficiency Large Python Systems--Lesson #3: Banish lazy imports »

CherryPy for Python 3000

07/25/08

Permalink 01:20:56 am, by fumanchu Email , 243 words   English (US)
Categories: Python, CherryPy

CherryPy for Python 3000

I'm categorically rejecting the 2to3 approach--for myself anyway. If you think it would help, feel free to:

  1. "upgrade" CP to 2.6, which AFAICT means ensuring it will no longer work in 2.5 or previous versions
  2. turn on the 3k warning
  3. import-and-fix until you don't get any warnings
  4. run-tests-and-fix until you don't get any warnings
  5. run 2to3
  6. import-and-fix until you don't get any errors
  7. run-tests-and-fix until you don't get any errors
  8. wait for bug reports

Me, I'd rather just drop cherrypy/ into 3k and skip steps 1-5.

Changes I had to make so far (http://www.cherrypy.org/changeset/2029):

  • (4) urlparse -> urllib.parse
  • (24) "except (ExcA, ExcB):" -> "except ExcA, ExcB:"
  • (30) "except ExcClass, x:" -> "except ExcClass as x"
  • (22) u"" -> ""
  • (1) BaseHTTPServer -> http.server
  • (1) rfc822 -> email.utils
  • (4) md5.new() -> hashlib.md5()
  • (3) sha.new() -> hashlib.sha1()
  • (3) urllib2 -> urllib
  • (28) StringIO -> io
  • (1) func.func_code -> func.code
  • (6) Cookie -> http.cookies
  • (3) ConfigParser -> configparser
  • (1) rfc822._monthnames -> email._parseaddr._monthnames
  • (105) print -> print()
  • (35) httplib -> http.client
  • (22) basestring -> (str, bytes)
  • (12) items() -> list(items())
  • (46) iteritems() -> items()
  • (11) Thread.get/setName -> get/set_name
  • (1) exec "" -> exec("")
  • (1) 0777 -> 0o777
  • (1) Queue -> queue
  • (1) urllib.unquote -> urllib.parse.unquote

At the moment, I'm a bit blocked importing wsgiserver--we had a nonblocking version of makefile that subclassed the old socket._fileobject class. Looks like the whole socket implementation has changed (and much of it pushed down into C). Not looking forward to reimplementing that.

8 comments

Comment from: Benjamin Peterson [Visitor] Email · http://pybites.blogspot.com

I would recommend you at least reinclude step 5. 80-90% of the items you listed can be fixed by 2to3.

07/25/08 @ 13:21
Comment from: John P. Speno [Visitor] · http://speno.blogspot.com

I enjoyed this post. Thanks!

07/26/08 @ 12:36
Comment from: fumanchu [Member] Email

Ha, John, I was looking for a link to a spam site when I read your comment. Good thing I know you. :) You're always welcome.

07/26/08 @ 13:46
Comment from: Nicolas Grilly [Visitor] Email · http://blog.grilly.com

Thanks for this interesting post! I'm really happy to know you are updating CherryPy to Python 3.0.

07/27/08 @ 06:16
Comment from: Seun Osewa [Visitor]

Where can I get the Python 3000 compatible version of Cherrypy? Thanks in advance.

09/22/08 @ 18:10
Comment from: Nabil Stendardo [Visitor]

Hmmm,
According to me, subclassing concrete classes which aren't meant to be subclassed is an anti-pattern IMHO (especially implementation details starting with an underscore). Apart from that, where are you at with the implementation? Python 3.0 is definitely one of the cleanest languages, and I hope most current libraries and support software (such as easy-install) will update.

01/19/09 @ 13:51
Comment from: Arc Riley [Visitor] Email · https://www.ohloh.net/accounts/ArcRiley

Any updates on this? WSGI now has py3k support, it'd be nice to be able to use it within a framework.

01/20/09 @ 15:50
Comment from: fumanchu [Member] Email

Py3k support in CP is one of my goals before PyCon 09. Feel free to join the effort.

01/20/09 @ 22:15

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.

Please enter the phrase "I am a real human." in the textbox above.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
May 2017
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Search

The requested Blog doesn't exist any more!

XML Feeds

blogtool