Opened 5 years ago

Closed 5 years ago

#6078 enhancement closed fixed (fixed)

Port twisted.web.resource to Python 3

Reported by: Jean-Paul Calderone Owned by: Jean-Paul Calderone
Priority: normal Milestone: Python 3.3 Minimal
Component: web Keywords:
Cc: jknight Branch: branches/resource-py3-6078-2
branch-diff, diff-cov, branch-cov, buildbot
Author: exarkun

Description

The basis of the resource publishing model for the Twisted Web server.

Change History (9)

comment:1 Changed 5 years ago by DefaultCC Plugin

Cc: jknight added

comment:2 Changed 5 years ago by Jean-Paul Calderone

Author: exarkun
Branch: branches/resource-py3-6078

(In [36108]) Branching to 'resource-py3-6078'

comment:3 Changed 5 years ago by Jean-Paul Calderone

Basically done, I think, except:

  1. depends on prefixedMethodNames (#6100)
  2. I threw some encode('ascii') and decode('ascii') in. They get the job done in the naive case, but maybe they merit some additional error handling code? Or something? Or maybe 'latin-1' is a better charset to use. Also, maybe they suck for the Python 2 case - time for another string type/compat helper?

Maybe other stuff is terrible about this too, but those stand out to me.

comment:4 Changed 5 years ago by Jean-Paul Calderone

Keywords: review added
Owner: changed from Jean-Paul Calderone to Itamar Turner-Trauring

Still depends on #6100 being resolved first.

comment:5 Changed 5 years ago by Itamar Turner-Trauring

Keywords: review removed
Owner: changed from Itamar Turner-Trauring to Jean-Paul Calderone

Nice to see extra tests.

  1. I'm fine with HTTP methods being ASCII only (latin-1 doesn't make sense to me; I suppose it's possible RFC will be expanded to be UTF-8 someday, but not that). For the decode case, nativeString is what you want to use, I believe; in particular since on Python 2 this is a slightly more expensive way of doing what the current trunk code does, so no change or potential for new errors. For the encode... we could create nativeStringToBytes? I suppose if we find another instance where this is necessary we should create it, but for now I'd say just leave it as is.
  2. Resource and IResource could use some addition and clarification of the types of parameters. E.g. IResource doesn't mention types at all, and Resource says string when it means bytes.
  3. Resource.getChild code example should indicate bytes, likewise putChild.
  4. Add the byteness of path elements to the porting howto.

Fix the above, then merge (after #6100 I guess).

comment:6 Changed 5 years ago by Jean-Paul Calderone

(In [36145]) Fixes to string types used by ErrorPage-related code.

refs #6078

comment:7 Changed 5 years ago by Jean-Paul Calderone

Branch: branches/resource-py3-6078branches/resource-py3-6078-2

(In [36147]) Branching to 'resource-py3-6078-2'

comment:8 Changed 5 years ago by Jean-Paul Calderone

I'm fine with HTTP methods being ASCII only (latin-1 doesn't make sense to me; I suppose it's possible RFC will be expanded to be UTF-8 someday, but not that). For the decode case, nativeString is what you want to use, I believe; in particular since on Python 2 this is a slightly more expensive way of doing what the current trunk code does, so no change or potential for new errors. For the encode... we could create nativeStringToBytes? I suppose if we find another instance where this is necessary we should create it, but for now I'd say just leave it as is.

Switched to nativeString and added a comment for the encode case in r36142.

Resource and IResource could use some addition and clarification of the types of parameters. E.g. IResource doesn't mention types at all, and Resource says string when it means bytes. Resource.getChild code example should indicate bytes, likewise putChild.

Fixed in r36143.

Add the byteness of path elements to the porting howto.

Did that in r36144.

Also fixed some ErrorPage stuff in r36145 and r36146.

comment:9 Changed 5 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(In [36151]) Merge resource-py3-6078-2

Author: exarkun Reviewer: itamarst Fixes: #6078

Port twisted.web.error and twisted.web.resource to Python 3. Also add some unit tests for twisted.web.resource.Resource which were previously missing.

Note: See TracTickets for help on using tickets.