[Twisted-Python] [patch] three short ones
Sune Kirkeby
sune at mel.interspace.dk
Fri May 31 09:04:48 EDT 2002
Hello twisted-ppl,
Attached you'll find three short patches, two against
t.w.widgets.RenderSession and one against t.p.http.Request.
The first patch makes RenderSession unicode-agnostic (i.e. makes it
treat string and unicode object alike). The second one makes
t.p.http.Request aware of unicode, to the extent that it will
correctly handle unicode strings with all ordinals < 128 (by simply
str'ing them).
The last patch makes RenderSession.callback return the result it was
passed, so that later callbacks made by the given Deferred also
benefit from this knowledge. It had completely escaped me that
Deferred._runCallbacks acts like a folding operation, last I poked
around in the code.
Regards,
--
Sune Kirkeby | % cat /usr/include/sys/errno.h
| #define EPERM 1 /* Operation not permitted */
| [...]
| #define EMACS 666 /* Editor Too Large */
-------------- next part --------------
Index: widgets.py
===================================================================
RCS file: /cvs/Twisted/twisted/web/widgets.py,v
retrieving revision 1.46
diff -u -r1.46 widgets.py
--- widgets.py 26 May 2002 06:42:38 -0000 1.46
+++ widgets.py 31 May 2002 12:41:44 -0000
@@ -802,7 +802,8 @@
self.forgotten = 1
return
- if isinstance(item, types.StringType):
+ stringtypes = getattr(types, 'StringTypes', types.StringType)
+ if isinstance(item, stringtypes):
self.beforeBody = 0
self.request.write(item)
elif type(item) is types.TupleType and len(item) > 0:
-------------- next part --------------
Index: http.py
===================================================================
RCS file: /cvs/Twisted/twisted/protocols/http.py,v
retrieving revision 1.21
diff -u -r1.21 http.py
--- http.py 18 May 2002 22:18:41 -0000 1.21
+++ http.py 31 May 2002 13:02:32 -0000
@@ -24,6 +24,7 @@
import string
from cStringIO import StringIO
import tempfile
+import types
import base64
import cgi
import urllib
@@ -518,6 +519,13 @@
if self.method == "HEAD":
self.write = lambda data: None
return
+
+ # this converts unicode w/o high-bits to normal strings,
+ # should probably be replaced with something that knows
+ # about the Content-Type charset parameter and codecs,
+ stringtypes = getattr(types, 'StringTypes', types.StringType)
+ if isinstance(data, stringtypes):
+ data = str(data)
self.sentLength = self.sentLength + len(data)
if data:
-------------- next part --------------
Index: widgets.py
===================================================================
RCS file: /cvs/Twisted/twisted/web/widgets.py,v
retrieving revision 1.46
diff -u -r1.46 widgets.py
--- widgets.py 26 May 2002 06:42:38 -0000 1.46
+++ widgets.py 31 May 2002 12:43:14 -0000
@@ -731,7 +731,7 @@
def callback(self, result, sentinel, decNeedsHeaders):
if self.forgotten:
- return
+ return result
if result != FORGET_IT:
self.needsHeaders = self.needsHeaders - decNeedsHeaders
else:
@@ -786,6 +786,7 @@
for r in toArm:
r.arm()
+ return result
def keepRendering(self):
if self.needsHeaders:
More information about the Twisted-Python
mailing list