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 hashlib import md5 | |
| # Calculate response hash to authentication challenge | |
| def calc_auth_response(username, password, realm, nonce, digest_uri, method): | |
| ha1 = md5('%s:%s:%s' % (username, realm, password)).hexdigest() | |
| ha2 = md5('%s:%s' % (method, digest_uri)).hexdigest() | |
| response = md5('%s:%s:%s' % (ha1, nonce, ha2)).hexdigest() | |
| return response |
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
| # Derived from Singleton class by Dan Pascu on python-application package | |
| from new import instancemethod | |
| from weakref import WeakValueDictionary | |
| from application.python.decorator import preserve_signature | |
| class WeakSingleton(type): | |
| """ |
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
| <?php | |
| $host ='1.2.3.4'; | |
| $port = 25061; | |
| $timeout = 10; | |
| $cert = '/tmp/mediaproxy.pem'; | |
| $context = stream_context_create(array('ssl'=>array('local_cert'=> $cert,))); | |
| $fp = stream_socket_client('tcp://'.$host.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); | |
| if (!$fp) { | |
| echo "ERROR: $errno - $errstr\n"; | |
| } else { |
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
| server.modules += ( "mod_fastcgi" ) | |
| fastcgi.server = ( ".php" => | |
| ( "localhost" => | |
| ( | |
| "host" => "127.0.0.1", | |
| "port" => "9000" | |
| ) | |
| ) | |
| ) |
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
| # coding=utf8 | |
| # Copyright (C) 2011 Saúl Ibarra Corretgé <saghul@gmail.com> | |
| # | |
| __all__ = ['Database', 'DatabaseError'] | |
| from threading import Thread | |
| from sqlobject import connectionForURI, sqlhub, SQLObject, StringCol | |
| from twisted.internet import reactor | |
| from twisted.internet.threads import deferToThreadPool |
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
| pool = ThreadPool(minthreads=1, maxthreads=1, name='db-ops') | |
| pool.start() | |
| reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) |
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 run_in_db_thread(func): | |
| """Decorator to run DB queries in Twisted's thread pool""" | |
| def wrapper(*args, **kw): | |
| return deferToThreadPool(reactor, pool, func, *args, **kw) | |
| return wrapper |
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
| In [1]: class Foo(object): | |
| ...: def __init__(self, bar=[]): | |
| ...: self.bar = bar | |
| ...: | |
| ...: | |
| In [2]: f1 = Foo() | |
| In [3]: f2 = Foo() |
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
| In [1]: class Foo(object): | |
| ...: def __init__(self, bar=5): | |
| ...: self.bar = bar | |
| ...: | |
| ...: | |
| In [2]: f1 = Foo() | |
| In [3]: f2 = Foo() |
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
| In [1]: class Foo(object): | |
| ...: def __init__(self, bar=None): | |
| ...: self.bar = bar or [] | |
| ...: | |
| ...: | |
| In [2]: f1 = Foo() | |
| In [3]: f2 = Foo() |