Skip to content

Instantly share code, notes, and snippets.

@rbarrois
rbarrois / gist:3721801
Created September 14, 2012 13:05
Well behaving HTTP transport for suds
from suds.transport.http import HttpTransport as SudsHttpTransport
class WellBehavedHttpTransport(SudsHttpTransport):
"""HttpTransport which properly obeys the ``*_proxy`` environment variables."""
def u2handlers(self):
"""Return a list of specific handlers to add.
The urllib2 logic regarding ``build_opener(*handlers)`` is:
@rbarrois
rbarrois / mock_datetime.py
Created April 21, 2013 20:18
Proper module for patching datetime.datetime.now().
# This code is in the public domain
# Author: Raphaël Barrois
from __future__ import print_function
import datetime
import mock
@rbarrois
rbarrois / settings.py
Created September 29, 2013 20:58
Helper to get pretty (?) exceptions in Django templates for invalid variable names.
class InvalidStringHandler(object):
"""Custom handler for invalid string in templates."""
def __call__(self):
"""Force crashes in {{ foo|sth }}, without breaking __str__."""
import ipdb; ipdb.set_trace()
raise ValueError()
def __nonzero__(self):
"""So that '{% if foo %}' doesn't break."""
@rbarrois
rbarrois / test_lcd.py
Created September 7, 2014 22:22
Small test tool for mpdlcd / LCDd charset
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
import socket
import sys
DEFAULT_LCDD_CHARSET = 'utf-8'
@rbarrois
rbarrois / my_factory.py
Created February 6, 2015 20:30
WIP: API for factory_boy / SQLAlchemy's session
import factory
import factory.alchemy
import my_tests
import my_models
class MyFactory(factory.alchemy.SQLAlchemyFactory):
class Meta:
sqlalchemy_session_loader = my_tests.session_loader
model = my_models.Model
@rbarrois
rbarrois / fixed.py
Last active February 27, 2017 12:57
Support sur #python-fr, 20170227
# Pas besoin de point-virgule
import os;
# Utilise open("gaumont.generate.txt", 'w') à la place ; ici tu supprimes le fichier puis l'ouvres en mode "ajout à la fin",
# autant l'ouvrir directement en mode "remplacement"
os.remove("gaumont.generate.txt");
FILE = open("gaumont.generate.txt", "a+");
print("=========================");
print(" GAUMONT GENERATOR BY TCHOTCHO");
@rbarrois
rbarrois / wsgi.py
Created May 25, 2018 13:46
Django uWSGI warmup
# -*- coding: utf-8 -*-
import io
import os
import sys
import time
import wsgiref.util
import uwsgidecorators