Skip to content

Instantly share code, notes, and snippets.

View GrahamDumpleton's full-sized avatar
😎

Graham Dumpleton GrahamDumpleton

😎
View GitHub Profile
@GrahamDumpleton
GrahamDumpleton / gist:01d962cb085c28184819
Created August 25, 2015 00:37
Qualified name of function being executed.
# Can't get class via stack frame as only have access to code object and not what type it may have been bound to if a function.
>>> def func():
... print sys._getframe().f_code.co_name
...
>>> func()
func
>>> class A(object):
... def method(self):
... print sys._getframe().f_code.co_name
@GrahamDumpleton
GrahamDumpleton / gist:6be06d259a166d69bf8c
Last active August 29, 2015 14:23
Exporting functions and variables from a module.
# exports.py
import sys
class Exports(object):
def __getattr__(self, name):
context = sys._getframe().f_back.f_globals
return context[name]
@GrahamDumpleton
GrahamDumpleton / gist:b79d336569054882679e
Last active January 10, 2020 22:05
Running HTTPS and client authentication with mod_wsgi-express.

Note that for client authentication the very latest mod_wsgi-express version is required.

For now this means installing from from the git repo. To install run:

pip install -U https://github.com/GrahamDumpleton/mod_wsgi/archive/develop.zip

To create a self signed server certificate so that can run HTTPS use:

@GrahamDumpleton
GrahamDumpleton / gist:b380652b768e81a7f60c
Last active May 18, 2024 03:35
Setting environment variables for Apache/mod_wsgi hosted Python application.

Django documentation says to use:

WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com

<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
@GrahamDumpleton
GrahamDumpleton / gist:dca226dcb67518a9454a
Last active August 29, 2015 14:08
Delegate only sub URL to embedded mode.
# This is example configuration of how a specific sub URL of a Python
# web application can be delegated to run in mod_wsgi embedded mode
# where the remainder of the site is delegated to run in mod_wsgi
# daemon mode.
#
# The particular example in this case is to work around the current
# issue that the optional enabling of non WSGI handling of chunked
# request content doesn't work for mod_wsgi daemon mode. A fix for
# that has been developed but hasn't yet been released. As Linux
# distributions ship older mod_wsgi versions and do not update them,
@GrahamDumpleton
GrahamDumpleton / gist:10609688
Last active August 29, 2015 13:59
Delay decorator action until class instantiation to allow access to class variable.
class Router(object):
def __init__(self):
self.methods = {}
def route(self, url):
def decorator(wrapped):
wrapped.__route_info__ = (self, url)
return wrapped
return decorator
def register(self, url, method):
self.methods[url] = method
@GrahamDumpleton
GrahamDumpleton / gist:8553894
Created January 22, 2014 05:29
The callable() function doesn't respect when __call__ is a descriptor.
class Wrapper(object):
def __init__(self, wrapped):
self.__wrapped__ = wrapped
@property
def __call__(self):
return self.__wrapped__.__call__
>>> wrapper = Wrapper(None)
@GrahamDumpleton
GrahamDumpleton / gist:7671860
Created November 27, 2013 07:22
Strange warning logged by pypy.
Exception AssertionError: AssertionError() in interrupting generator of <generator object __iter__ at 0x0000000107c489f8> ignored
@GrahamDumpleton
GrahamDumpleton / gist:7348692
Created November 7, 2013 03:51
Why list(six.iteritems(d)) is bad.
>>> d = { "a": "b" }
>>> i = iter(d.iteritems())
>>> i
<dictionary-itemiterator object at 0x1072d8cb0>
>>> d["c"] = "d"
>>> list(i)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration
@GrahamDumpleton
GrahamDumpleton / gist:6694421
Last active December 23, 2015 21:09
PASS/FAIL matrix for various requests module versions and proxy SSL request via Squid.

Squid configuration:

http_port 3128
https_port 3129 cert=/usr/local/opt/squid/etc/ssl/squid.crt key=/usr/local/opt/squid/etc/ssl/squid.key

Test names:

The 'http_port' annotation indicates whether Squid HTTP port was used.

The 'https_port' annotation indicates whether Squid HTTPS port was used.