by topic • Give you ideas you might not have had. • If you have questions: SHOUT and interrupt me :-) • All slides are available for download: • http://lucumr.pocoo.org/talks/
[] while 1: if len(buffer) > 1: yield buffer.pop() continue chunks = chunk_iter.next().splitlines(True) chunks.reverse() first_chunk = buffer and buffer[0] or '' if chunks: if first_chunk.endswith('\n') or first_chunk.endswith('\r'): yield first_chunk first_chunk = '' first_chunk += chunks.pop() if not first_chunk: return buffer = chunks yield first_chunk
def __init__(self, func): self.func = func self.__name__ = func.__name__ self.__doc__ = func.__doc__ self.__module__ = func.__module__ def __get__(self, obj, type=None): if obj is None: return self value = obj.__dict__.get(self.__name__, missing) if value is missing: value = self.func(obj) obj.__dict__[self.__name__] = value return value
__init__(self, headers): self._headers = headers def __getitem__(self, key): ikey = key.lower() for key, value in self._headers: if key.lower() == ikey: return value raise KeyError(key) def __len__(self): return len(self._headers) def __iter__(self): return (key for key, value in self._headers)