5151::
5252
5353 memcache.client.set('foo', 'bar')
54-
5554"""
5655
56+ from __future__ import annotations
57+
5758import flask
58- import pymemcache .client
59- import pymemcache .client .hash
59+ import pymemcache
6060
6161
6262class FlaskPyMemcache :
63- def __init__ (self , app = None , conf_key = None ) :
63+ def __init__ (self , app = None , conf_key = None , client_class = None ) -> None :
6464 """
6565 :type app: flask.Flask
6666 :parm str conf_key: Key of flask config.
6767 """
6868 self .conf_key = conf_key
6969 if app is not None :
70- self .init_app (app , conf_key )
70+ self .init_app (app , conf_key , client_class )
7171
72- def init_app (self , app , conf_key = None ) :
72+ def init_app (self , app , conf_key = None , client_class = None ) -> None :
7373 """
7474 :type app: flask.Flask
7575 :parm str conf_key: Key of flask config.
@@ -84,9 +84,9 @@ def init_app(self, app, conf_key=None):
8484
8585 if isinstance (conf ["server" ], list ):
8686 conf ["servers" ] = conf .pop ("server" )
87- client = pymemcache .client . hash . HashClient (** conf )
87+ client = ( client_class or pymemcache .HashClient ) (** conf )
8888 elif isinstance (conf ["server" ], tuple ):
89- client = pymemcache .client . Client (** conf )
89+ client = ( client_class or pymemcache .Client ) (** conf )
9090 else :
9191 raise TypeError (
9292 "Flask-PyMemcache conf['server'] should be tuple or list of tuples"
@@ -102,8 +102,5 @@ def close_connection(exc=None):
102102 client .close ()
103103
104104 @property
105- def client (self ):
106- """
107- :rtype: pymemcache.client.Client
108- """
105+ def client (self ) -> pymemcache .Client :
109106 return flask .current_app .extensions ["pymemcache" ][self ]
0 commit comments