7
7
from twisted .web import resource , static
8
8
from twisted .web .server import NOT_DONE_YET
9
9
from twisted .web .wsgi import WSGIResource , _WSGIResponse
10
+ from twisted .logger import Logger
10
11
11
- import logging
12
12
import chalk
13
- from twisted .internet .threads import deferToThread
14
13
import threading
15
- import uuid
16
-
17
- logger = logging .getLogger (__name__ )
18
-
19
- # thread_list = [] # Debug
14
+ import uuid
20
15
21
16
22
17
class HendrixWSGIResponse (_WSGIResponse ):
23
18
19
+ log = Logger ()
20
+
24
21
def __init__ (self , * args , ** kwargs ):
25
22
self .crosstown_tasks = []
26
23
return super (HendrixWSGIResponse , self ).__init__ (* args , ** kwargs )
27
24
28
25
def run (self , * args , ** kwargs ):
29
26
self .thread = threading .current_thread ()
30
- # thread_list.append(self.thread) # Debug
31
- # logger.debug("Assigning %s as the current response for thread %s" % (self, self.thread))
32
27
self .thread .response_object = self
33
28
self .request .setHeader ('server' , 'hendrix/Twisted' )
34
29
ran = super (HendrixWSGIResponse , self ).run (* args , ** kwargs )
35
30
self .follow_response_tasks ()
36
31
return ran
37
-
38
- def follow_response_tasks (self ):
39
32
33
+ def follow_response_tasks (self ):
40
34
for task in self .crosstown_tasks :
41
- logger .info ("Processing crosstown task: '%s'" % task )
42
35
task .run (self .threadpool )
43
36
37
+
44
38
class LoudWSGIResponse (HendrixWSGIResponse ):
45
39
46
40
def startResponse (self , status , headers , excInfo = None ):
@@ -55,19 +49,20 @@ def startResponse(self, status, headers, excInfo=None):
55
49
responseInColor , self .request , status , headers
56
50
)
57
51
return self .write
58
-
52
+
59
53
60
54
class HendrixWSGIResource (WSGIResource ):
61
-
55
+
62
56
ResponseClass = HendrixWSGIResponse
63
-
64
- def render (self , request ):
57
+
58
+ def render (self , request ):
65
59
response = self .ResponseClass (
66
- self ._reactor , self ._threadpool , self ._application , request )
60
+ self ._reactor , self ._threadpool , self ._application , request
61
+ )
67
62
response .start ()
68
63
return NOT_DONE_YET
69
64
70
-
65
+
71
66
class DevWSGIResource (HendrixWSGIResource ):
72
67
73
68
ResponseClass = LoudWSGIResponse
@@ -86,12 +81,16 @@ class HendrixResource(resource.Resource):
86
81
to ensure that django always gets the full path.
87
82
"""
88
83
84
+ log = Logger ()
85
+
89
86
def __init__ (self , reactor , threads , application , loud = False ):
90
87
resource .Resource .__init__ (self )
91
88
if loud :
92
89
self .wsgi_resource = DevWSGIResource (reactor , threads , application )
93
90
else :
94
- self .wsgi_resource = HendrixWSGIResource (reactor , threads , application )
91
+ self .wsgi_resource = HendrixWSGIResource (
92
+ reactor , threads , application
93
+ )
95
94
96
95
def getChild (self , name , request ):
97
96
"""
@@ -137,11 +136,12 @@ def putNamedChild(self, res):
137
136
138
137
name = parts [- 1 ] # get the path part that we care about
139
138
if children .get (name ):
140
- logger .warning (
141
- 'A resource already exists at this path. Check '
142
- 'your resources list to ensure each path is '
143
- 'unique. The previous resource will be overridden.'
144
- )
139
+ # self.log.warn(
140
+ # 'A resource already exists at this path. Check '
141
+ # 'your resources list to ensure each path is '
142
+ # 'unique. The previous resource will be overridden.'
143
+ # )
144
+ pass
145
145
parent .putChild (name , res )
146
146
except AttributeError :
147
147
# raise an attribute error if the resource `res` doesn't contain
@@ -215,9 +215,6 @@ def DjangoStaticResource(path, rel_url='static'):
215
215
rel_url = rel_url .strip ('/' )
216
216
StaticFilesResource = MediaResource (path )
217
217
StaticFilesResource .namespace = rel_url
218
- chalk .green (
219
- "Adding media resource for URL '%s' at path '%s'" % (rel_url , path )
220
- )
221
218
return StaticFilesResource
222
219
223
220
0 commit comments