#NEWLINE# def __init__( self , app , conf ) : #NEWLINE# #INDENT# self . app = app #NEWLINE# self . memcache_servers = conf . get ( 'memcache_servers' ) #NEWLINE# serialization_format = conf . get ( 'memcache_serialization_support' ) #NEWLINE# try : #NEWLINE# #INDENT# max_conns = int ( conf . get ( 'memcache_max_connections' , conf . get ( 'max_connections' , 0 ) ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# max_conns = 0 #NEWLINE# #UNINDENT# memcache_options = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( ( not self . memcache_servers ) or ( serialization_format is None ) or ( max_conns <= 0 ) ) : #NEWLINE# #INDENT# path = os . path . join ( conf . get ( 'swift_dir' , '/etc/swift' ) , 'memcache.conf' ) #NEWLINE# memcache_conf = ConfigParser ( ) #NEWLINE# if memcache_conf . read ( path ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# memcache_options = dict ( memcache_conf . items ( 'memcache' ) ) #NEWLINE# #UNINDENT# except NoSectionError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( not pool_timeout . memcache_servers ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . memcache_servers = memcache_conf . get ( 'memcache' , 'memcache_servers' ) #NEWLINE# #UNINDENT# except ( NoSectionError , NoOptionError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( serialization_format is None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# serialization_format = memcache_conf . get ( 'memcache' , 'memcache_serialization_support' ) #NEWLINE# #UNINDENT# except ( NoSectionError , NoOptionError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( max_conns <= 0 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# new_max_conns = memcache_conf . get ( 'memcache' , 'memcache_max_connections' ) #NEWLINE# max_conns = int ( new_max_conns ) #NEWLINE# #UNINDENT# except ( NoSectionError , NoOptionError , ValueError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# memcache_options . update ( conf ) #NEWLINE# connect_timeout = float ( memcache_options . get ( 'connect_timeout' , CONN_TIMEOUT ) ) #NEWLINE# pool_timeout = float ( memcache_options . get ( 'pool_timeout' , POOL_TIMEOUT ) ) #NEWLINE# tries = int ( memcache_options . get ( 'tries' , TRY_COUNT ) ) #NEWLINE# io_timeout = float ( memcache_options . get ( 'io_timeout' , IO_TIMEOUT ) ) #NEWLINE# if ( not self . memcache_servers ) : #NEWLINE# #INDENT# self . memcache_servers = '127.0.0.1:11211' #NEWLINE# #UNINDENT# if ( max_conns <= 0 ) : #NEWLINE# #INDENT# max_conns = 2 #NEWLINE# #UNINDENT# if ( serialization_format is None ) : #NEWLINE# #INDENT# serialization_format = 2 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# serialization_format = int ( serialization_format ) #NEWLINE# #UNINDENT# self . memcache = MemcacheRing ( [ s . strip ( ) for s in self . memcache_servers . split ( ',' ) if s . strip ( ) ] , connect_timeout = connect_timeout , pool_timeout = pool_timeout , tries = tries , io_timeout = io_timeout , allow_pickle = ( serialization_format == 0 ) , allow_unpickle = ( serialization_format <= 1 ) , max_conns = max_conns )