This file contains 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
'--8banana133744910kmmr13a56!102!2405\r\nContent-Disposition: form-data; name="file_1"; filename="test_file1.txt"; Content-Type: application/octet-stream\r\n\r\nCompooper\r\n--8banana133744910kmmr13a56!102!2405--\r\n' |
This file contains 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
class LastLoopCacherNoFinal: | |
pass | |
class LastLoopCacher: | |
""" | |
An iterable context manager that stores the last value it loops as | |
an attribute, `final`. | |
Final falls out of scope upon exiting the context manager. |
This file contains 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 threading import BoundedSemaphore | |
from types import GeneratorType | |
from collections.abc import MappingView, Sequence | |
from functools import partial | |
_ALLOWED_SEQUENCE_TYPES = ( | |
Sequence, | |
MappingView, | |
GeneratorType |
This file contains 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 threading import BoundedSemaphore | |
from types import GeneratorType | |
from collections.abc import MappingView, Sequence | |
from functools import partial | |
_ALLOWED_SEQUENCE_TYPES = ( | |
Sequence, | |
MappingView, | |
GeneratorType |
This file contains 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 collections import OrderedDict | |
class OrderedDefaultDict(OrderedDict): | |
def __init__(self, default, *args, **kwargs): | |
# Your default must be callable. | |
self.default = default | |
super().__init__(*args, **kwargs) | |
def __missing__(self, key): | |
self[key] = value = self.default() |
This file contains 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 processor(burn=1): | |
def inner(gen): | |
def wrapper(*args, **kwargs): | |
g = gen(*args, **kwargs) | |
for _ in range(burn): | |
next(g) | |
return g | |
return wrapper | |
return inner |
This file contains 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
import socket | |
import time | |
from gzip import compress | |
def main(): | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
s.bind(('', 8000)) | |
s.listen(4) | |
while True: |
This file contains 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 itertools import cycle, islice | |
import pprint | |
# one cycle of the group | |
def increasing_cyclical(xs, period, max_width): | |
""" | |
Find the subcycles of an iterable given a depth and breadth. | |
period: the depth of the subcycle | |
max_width: the breadth of the subcycle | |
""" |
This file contains 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
['ascii', | |
'big5', | |
'big5hkscs', | |
'cp037', | |
'cp273', | |
'cp424', | |
'cp437', | |
'cp500', | |
'cp720', | |
'cp737', |
This file contains 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 that accepts a connection, spawns a client handler. Client handler | |
accepts a request, sends a 404, and kills the connection. Client should attempt | |
to reuse the connection, failing. Client should retry a new request, passing. | |
""" | |
import time | |
import socket | |
import h11 |