Skip to content

Instantly share code, notes, and snippets.

View lqc's full-sized avatar

Łukasz Rekucki lqc

  • Syncron
  • Warsaw, Poland
View GitHub Profile
@lqc
lqc / ftpclient.py
Created July 17, 2011 18:49
Some random program from pl.python.org I'm reviewing ;)
# Klient FTP
# Napisany przez Sherifa, na licencji Open Source
# importuje biblioteke
import ftplib
# Chyba widac...
print "=======================\n"
print "====== FTP Klient =====\n"
print "=======================\n"
from ConfigParser import RawConfigParser, NoOptionError
class SectionProxy(object):
__slots__ = ('_section_name', '_config')
def __init__(self, config, section_name):
self._section_name = section_name
self._config = config
def __getattr__(self, name):
from ConfigParser import RawConfigParser, NoOptionError
class SectionProxy(object):
__slots__ = ('_section_name', '_config')
def __init__(self, config, section_name):
self._section_name = section_name
self._config = config
def __getattr__(self, name):
class Base(object):
def foo(self):
return "foo"
class FaultyClass(Base):
def foo(self):
return "faulty-" + Base.foo(self)
@login_required
def personal_items(request, **kwargs):
qs = kwargs['queryset']
qs = qs.filter(author=request.user)
# i inne filtry...
kwargs['queryset'] = qs
return django.views.generic.list_detail.object_list(request, **kwargs)
# -*- coding: utf-8
hrum = True # "hrum" to niezbyt dobra nazwa zmiennej
while hrum:
try:
option = int(raw_input("Menu:\n0.Zakoncz\n1.Sciagniecie witryny przez http\n2.Sciagniecie pliku\n3.Pobranie pliku z ftp\n"))
except ValueError:
continue
if option == 0:
@lqc
lqc / kwars_decorator.py
Created December 20, 2010 22:43
Decorator to create well-behaving decorators :)
def decorator_with_kwargs(decorator):
"""
There are many techniques to produce decorators that can be used with
arguments and without them. Accepting only keyword arguments is the simples, IMHO.
>>> def execution_decorator(view, opts):
... return view(**opts)
...
>>> def format_kwargs(**kwargs):
... return "ARGS: %r" % kwargs
# from django.conf import settings
from functools import wraps
class _s:
def __init__(self, a=10, b=None):
self.a, self.b = a,b
def _override_settings(overrides):
_orig = {}
_missing = []
@lqc
lqc / gist:643536
Created October 24, 2010 13:32
Python 2.x super() is broken :(
class A(object):
def method(self):
return "A"
class B(A):
def method(self):
return "B" + super(B, self).method()
class C(B):
pass

Mixins

  • A ton of Mixins look really reusable, but do we really need all of them (or any of them).
    • Does is makes sense to have ProcessFormView and DisplayFormView ? Maybe this should be one view (having both functions is the common case) and people can prevent display/process by subclassing.
    • Most view's MRO looks like this: FooBarView, MixinA, MixinB, ..., TemplateMixin, View. If I wanted an almost exactly same view, but a one that uses diffrent template system (or a JSON serializer), I have to either create