Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

  1. """
  2. Python utilities for the ein inspector.
  3. Copyright (C) 2017- John M. Miller
  4. Author: John Miller <millejoh at gmail.com>
  5. ein_inspector.py is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. ein_inspector.py is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with ein_inspector.py. If not, see <http://www.gnu.org/licenses/>.
  15. """
  16. import json
  17. import inspect
  18. def generate_inspector_data(obj_str, globals, locals):
  19. odata = {'name': obj_str}
  20. try:
  21. obj = eval(obj_str, globals, locals)
  22. except NameError:
  23. odata['error'] = 'Object {} not found.'.format(obj_str)
  24. else:
  25. odata['doc'] = inspect.getdoc(obj)
  26. odata['type'] = str(type(obj))
  27. odata['repr'] = str(obj)
  28. try:
  29. odata['source_file'] = inspect.getsourcefile(obj)
  30. odata['source_lines'] = inspect.getsourcelines(obj)
  31. except:
  32. odata['source_file'] = None
  33. odata['source_lines'] = None
  34. print(json.dumps(odata))
  35. return odata