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 os | |
import sys | |
def taskexists(pid): | |
if sys.platform == "win32": | |
import ctypes | |
import win32con | |
h = ctypes.windll.kernel32.OpenProcess(win32con.PROCESS_ALL_ACCESS, False, pid) | |
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 sqlalchemy import Column, Integer, String, MetaData | |
from sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base() | |
class User(Base): | |
__tablename__ = 'users' | |
id = Column(Integer, primary_key=True) | |
name = Column(String) | |
fullname = Column(String) |
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 panglery | |
class Base(object): | |
p = panglery.PanglerAggregate('hooks') | |
def __init__(self): | |
self.attr = True | |
class Plugin(Base): | |
hooks = panglery.Pangler() |
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
# before | |
# In plugin manager: | |
def register_trigger(self, func, *events): | |
for event in events: | |
self.triggers[event.upper()].append(func) | |
# In plugin: | |
def initialize(self, *args, **kwargs): | |
manager.register_trigger(self.on_welcome, "IRC_RPL_WELCOME") |
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 collections import defaultdict | |
class Manager(object): | |
def __init__(self): | |
self.strings = defaultdict(list) # { stringname: [func1, func2, ...], ... } | |
def deco(self, string): | |
def decofunc(func): | |
self.strings[string].append(func) | |
return func |
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 hashlib | |
class Klass(object): | |
def func(self): | |
"""Ohai from Klass.func""" | |
print self.func.__doc__ | |
def Func(): | |
"""Ohai from __main__.Func""" | |
print Func.__doc__ |
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 hashlib | |
class User(object): | |
def __init__(self): | |
self.password = "" | |
def set_password(self, raw_password): | |
hash = "pass" # randomly generate this | |
m = hashlib.sha1(raw_password + hash) | |
self.password = "%s$%s" % (m.hexdigest(), hash) | |
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
# The only requirements are that the process ends with a specific return code (7 in this case) | |
import os | |
import sys | |
import subprocess | |
class main(object): | |
def __init__(self, file, cwd): | |
self.file = os.path.abspath(file) | |
self.cwd = os.path.abspath(cwd) |
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
d = defer.maybeDeferred(func, self, user, channel, msg) | |
d.addErrback(self.printerror) | |
d.addCallback(self.msg, channel) | |
def msg(self, user, message): | |
pass | |
# user ends up having the message, and message the target. |
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 BotFactory(protocol.ReconnectingClientFactory): | |
protocol = Bot | |
def __init__(self, config, name, state): | |
self.config = config | |
self.name = name | |
self.sharedstate = state | |
self.quitted = False | |
def clientConnectionLost(self, connector, unused_reason): |