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
| """ Monkey patch to hit wsgi apps when using urlfetch | |
| This will monkey patch App Engine's urlfetch.fetch with a fetch that hits a local | |
| wsgi app registered with add_intercept. This module is inspired by and borrows | |
| code from the wsgi-intercept project, which doesn't work with App Engine. | |
| This is intended only for the local SDK environment for unit tests. | |
| Usage: |
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
| """ Cruster -- distributed group membership system | |
| Cruster provides distributed group membership for easily building clustered | |
| applications with gevent. Using Cruster in your app, you just provide the IP | |
| of another node in the cluster and it will receive the IPs of all nodes in | |
| the cluster. When a node joins or drops from the cluster, all other nodes find | |
| out immediately. | |
| The roster is managed by a leader. When you create a cluster, you tell the | |
| first node it is the leader (by simply pointing it to its own IP). As you |
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
| """A line protocol generator | |
| Usage: | |
| import socket | |
| sock = socket.create_connection((host, port)) | |
| for line in line_protocol(sock): | |
| print line | |
| sock.send("ack!") |
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 gevent | |
| import gevent.pool | |
| class GroupWithExceptionCatching(gevent.pool.Group): | |
| def __init__(self, *args): | |
| super(GroupWithExceptionCatching, self).__init__(*args) | |
| self._error_handlers = {} | |
| def _wrap_errors(self, func): | |
| """Wrap a callable for triggering error handlers |
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 asyncore, socket, sys | |
| class MyClient(asyncore.dispatcher): | |
| def __init__(self, host, port, name): | |
| asyncore.dispatcher.__init__(self) | |
| self.name = name | |
| self.create_socket(socket.AF_INET, socket.SOCK_STREAM) | |
| self.connect( (host, port) ) | |
| print 'Started to connect.' | |
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 getPage(url): | |
| d = Deferred() | |
| # here it would set up an http client programmed to call | |
| # d.callback(body) when page is fully received... | |
| return d | |
| def handleBody(body): | |
| print body |
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
| function repeat(times:int, loop:Function) { | |
| for (i=0;i<times;i++){ | |
| loop.call(); | |
| } | |
| } | |
| repeat(10, function() { | |
| // stuff | |
| }) |
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
| >>> h.heap() | |
| Partition of a set of 3149666 objects. Total size = 432576704 bytes. | |
| Index Count % Size % Cumulative % Kind (class / dict of class) | |
| 0 301452 10 110323872 26 110323872 26 dict (no owner) | |
| 1 299175 9 88555800 20 198879672 46 realtime.utils.attrdict | |
| 2 299176 9 83769280 19 282648952 65 dict of realtime.utils.dispatcher.CallbackDispatcher | |
| 3 669660 21 45685424 11 328334376 76 str | |
| 4 599730 19 43301008 10 371635384 86 list | |
| 5 339907 11 24939144 6 396574528 92 tuple | |
| 6 299176 9 19147264 4 415721792 96 realtime.utils.dispatcher.CallbackDispatcher |
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
| for scope in path_scopes: | |
| filter_constraints = cgi.parse_qs(scope.params.get('params', '')) | |
| filter_keys = set(request.args.keys()) & set(filter_constraints.keys()) | |
| def arg_satisfies_filter(f): | |
| return set(request.args[f]).issubset(set(filter_constraints[f])) | |
| if all(arg_satisfies_filter(f) for f in filter_keys): | |
| # if for every parameter, the values are a subset of allowed params, we good! | |
| return True |
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 gevent.pywsgi | |
| from websocket import WebSocketUpgrader | |
| class UpgradableWSGIHandler(gevent.pywsgi.WSGIHandler): | |
| def handle_one_response(self): | |
| connection_header = self.environ.get('HTTP_CONNECTION', '').lower() | |
| if connection_header == 'upgrade' and self.server.upgrade_handler: | |
| upgrade_header = self.environ.get('HTTP_UPGRADE', '').lower() | |
| handler = self.server.upgrade_handler(upgrade_header, self.environ) |