@@ -147,12 +147,12 @@ def remote_detailled_methods():
147
147
r = [(name + (inspect .formatargspec (* argspec )
148
148
if argspec else '(...)' ), doc )
149
149
for name , argspec , doc in remote_detailled_methods ()]
150
- longest_name_len = max (len (name ) for name , doc in r )
150
+ longest_name_len = max (len (name ) for name , doc in r ) if r else 0
151
151
return (longest_name_len , r )
152
152
153
153
154
154
# handle the 'python formatted' _zerorpc_inspect, that return the output of
155
- # "getargspec" from the python lib "inspect".
155
+ # "getargspec" from the python lib "inspect". A monstruosity from protocol v2.
156
156
def zerorpc_inspect_python_argspecs (remote_methods , filter_method , long_doc , include_argspec ):
157
157
def format_method (name , argspec , doc ):
158
158
if include_argspec :
@@ -165,10 +165,13 @@ def format_method(name, argspec, doc):
165
165
return (name , doc )
166
166
r = [format_method (* methods_info ) for methods_info in remote_methods if
167
167
filter_method is None or methods_info [0 ] == filter_method ]
168
- longest_name_len = max (len (name ) for name , doc in r )
168
+ if not r :
169
+ return None
170
+ longest_name_len = max (len (name ) for name , doc in r ) if r else 0
169
171
return (longest_name_len , r )
170
172
171
173
174
+ # Handles generically formatted arguments (not tied to any specific programming language).
172
175
def zerorpc_inspect_generic (remote_methods , filter_method , long_doc , include_argspec ):
173
176
def format_method (name , args , doc ):
174
177
if include_argspec :
@@ -178,37 +181,53 @@ def format_arg(arg):
178
181
return arg ['name' ]
179
182
return '{0}={1}' .format (arg ['name' ], def_val )
180
183
181
- name += '({0})' .format (', ' .join (map (format_arg , args )))
184
+ if args :
185
+ name += '({0})' .format (', ' .join (map (format_arg , args )))
186
+ else :
187
+ name += '(??)'
188
+
182
189
if not doc :
183
190
doc = '<undocumented>'
184
191
elif not long_doc :
185
192
doc = doc .splitlines ()[0 ]
186
193
return (name , doc )
187
194
188
- methods = [format_method (name , details ['args' ], details ['doc' ]) for name , details in remote_methods .items ()
195
+ methods = [format_method (name , details ['args' ], details ['doc' ])
196
+ for name , details in remote_methods .items ()
189
197
if filter_method is None or name == filter_method ]
190
198
191
- longest_name_len = max (len (name ) for name , doc in methods )
199
+ longest_name_len = (max (len (name ) for name , doc in methods )
200
+ if methods else 0 )
192
201
return (longest_name_len , methods )
193
202
194
203
195
204
def zerorpc_inspect (client , method = None , long_doc = True , include_argspec = True ):
196
205
try :
197
- remote_methods = client ._zerorpc_inspect ()['methods' ]
206
+ inspect_result = client ._zerorpc_inspect ()
207
+ remote_methods = inspect_result ['methods' ]
198
208
legacy = False
199
209
except (zerorpc .RemoteError , NameError ):
200
210
legacy = True
201
211
202
212
if legacy :
203
- return zerorpc_inspect_legacy (client , method ,
204
- long_doc , include_argspec )
213
+ try :
214
+ service_name = client ._zerorpc_name ()
215
+ except (zerorpc .RemoteError ):
216
+ service_name = 'N/A'
205
217
206
- if not isinstance (remote_methods , dict ):
207
- return zerorpc_inspect_python_argspecs (remote_methods , method , long_doc ,
208
- include_argspec )
218
+ (longest_name_len , detailled_methods ) = zerorpc_inspect_legacy (client ,
219
+ method , long_doc , include_argspec )
220
+ else :
221
+ service_name = inspect_result .get ('name' , 'N/A' )
222
+ if not isinstance (remote_methods , dict ):
223
+ (longest_name_len ,
224
+ detailled_methods ) = zerorpc_inspect_python_argspecs (
225
+ remote_methods , method , long_doc , include_argspec )
209
226
210
- return zerorpc_inspect_generic (remote_methods , method , long_doc ,
211
- include_argspec )
227
+ (longest_name_len , detailled_methods ) = zerorpc_inspect_generic (
228
+ remote_methods , method , long_doc , include_argspec )
229
+
230
+ return longest_name_len , detailled_methods , service_name
212
231
213
232
214
233
def run_client (args ):
@@ -218,8 +237,9 @@ def run_client(args):
218
237
client .debug = True
219
238
setup_links (args , client )
220
239
if not args .command :
221
- (longest_name_len , detailled_methods ) = zerorpc_inspect (client ,
240
+ (longest_name_len , detailled_methods , service ) = zerorpc_inspect (client ,
222
241
long_doc = False , include_argspec = args .inspect )
242
+ print '[{0}]' .format (service )
223
243
if args .inspect :
224
244
for (name , doc ) in detailled_methods :
225
245
print name
@@ -228,10 +248,13 @@ def run_client(args):
228
248
print '{0} {1}' .format (name .ljust (longest_name_len ), doc )
229
249
return
230
250
if args .inspect :
231
- (longest_name_len , detailled_methods ) = zerorpc_inspect (client ,
251
+ (longest_name_len , detailled_methods , service ) = zerorpc_inspect (client ,
232
252
method = args .command )
233
- (name , doc ) = detailled_methods [0 ]
234
- print '\n {0}\n \n {1}\n ' .format (name , doc )
253
+ if detailled_methods :
254
+ (name , doc ) = detailled_methods [0 ]
255
+ print '[{0}]\n {1}\n \n {2}\n ' .format (service , name , doc )
256
+ else :
257
+ print '[{0}]\n No documentation for "{1}".' .format (service , args .command )
235
258
return
236
259
if args .json :
237
260
call_args = [json .loads (x ) for x in args .params ]
0 commit comments