Skip to content

Commit

Permalink
web: add send_javascript method to tinyhttpserver
Browse files Browse the repository at this point in the history
  • Loading branch information
borisfaure committed Jul 27, 2010
1 parent 9a8801a commit ffd60c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 1 addition & 11 deletions amsn2/ui/front_ends/web/bend.py
Expand Up @@ -61,20 +61,10 @@ def on_accept(self, s, c):
self._workers.append(t)
return True

def emit_event(self, event, *args, **kwargs):
"""
if event in self.listeners.keys():
for func in self.listeners[event]:
try:
func(*args, **kwargs)
except:
pass
"""

def out(self, w, uri, headers, body = None):
if len(self._q):
print ">>> %s" % (self._q,)
w._200(self._q)
w.send_javascript(self._q)
self._q = ""

def _args2JS(self, *args):
Expand Down
8 changes: 8 additions & 0 deletions amsn2/ui/front_ends/web/tinyhttpserver.py
Expand Up @@ -183,6 +183,14 @@ def send_file(self, path):
% (len(r), r))
self.close()

def send_javascript(self, code):
if code:
self.write("HTTP/1.1 200 OK\r\nContent-Type: text/javascript; charset=UTF-8\r\nContent-Length: %d\r\n\r\n%s"
% (len(code), code))
else:
self.write("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n")
self.close()

def _200(self, body = None):
if body:
self.write("HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s"
Expand Down

0 comments on commit ffd60c5

Please sign in to comment.