@@ -65,63 +65,41 @@ def __init__(self, uri='http://127.0.0.1:8270', timeout=None):
65
65
timeout = timestr_to_secs (timeout )
66
66
self ._uri = uri
67
67
self ._client = XmlRpcRemoteClient (uri , timeout )
68
- self ._kw_cache = None
69
-
70
- def _cached (info_type = None , default = None ):
71
- def decorator (f ):
72
- @wraps (f )
73
- def wrapper (self , name = None ):
74
- if self ._kw_cache :
75
- return self ._kw_cache .get (info_type , dict ()).get (name , default )
76
- else :
77
- try :
78
- return f (self , name )
79
- except TypeError :
80
- return default
81
- return wrapper
82
- return decorator
83
-
84
- def _build_kw_info_cache (self ):
85
- """
86
- Single attempt to build the cache using get_library_information interface
87
- cache structure:
88
- { "keyword_name" : { 'args':[], 'tags':[], 'doc':"", 'types':[]},
89
- "kw2" : {...}, etc. }
90
- """
91
- try :
92
- self ._kw_cache = self ._client .get_library_information ()
93
- self ._kw_cache ['__intro__' ] = dict (
94
- doc = self ._client .get_keyword_documentation ('__intro__' ))
95
- self ._kw_cache ['__init__' ] = dict (
96
- doc = self ._client .get_keyword_documentation ('__init__' ))
97
- except TypeError :
98
- pass # Best effort failed, fall back to regular loading
68
+ self ._lib_info = None
99
69
100
70
def get_keyword_names (self ):
101
- self ._build_kw_info_cache ()
102
- if self ._kw_cache :
103
- return self ._kw_cache .keys ()
71
+ try :
72
+ self ._lib_info = self ._client .get_library_information ()
73
+ except TypeError :
74
+ pass
75
+ else :
76
+ return self ._lib_info .keys ()
104
77
try :
105
78
return self ._client .get_keyword_names ()
106
79
except TypeError as error :
107
80
raise RuntimeError ('Connecting remote server at %s failed: %s'
108
81
% (self ._uri , error ))
109
82
110
- @_cached ('args' , default = ['*args' ])
111
83
def get_keyword_arguments (self , name ):
112
- return self ._client .get_keyword_arguments (name )
84
+ return self ._get_kw_info (name , 'args' , self ._client .get_keyword_arguments ,
85
+ default = ['*args' ])
86
+
87
+ def _get_kw_info (self , kw , info , getter , default = None ):
88
+ if self ._lib_info is not None :
89
+ return self ._lib_info [kw ].get (info , default )
90
+ try :
91
+ return getter (kw )
92
+ except TypeError :
93
+ return default
113
94
114
- @_cached ('types' )
115
95
def get_keyword_types (self , name ):
116
- return self ._client .get_keyword_types ( name )
96
+ return self ._get_kw_info ( name , 'types' , self . _client .get_keyword_types )
117
97
118
- @_cached ('tags' )
119
98
def get_keyword_tags (self , name ):
120
- return self ._client .get_keyword_tags ( name )
99
+ return self ._get_kw_info ( name , 'tags' , self . _client .get_keyword_tags )
121
100
122
- @_cached ('doc' )
123
101
def get_keyword_documentation (self , name ):
124
- return self ._client .get_keyword_documentation ( name )
102
+ return self ._get_kw_info ( name , 'doc' , self . _client .get_keyword_documentation )
125
103
126
104
def run_keyword (self , name , args , kwargs ):
127
105
coercer = ArgumentCoercer ()
@@ -258,7 +236,7 @@ def get_library_information(self):
258
236
def get_keyword_names (self ):
259
237
with self ._server as server :
260
238
return server .get_keyword_names ()
261
-
239
+
262
240
def get_keyword_arguments (self , name ):
263
241
with self ._server as server :
264
242
return server .get_keyword_arguments (name )
0 commit comments