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
#!/usr/bin/env python | |
### | |
### Field Concepts | |
### | |
class IntField(object): | |
def __init__(self): | |
print 'new int field' |
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
class xrange(object): | |
def __init__(self, x): | |
self.offset = 0 | |
self.x = x | |
def __len__(self): | |
return self.x | |
def __iter__(self): | |
return self | |
def next(self): | |
if self.offset == self.x: |
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
>>> def foo(): | |
... foo.x = 5 | |
... foo.get = lambda: foo.x | |
... def set(x): | |
... foo.x = x | |
... foo.set = set | |
... | |
>>> foo() | |
>>> foo.get() | |
5 |
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
#!/usr/bin/env python | |
import tornado | |
import tornado.escape | |
import tornado.httpclient | |
import tornado.ioloop | |
import tornado.web | |
urls = [ | |
"http://friendfeed-api.com/v2/feed/bret", |
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
==> typespecs (get-deps) | |
[Building...] | |
==> typespecs (compile) | |
==> agner.SC7PqD (compile) | |
ERROR: OTP release R15B does not match required regex R14 | |
make: *** [compile] 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
$ ./m2reader.py | |
34f9ceee-cd52-4b7f-b197-88bf2f0ec378 0 / 571:{"PATH":"/","x-forwarded-for":"127.0.0.1","accept-language":"en-US,en;q=0.8","accept-encoding":"gzip,deflate,sdch","connection":"keep-alive","accept-charset":"ISO-8859-1,utf-8;q=0.7,*;q=0.3","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30","host":"localhost:6767","METHOD":"GET","VERSION":"HTTP/1.1","URI":"/","PATTERN":"/"},0:, |
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 request_handling import WebMessageHandler | |
### Rendering Mixing | |
class TemplateRendering(WebMessageHandler): | |
def render_template(self, template_file, | |
_status_code=WebMessageHandler._SUCCESS_CODE, | |
**context): | |
body = self.application.render_template(template_file, **context or {}) |
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
# All of this testing was done on an AWS m1.large with a single Python | |
# process. I ran the commands multiple times and the numbers below are | |
# typical of the behavior, though they are the results of two particular | |
# cases | |
# Brubeck with Gevent | |
$ siege -c500 -t10s localhost:6767/brubeck | |
Lifting the server siege... done. |
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
#! /usr/bin/env python | |
from brubeck.request_handling import Brubeck, http_response | |
from brubeck.templating import load_jinja2_env | |
from brubeck.templating import Jinja2Rendering | |
app = Brubeck(mongrel2_pair=('ipc://127.0.0.1:9999', | |
'ipc://127.0.0.1:9998'), |
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 dictshield.document import Document, EmbeddedDocument | |
from dictshield.fields import StringField, UUIDField | |
from dictshield.fields.mongo import ObjectIdField | |
class ThoughtsMixin(EmbeddedDocument): | |
"""Simple document that has one StringField member | |
""" | |
thoughts = StringField(max_length=255) | |
class Meta: |