comparison Sphinx/source/plugins/python.rst @ 369:181b02cea7ab

inspecting Python API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 02 Apr 2020 08:39:41 +0200
parents 234de55ed125
children cb1d9a5bb043 847996394688
comparison
equal deleted inserted replaced
366:12f88a12d146 369:181b02cea7ab
346 output.SendMethodNotAllowed('GET') 346 output.SendMethodNotAllowed('GET')
347 347
348 orthanc.RegisterRestCallback('/pydicom/(.*)', DecodeInstance) # (*) 348 orthanc.RegisterRestCallback('/pydicom/(.*)', DecodeInstance) # (*)
349 349
350 350
351 .. _python-introspection:
352
353 Inspecting the available API
354 ............................
355
356 .. highlight:: python
357
358 Thanks to Python's introspection primitives, it is possible to inspect
359 the API of the ``orthanc`` module in order to dump all the available
360 features::
361
362 import inspect
363 import numbers
364 import orthanc
365
366 # Loop over the members of the "orthanc" module
367 for (name, obj) in inspect.getmembers(orthanc):
368 if inspect.isroutine(obj):
369 print('Function %s():\n Documentation: %s\n' % (name, inspect.getdoc(obj)))
370
371 elif inspect.isclass(obj):
372 print('Class %s:\n Documentation: %s' % (name, inspect.getdoc(obj)))
373
374 # Loop over the members of the class
375 for (subname, subobj) in inspect.getmembers(obj):
376 if isinstance(subobj, numbers.Number):
377 print(' - Enumeration value %s: %s' % (subname, subobj))
378 elif (not subname.startswith('_') and
379 inspect.ismethoddescriptor(subobj)):
380 print(' - Method %s(): %s' % (subname, inspect.getdoc(subobj)))
381 print('')
382
383
384
385
386
351 Performance and concurrency 387 Performance and concurrency
352 --------------------------- 388 ---------------------------
353 389
354 .. highlight:: python 390 .. highlight:: python
355 391