Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
Django-Redis-Cache
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shared
Django-Redis-Cache
Commits
3abc2eca
Commit
3abc2eca
authored
Jul 20, 2015
by
Sean Bleier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor class importing.
parent
22c233de
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
32 deletions
+24
-32
base.py
redis_cache/backends/base.py
+10
-32
utils.py
redis_cache/utils.py
+14
-0
No files found.
redis_cache/backends/base.py
View file @
3abc2eca
...
...
@@ -3,8 +3,6 @@ from django.core.exceptions import ImproperlyConfigured
from
django.utils
import
importlib
from
django.utils.importlib
import
import_module
from
redis_cache.compat
import
smart_bytes
,
DEFAULT_TIMEOUT
try
:
import
redis
except
ImportError
:
...
...
@@ -14,8 +12,11 @@ except ImportError:
from
redis.connection
import
DefaultParser
from
redis_cache.compat
import
smart_bytes
,
DEFAULT_TIMEOUT
from
redis_cache.connection
import
pool
from
redis_cache.utils
import
CacheKey
,
get_servers
,
parse_connection_kwargs
from
redis_cache.utils
import
(
CacheKey
,
get_servers
,
parse_connection_kwargs
,
import_class
)
from
functools
import
wraps
...
...
@@ -92,18 +93,10 @@ class BaseRedisCache(BaseCache):
return
self
.
params
.
get
(
'password'
,
self
.
options
.
get
(
'PASSWORD'
,
None
))
def
get_parser_class
(
self
):
cl
s
=
self
.
options
.
get
(
'PARSER_CLASS'
,
None
)
if
cl
s
is
None
:
parser_clas
s
=
self
.
options
.
get
(
'PARSER_CLASS'
,
None
)
if
parser_clas
s
is
None
:
return
DefaultParser
mod_path
,
cls_name
=
cls
.
rsplit
(
'.'
,
1
)
try
:
mod
=
importlib
.
import_module
(
mod_path
)
parser_class
=
getattr
(
mod
,
cls_name
)
except
AttributeError
:
raise
ImproperlyConfigured
(
"Could not find parser class '
%
s'"
%
parser_class
)
except
ImportError
as
ex
:
raise
ImproperlyConfigured
(
"Could not find module '
%
s'"
%
ex
)
return
parser_class
return
import_class
(
parser_class
)
def
get_pickle_version
(
self
):
"""
...
...
@@ -120,12 +113,7 @@ class BaseRedisCache(BaseCache):
def
get_connection_pool_class
(
self
):
pool_class
=
self
.
options
.
get
(
'CONNECTION_POOL_CLASS'
,
'redis.ConnectionPool'
)
module_name
,
class_name
=
pool_class
.
rsplit
(
'.'
,
1
)
module
=
import_module
(
module_name
)
try
:
return
getattr
(
module
,
class_name
)
except
AttributeError
:
raise
ImportError
(
'cannot import name
%
s'
%
class_name
)
return
import_class
(
pool_class
)
def
get_connection_pool_class_kwargs
(
self
):
return
self
.
options
.
get
(
'CONNECTION_POOL_CLASS_KWARGS'
,
{})
...
...
@@ -135,12 +123,7 @@ class BaseRedisCache(BaseCache):
'SERIALIZER_CLASS'
,
'redis_cache.serializers.PickleSerializer'
)
module_name
,
class_name
=
serializer_class
.
rsplit
(
'.'
,
1
)
module
=
import_module
(
module_name
)
try
:
return
getattr
(
module
,
class_name
)
except
AttributeError
:
raise
ImportError
(
'cannot import name
%
s'
%
class_name
)
return
import_class
(
serializer_class
)
def
get_serializer_class_kwargs
(
self
):
return
self
.
options
.
get
(
'SERIALIZER_CLASS_KWARGS'
,
{})
...
...
@@ -150,12 +133,7 @@ class BaseRedisCache(BaseCache):
'COMPRESSOR_CLASS'
,
'redis_cache.compressors.NoopCompressor'
)
module_name
,
class_name
=
compressor_class
.
rsplit
(
'.'
,
1
)
module
=
import_module
(
module_name
)
try
:
return
getattr
(
module
,
class_name
)
except
AttributeError
:
raise
ImportError
(
'cannot import name
%
s'
%
class_name
)
return
import_class
(
compressor_class
)
def
get_compressor_class_kwargs
(
self
):
return
self
.
options
.
get
(
'COMPRESSOR_CLASS_KWARGS'
,
{})
...
...
redis_cache/utils.py
View file @
3abc2eca
import
warnings
from
django.core.exceptions
import
ImproperlyConfigured
from
django.utils.importlib
import
import_module
from
redis.connection
import
SSLConnection
from
redis_cache.compat
import
(
...
...
@@ -49,6 +50,19 @@ def get_servers(location):
return
servers
def
import_class
(
path
):
module_name
,
class_name
=
path
.
rsplit
(
'.'
,
1
)
try
:
module
=
import_module
(
module_name
)
except
ImportError
:
raise
ImproperlyConfigured
(
'Could not find module "
%
s"'
%
module_name
)
else
:
try
:
return
getattr
(
module
,
class_name
)
except
AttributeError
:
raise
ImproperlyConfigured
(
'Cannot import "
%
s"'
%
class_name
)
def
parse_connection_kwargs
(
server
,
db
=
None
,
**
kwargs
):
"""
Return a connection pool configured from the given URL.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment