Skip to content

Instantly share code, notes, and snippets.

View ambv's full-sized avatar
🐍
CPython Dev in Residence

Łukasz Langa ambv

🐍
CPython Dev in Residence
View GitHub Profile
import os
import re
import stat
import sys
if sys.version_info < (3, 1):
sys.stderr.write("Python 3.1+ required. Sorry.")
sys.exit(0)
READ_WRITE = re.compile(b"svn\+ssh://pythondev@svn\.python\.org")

Possible solutions

  • Implement escaping by the backslash character
    • advantages: elegant and predictable
    • disadvantages: even more backwards incompatible than the current patch
  • Make another list for the __init__ method with prefixes disallowed for inline comments
@ambv
ambv / map_reduce.py
Created November 29, 2011 21:16
Proper MapReduce in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" A response to http://terse-words.blogspot.com/2011/11/mapreduce-in-python.html """
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
@ambv
ambv / choices.rst
Created April 3, 2012 14:10
Upgrading the choices machinery for Django - a Django enhancement proposal

Upgrading the choices machinery for Django

Specifying choices for form fields and models currently does not do much justice to the DRY philosophy Django is famous for. Everybody seems to either have their own way of working around it or live with the suboptimal tuple-based pairs. This Django enhancement proposal presents a comprehensive solution based on an existing

@ambv
ambv / enable_offline.py
Last active November 14, 2016 19:44
Make `pip install --no-index -f $PIP_DOWNLOAD_CACHE SomePackage` work.
#!/usr/bin/env python
"""
enable_offline.py - symlink files in your PIP_DOWNLOAD_CACHE so that
``pip install --find-links`` picks them up.
Inspired by http://tartley.com/?p=1423
Usage
-----
@ambv
ambv / adapters.rst
Last active December 16, 2015 14:09
Adapter discovery in requests.Session

Look

Having:

>>> import requests
>>> s = requests.Session()

We cannot currently reliably do:

@ambv
ambv / state.py
Last active February 28, 2016 00:05
Stateful methods with PEP 443 single-dispatch generic functions.
from decimal import Decimal
from functools import singledispatch
#
# @singledispatch has to be moved inside __init__ to
# make registration work per instance.
#
class State:
def __init__(self):
@ambv
ambv / gist:ff0c793c050bbd701c7b
Created June 15, 2014 02:13
Steps to reproduce the Unicode bug
$ pip install testunicodepackagedependant
Downloading/unpacking testunicodepackagedependant
Downloading testunicodepackagedependant-1.0.tar.gz
Storing download in cache at /Users/ambv/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Ft%2Ftestunicodepackagedependant%2Ftestunicodepackagedependant-1.0.tar.gz
Running setup.py (path:/private/tmp/testestest/build/testunicodepackagedependant/setup.py) egg_info for package testunicodepackagedependant
Downloading/unpacking testunicodepackage==1.0 (from testunicodepackagedependant)
Downloading testunicodepackage-1.0.tar.gz
Cleaning up...
Exception:

Keybase proof

I hereby claim:

  • I am ambv on github.
  • I am ambv (https://keybase.io/ambv) on keybase.
  • I have a public key whose fingerprint is E3FF 2839 C048 B25C 084D EBE9 B269 95E3 1025 0568

To claim this, I am signing this object:

#!/usr/bin/env python3
"""Repacks entries in a ZIP file so that they become correctly zipimportable \
in Python 3.5. See https://bugs.python.org/issue25710 for details.
"""
import argparse
from pathlib import Path
import importlib._bootstrap_external
import sys