This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.web.resource import Resource | |
from twisted.web.server import Site, NOT_DONE_YET | |
from twisted.web.client import getPage | |
from twisted.internet import reactor, defer, task | |
from twisted.names.client import createResolver | |
from twisted.names import dns | |
from twisted.python import log | |
import sys | |
log.startLogging(sys.stdout) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -N localhost:8000 | |
<html><body>http://adobe.com <twisted.names.dns.Message instance at 0x10261c830> <twisted.names.dns.Message instance at 0x10261c830> | |
{'OK': 0, 'TIMEOUT': 0, 'ERROR': 1} | |
{'OK': 1, 'TIMEOUT': 0, 'ERROR': 1} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python monitor3.py | |
2011-06-17 12:22:43+0300 [-] Log opened. | |
2011-06-17 12:22:43+0300 [-] /etc/resolv.conf changed, reparsing | |
2011-06-17 12:22:43+0300 [-] Resolver added ('10.0.99.1', 53) to server list | |
2011-06-17 12:22:43+0300 [-] twisted.web.server.Site starting on 8000 | |
2011-06-17 12:22:43+0300 [-] Starting factory <twisted.web.server.Site instance at 0x1025ff128> | |
2011-06-17 12:22:44+0300 [-] Starting factory <HTTPClientFactory: http://apple.com> | |
2011-06-17 12:22:44+0300 [-] Starting factory <HTTPClientFactory: http://adobe.com> | |
2011-06-17 12:22:44+0300 [-] <class 'twisted.names.dns.DNSDatagramProtocol'> starting on 56464 | |
2011-06-17 12:22:44+0300 [-] Starting protocol <twisted.names.dns.DNSDatagramProtocol object at 0x102615c10> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.web.client import getPage | |
from twisted.internet import reactor, task | |
from twisted.names.client import createResolver | |
def p(s): | |
print s | |
def _getPage(address): | |
d = getPage(address, timeout=10) | |
d.addCallback(lambda _, a=address: p("OK " + a)) | |
d.addErrback(lambda e, a=address: p("NO " + a + ' ' + e.getErrorMessage())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Pdb) mes = e.value.message | |
(Pdb) mes | |
<twisted.names.dns.Message instance at 0x102d40ea8> | |
(Pdb) mes.answer | |
1 | |
(Pdb) mes.queries | |
[Query('apple.com', 255, 1)] | |
(Pdb) mes.answers | |
[] | |
(Pdb) mes.additional |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import Bottle, template, request, run | |
app = Bottle() | |
@app.route('/hello/') | |
def greet(): | |
return template(''' | |
<html> | |
<body> | |
Please introduce yourself: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# crochet allows non-twisted apps to call twisted code | |
import crochet | |
crochet.no_setup() | |
from twisted.application import internet, service | |
from twisted.web import server, wsgi, static, resource | |
from twisted.internet import reactor | |
from twisted.python import threadpool | |
# boilerplate to get any WSGI app running under twisted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import crochet | |
crochet.setup() | |
from twisted.web import resource, server | |
import random | |
from datetime import datetime | |
import json | |
def _format_sse(msg, event=None): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript"> | |
var evtSource = new EventSource("/sse"); | |
evtSource.onmessage = function(e) { | |
// onmessage is the generic handler | |
var eventList = document.getElementById("eventlist"); | |
var newElement = document.createElement("li"); | |
newElement.innerHTML = "message: " + e.data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
response: '{"data":{"id":"35","type":"file-upload","attributes":{"file":"http://example.com/somefile"}, "relationships":{}}}', | |
data: null, | |
normal: null, | |
objPush: null, | |
objPushPayload: null, | |
actions: { |