Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
migrate apps/amo/utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
eviljeff committed Dec 31, 2014
1 parent 356c6da commit beb0c32
Show file tree
Hide file tree
Showing 80 changed files with 954 additions and 1,179 deletions.
60 changes: 0 additions & 60 deletions apps/amo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import threading

import commonware.log
from caching.base import CachingQuerySet

from mkt.constants.applications import *
from mkt.constants.base import *
Expand All @@ -31,65 +30,6 @@ def set_user(user):
_locals.user = user


def cached_property(*args, **kw):
# Handles invocation as a direct decorator or
# with intermediate keyword arguments.
if args: # @cached_property
return CachedProperty(args[0])
else: # @cached_property(name=..., writable=...)
return lambda f: CachedProperty(f, **kw)


class CachedProperty(object):
"""
A decorator that converts a function into a lazy property. The
function wrapped is called the first time to retrieve the result
and than that calculated result is used the next time you access
the value::
class Foo(object):
@cached_property
def foo(self):
# calculate something important here
return 42
Lifted from werkzeug.
"""

def __init__(self, func, name=None, doc=None, writable=False):
self.func = func
self.writable = writable
self.__name__ = name or func.__name__
self.__doc__ = doc or func.__doc__

def __get__(self, obj, type=None):
if obj is None:
return self
_missing = object()
value = obj.__dict__.get(self.__name__, _missing)
if value is _missing:
value = self.func(obj)
if isinstance(value, CachingQuerySet):
# Work around a bug in django-cache-machine that
# causes deadlock or infinite recursion if
# CachingQuerySets are cached before they run their
# query.
value._fetch_all()
obj.__dict__[self.__name__] = value
return value

def __set__(self, obj, value):
if not self.writable:
raise TypeError('read only attribute')
obj.__dict__[self.__name__] = value

def __delete__(self, obj):
if not self.writable:
raise TypeError('read only attribute')
del obj.__dict__[self.__name__]


# We need to import waffle here to avoid a circular import with jingo which
# loads all INSTALLED_APPS looking for helpers.py files, but some of those apps
# import jingo.
Expand Down
128 changes: 0 additions & 128 deletions apps/amo/tests/ospatch.py

This file was deleted.

0 comments on commit beb0c32

Please sign in to comment.