5454 memcache.client.set('foo', 'bar')
5555
5656"""
57+
5758from __future__ import absolute_import , division , print_function
5859import flask
5960import pymemcache .client
6061import pymemcache .client .hash
6162
6263
6364class FlaskPyMemcache (object ):
64-
6565 def __init__ (self , app = None , conf_key = None ):
6666 """
6767 :type app: flask.Flask
@@ -76,26 +76,29 @@ def init_app(self, app, conf_key=None):
7676 :type app: flask.Flask
7777 :parm str conf_key: Key of flask config.
7878 """
79- conf_key = conf_key or self .conf_key or ' PYMEMCACHE'
79+ conf_key = conf_key or self .conf_key or " PYMEMCACHE"
8080 self .conf_key = conf_key
8181 conf = app .config [conf_key ]
8282 if not isinstance (conf , dict ):
8383 raise TypeError ("Flask-PyMemcache conf should be dict" )
8484
85- close_on_teardown = conf .pop (' close_on_teardown' , False )
85+ close_on_teardown = conf .pop (" close_on_teardown" , False )
8686
87- if isinstance (conf [' server' ], list ):
88- conf [' servers' ] = conf .pop (' server' )
87+ if isinstance (conf [" server" ], list ):
88+ conf [" servers" ] = conf .pop (" server" )
8989 client = pymemcache .client .hash .HashClient (** conf )
90- elif isinstance (conf [' server' ], tuple ):
90+ elif isinstance (conf [" server" ], tuple ):
9191 client = pymemcache .client .Client (** conf )
9292 else :
93- raise TypeError ("Flask-PyMemcache conf['server'] should be tuple or list of tuples" )
93+ raise TypeError (
94+ "Flask-PyMemcache conf['server'] should be tuple or list of tuples"
95+ )
9496
95- app .extensions .setdefault (' pymemcache' , {})
96- app .extensions [' pymemcache' ][self ] = client
97+ app .extensions .setdefault (" pymemcache" , {})
98+ app .extensions [" pymemcache" ][self ] = client
9799
98100 if close_on_teardown :
101+
99102 @app .teardown_appcontext
100103 def close_connection (exc = None ):
101104 client .close ()
@@ -105,4 +108,4 @@ def client(self):
105108 """
106109 :rtype: pymemcache.client.Client
107110 """
108- return flask .current_app .extensions [' pymemcache' ][self ]
111+ return flask .current_app .extensions [" pymemcache" ][self ]
0 commit comments