This file contains hidden or 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 django.core.management.base import BaseCommand, CommandError | |
from django.db.models.loading import get_apps | |
from django.conf import settings | |
import simpledb | |
class Command(BaseCommand): | |
help = ("Sync all of the SimpleDB domains.") | |
def handle(self, *args, **options): |
This file contains hidden or 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 FriendDescriptor(object): | |
""" | |
A descriptor that provides access to a user's friends. | |
""" | |
def __get__(self, instance, cls): | |
if not instance: | |
raise AttributeError('Manager must be accessed via instance') | |
Relationship = get_model('friends', 'Relationship') |
This file contains hidden or 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 FollowerDescriptor(object): | |
""" | |
A descriptor which provides access to a user's followers. | |
""" | |
def __get__(self, instance, cls): | |
if not instance: | |
raise AttributeError('Manager must be accessed via instance') | |
class RelationshipManager(models.Manager): | |
def get_query_set(self): |
This file contains hidden or 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 Model(object): | |
keyspace = None | |
column_family = None | |
key = None | |
data = {} | |
required = [] | |
modified = False | |
def __init__(self, **kwargs): | |
if self.key in kwargs and len(kwargs) == 1: |
This file contains hidden or 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 datetime | |
from django.db import models | |
class Frob(models.Model): | |
name = models.CharField(max_length=255) | |
created = models.DateTimeField(default=datetime.datetime.now) | |
class Fritz(models.Model): | |
age = models.IntegerField(default=5) |
This file contains hidden or 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
""" | |
Some simple utilities to read the magic bytes from the beginning of a | |
file and determine whether the file meets certain criteria (e.g., contains | |
JPEG image data). | |
""" | |
import array | |
from operator import eq | |
IMAGE_MAGIC_DATA = ( |
This file contains hidden or 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 django.core.paginator import ObjectPaginator | |
class QuickObjectPaginator(ObjectPaginator): | |
max_safe_pages = 0 | |
def __init__(self, object_list, per_page, orphans=0, max_safe_pages=0): | |
self.max_safe_pages = max_safe_pages | |
super(QuickObjectPaginator, self).__init__(object_list, per_page, orphans) | |
def validate_page_number(self, page_number): |
This file contains hidden or 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 pstats | |
>>> p = pstats.Stats('p.1258156459.52174278XcQE.prof') | |
>>> p.strip_dirs().sort_stats(-1).print_stats(5) | |
Fri Nov 13 15:54:20 2009 p.1258156459.52174278XcQE.prof | |
124278 function calls (122386 primitive calls) in 0.589 CPU seconds | |
Ordered by: standard name | |
List reduced from 1014 to 5 due to restriction <5> |
This file contains hidden or 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
"Memcached cache backend" | |
from django.core.cache.backends import memcached | |
from django.utils.encoding import smart_unicode, smart_str | |
MIN_COMPRESS_LEN = 150000 | |
class CacheClass(memcached.CacheClass): | |
def add(self, key, value, timeout=None, min_compress_len=MIN_COMPRESS_LEN): | |
if isinstance(value, unicode): |
This file contains hidden or 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
/** | |
* Reads from the | |
* stream <code>in</code> a representation | |
* of a Unicode character string encoded in | |
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format; | |
* this string of characters is then returned as a <code>String</code>. | |
* The details of the modified UTF-8 representation | |
* are exactly the same as for the <code>readUTF</code> | |
* method of <code>DataInput</code>. | |
* |