Klaus Demo bjoern / 01e28f7
More filewrapper fixes Jonas Haag 2 years ago
2 changed file(s) with 25 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
88 void FileWrapper_Done(PyObject *self)
99 {
1010 PyFile_DecUseCount((PyFileObject*)((FileWrapper*)self)->file);
11 Py_DECREF(((FileWrapper*)self)->file);
1211 }
1312
1413 static PyObject*
4847 return PyObject_GetIter(((FileWrapper*)self)->file);
4948 }
5049
50 void FileWrapper_dealloc(PyObject* self)
51 {
52 Py_DECREF(((FileWrapper*)self)->file);
53 PyObject_FREE(self);
54 }
55
5156 PyTypeObject FileWrapper_Type = {
5257 PyVarObject_HEAD_INIT(NULL, 0)
5358 "FileWrapper", /* tp_name (__name__) */
54 sizeof(FileWrapper) /* tp_basicsize */
59 sizeof(FileWrapper), /* tp_basicsize */
60 0, /* tp_itemsize */
61 (destructor)FileWrapper_dealloc, /* tp_dealloc */
5562 };
5663
5764 void _init_filewrapper(void)
00 import os
11 import random
2 import httplib
2 try:
3 import httplib
4 except ImportError:
5 import http.client as httplib
36 import socket
47
58 HOST = ('127.0.0.1', 9000)
8689
8790 def _tinker_request(self):
8891 if self.http_minor == 0:
89 req = 'GET / HTTP/1.0\r\n'
92 req = b'GET / HTTP/1.0\r\n'
9093 if self.want_keep_alive:
91 req += 'Connection: Keep-Alive\r\n'
94 req += b'Connection: Keep-Alive\r\n'
9295 else:
93 req = 'GET / HTTP/1.1\r\n'
96 req = b'GET / HTTP/1.1\r\n'
9497 if not self.want_keep_alive:
95 req += 'Connection: close\r\n'
96 req += '\r\n'
98 req += b'Connection: close\r\n'
99 req += b'\r\n'
97100 return req
98101
99102 def send_request(self, data):
114117 raise ValueError('bar')
115118 start_response('200 ok', headers)
116119 # second item is to trick bjoern's internal optimizations:
117 return [self.body, '']
120 return [self.body, b'']
118121
119 import thread
122 try:
123 import thread
124 except ImportError:
125 import _thread as thread
120126 import bjoern
121127 thread.start_new_thread(bjoern.run, (dispatcher,)+HOST)
122128
159165 ( 1, 1, 1, 0, 0, 0),
160166 ( 1, 1, 1, 1, 0, 0)
161167 ]):
162 print 'Running test %d: %r' % (index, tpl)
168 print('Running test %d: %r' % (index, tpl))
163169 class _test(Testcase):
164170 http_minor, \
165171 raise_error, \
169175 expect_keep_alive = tpl
170176 _test().run()
171177
172 print '--- SUCCESS! ---'
178 print('--- SUCCESS! ---')