Skip to content

Instantly share code, notes, and snippets.

View xordoquy's full-sized avatar

Xavier Ordoquy xordoquy

  • Paris, France
View GitHub Profile
>>> import json
>>> json.dumps({1: b'\xd1\x88\xd1\x82'})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/json/__init__.py", line 226, in dumps
return _default_encoder.encode(obj)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/json/encoder.py", line 188, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/json/encoder.py", line 246, in iterencode
return _iterencode(o, 0)
MacBook-Air-de-Xavier:tmp xordoquy$ mkvirtualenv
mkvirtualenv mkvirtualenv_help
MacBook-Air-de-Xavier:tmp xordoquy$ mkvirtualenv test
New python executable in test/bin/python
Installing setuptools.............done.
Installing pip...............done.
(test)MacBook-Air-de-Xavier:tmp xordoquy$ pip install -r req.txt
Downloading/unpacking numpy (from -r req.txt (line 1))
Downloading numpy-1.7.1.zip (3.1Mb): 3.1Mb downloaded
Storing download in cache at /Users/xordoquy/.pip/cache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fn%2Fnumpy%2Fnumpy-1.7.1.zip
OGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
},
'console': {
'level': 'DEBUG',
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('url', 'username', 'snippets')
class SnippetViewSet(viewsets.ModelViewSet):
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly)
@xordoquy
xordoquy / gist:8296853
Created January 7, 2014 09:22
This is a transport layer in order to make xmlrpc work with any proxy type thanks to the requests library
class RequestTransport(xmlrpclib.Transport, object):
def __init__(self, use_datetime=0, proxies=None):
super(RequestTransport, self).__init__(use_datetime)
self.session = requests.Session()
self.configure_requests(proxies=proxies)
def configure_requests(self, proxies=None):
self.session.headers.update({
'Content-Type': 'text/xml',
import unittest
class MetaTest(type):
def __new__(cls, name, bases, attrs):
for k, v in attrs['generation_data'].items():
def test_function(self):
self.assertTrue(v[0]**2, v[1])
attrs['test_%s' % k] = test_function
return super(MetaTest, cls).__new__(cls, name, bases, attrs)
def post(self, request, format=None):
serializer = self.get_serializer(data=request.DATA, files=request.FILES)
if serializer.is_valid():
some_function_to_save(serializer.object)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
# settings for an application:
from django.conf import settings
SOME_ATTR = getattr(settings, 'APP_SOME_ATTR', 'Default value')
location ~ /\+f/ {
try_files /+files$uri @proxy_to_app;
}
location ~ /\+f/ {
internal;
root /path/+files$uri;
try_files /+files$uri @proxy_to_app;
result = []
for i in range(5):
def f():
print(i)
result.append(f)
for f in result:
f()