Ticket #288: scribbles.py

File scribbles.py, 1.5 KB (added by exarkun, 4 years ago)

Some unexplained sketches of what an implementation might look like

Line 
1
2class NonStreamingRequest(object):
3      def __init__(self, streamingRequest, bytes):
4          # set up all old request attributes
5          self.content = StringIO(bytes)
6
7
8class OldToNew:
9      def __init__(self, wrapped, segments=None):
10          self.wrapped = wrapped
11          self.segments = segments or []
12
13      def getChild(self, name, request):
14          return OldToNew(self.wrapped, self.segments + [name])
15
16
17      def render(self, request):
18          d = self.request.body.startProducing(self)
19          def cbProduced(ignored):
20              oldRequest = NonStreamingRequest(request, self.bytes)
21              resource = self.wrapped
22              for path in self.segments:
23                  resource = resource.getChild(path, oldRequest)
24              result = resource.render(NonStreamingRequest(request, self.bytes))
25              # process result
26          d.addCallback(cbProduced)
27          return NOT_DONE_YET
28         
29
30      def write(self, bytes):
31            self.bytes += bytes
32     
33
34
35class Request:
36      def allHeadersReceived(self):
37          # parse url
38          resource = IStreamingResource(self.site.resource)
39          while urlSegments:
40                resource = resource.getChild(urlSegments.pop(0), self)
41          if urlSegments:
42             resource = NonStreamingWrapper(resource)
43          resource.render(self)
44
45
46
47      def allHeadersReceived(self):
48          # parse url
49          resource = self.site.resource
50          while urlSegments and IStreamingResource.providedBy(resource):
51                resource = resource.getChild(urlSegments.pop(0))
52          if urlSegments:
53             resource = NonStreamingWrapper(resource)
54          resource.render(self)
55
56
57