-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#5): remove django from project
- Loading branch information
sepgh
committed
Oct 31, 2023
1 parent
1c3e30e
commit c042bc4
Showing
15 changed files
with
114 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
Django==4.2 | ||
pre-commit |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import operator | ||
|
||
|
||
class LazyObject: | ||
|
||
_wrapped = None | ||
_is_init = False | ||
|
||
def __init__(self, factory): | ||
# Assign using __dict__ to avoid the setattr method. | ||
self.__dict__["_factory"] = factory | ||
|
||
def _setup(self): | ||
self._wrapped = self._factory() | ||
self._is_init = True | ||
|
||
def new_method_proxy(func): | ||
""" | ||
Util function to help us route functions | ||
to the nested object. | ||
""" | ||
|
||
def inner(self, *args): | ||
if not self._is_init: | ||
self._setup() | ||
return func(self._wrapped, *args) | ||
|
||
return inner | ||
|
||
def __setattr__(self, name, value): | ||
# These are special names that are on the LazyObject. | ||
# every other attribute should be on the wrapped object. | ||
if name in {"_is_init", "_wrapped"}: | ||
self.__dict__[name] = value | ||
else: | ||
if not self._is_init: | ||
self._setup() | ||
setattr(self._wrapped, name, value) | ||
|
||
def __delattr__(self, name): | ||
if name == "_wrapped": | ||
raise TypeError("can't delete _wrapped.") | ||
if not self._is_init: | ||
self._setup() | ||
delattr(self._wrapped, name) | ||
|
||
__getattr__ = new_method_proxy(getattr) | ||
__bytes__ = new_method_proxy(bytes) | ||
__str__ = new_method_proxy(str) | ||
__bool__ = new_method_proxy(bool) | ||
__dir__ = new_method_proxy(dir) | ||
__hash__ = new_method_proxy(hash) | ||
__class__ = property(new_method_proxy(operator.attrgetter("__class__"))) | ||
__eq__ = new_method_proxy(operator.eq) | ||
__lt__ = new_method_proxy(operator.lt) | ||
__gt__ = new_method_proxy(operator.gt) | ||
__ne__ = new_method_proxy(operator.ne) | ||
__hash__ = new_method_proxy(hash) | ||
__getitem__ = new_method_proxy(operator.getitem) | ||
__setitem__ = new_method_proxy(operator.setitem) | ||
__delitem__ = new_method_proxy(operator.delitem) | ||
__iter__ = new_method_proxy(iter) | ||
__len__ = new_method_proxy(len) | ||
__contains__ = new_method_proxy(operator.contains) |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Oops, something went wrong.