Skip to content

Instantly share code, notes, and snippets.

class TimeoutContext(object):
u"""
Контекст устанавливающий таймаут на операции с сокетами
>>> with TimeoutContext(14.88):
... urlopen('http://google.com').read()
Traceback (most recent call last)
...
timeout: timed out
"""
threads = self.get_queryset().order_by('-update_time')
thread_container = []
for thread in threads:
posts = thread.posts.all()[:3]
item = dict(thread=thread, posts=posts)
thread_container.append(item)
class BaseBoardClass(ListView):
model = models.Board
def get_context_data(self, board_name):
context = super(BaseBoardClass,self).get_context_data(**kwargs)
board = get_object_or_404(models.Board.objects,name=board_name) if board_name or None
context['board'] = bord
return context
@insanemainframe
insanemainframe / gist:7914542
Created December 11, 2013 17:15
scrapy bug
from scrapy.contrib.loader.processor import Compose
from operator import itemgetter
Compose(itemgetter(0))('a')
...
RuntimeError: maximum recursion depth exceeded while calling a Python object