Skip to content

Instantly share code, notes, and snippets.

View lvh's full-sized avatar

lvh lvh

View GitHub Profile
meese is a built-in package.
Status: Built-in.
Summary: protect the impressionable young minds of America
Adds a hook to protect the impressionable young minds of America
from reading certain files in the Emacs distribution using Emacs.
This file is named after Ed Meese, the US Attorney General
"""
AMP over WebSockets support.
"""
import json
import txws
from twisted.internet import defer, protocol
from twisted.python import log
class C1(object):
class __metaclass__(type):
def __new__(meta, name, bases, attrs):
attrs["sentinel"] = object()
return type(name, bases, attrs)
class C2(object):
class __metaclass__(type):
def __new__(meta, name, bases, attrs):
attrs["sentinel"] = object()
@lvh
lvh / client.py
Created July 6, 2012 08:37
Twisted file upload
import random
import StringIO
from zope import interface
from twisted.internet import abstract, defer, reactor
from twisted.web import client, http_headers, iweb
class _FileProducer(object): # pragma: no cover
"""
class ComposedLocator(object):
"""
A responder locator that consists of other locators.
"""
interface.implements(amp.IResponderLocator)
class __metaclass__(type):
def __new__(meta, name, bases, attrs):
"""
Makes sure every subclass gets its own set of locator classes.
from twisted.protocols import amp
class NestedAMPBox(amp.AmpList):
def fromStringProto(self, inString, proto):
value, = amp.AmpList.fromStringProto(self, inString, proto)
return value
def toStringProto(self, inObject, proto):
return amp.AmpList.toStringProto(self, [inObject], proto)
@lvh
lvh / manhole.py
Created September 15, 2012 11:10
Manhole and Axiom demo
from axiom import attributes, item, store
import jinja2
import sys
from twisted.cred import checkers, portal
from twisted.conch import manhole, manhole_ssh
from twisted.internet import reactor
from twisted.python import log
from twisted.web import resource, server
def _immediateResponder(f):
"""
A decorator for responder functions that should return immediately and
execute asynchronously, as a defense against timing attacks.
The responder decorator should be applied after (above) this decorator::
@SomeCommand.responder
@_immediateResponder
def responder(...):
@lvh
lvh / release-procedure.txt
Last active December 19, 2015 18:29
Updated release procedure for Divmod
1. Check Jenkins builders.
2. Get the latest revision:
% bzr pull
3. Bump version number in <Package>/<package>/_version.py
4. Write release notes in <Package>/NEWS.txt. Add version number and date.
from json import dumps, loads
from twisted.internet.defer import inlineCallbacks
from twisted.protocols.basic import NetstringReceiver
from twisted.python import log
class JSONRPCReceiver(NetstringReceiver):
def stringReceived(self, string):
try:
request = loads(string)