Guest User

Untitled

a guest
May 20th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #!/usr/env python3
  3. import jedi
  4.  
  5.  
  6. def run_with_debug(name, *args, **kwargs):
  7. re_raise = kwargs.pop('re_raise', ())
  8. try:
  9. script = jedi.Script(*args, **kwargs)
  10. return getattr(script, name)()
  11. except Exception as e:
  12. if isinstance(e, re_raise):
  13. raise
  14. # Bug jedi#485
  15. if (isinstance(e, ValueError) and "invalid \\x escape" in str(e)):
  16. return None
  17. # Bug jedi#485 in Python 3
  18. if (isinstance(e, SyntaxError) and "truncated \\xXX escape" in str(e)):
  19. return None
  20.  
  21.  
  22. def rpc_get_definition(filename, source, line, column):
  23. locations = run_with_debug('goto_definitions',
  24. source=source, line=line, column=column,
  25. path=filename, encoding='utf-8')
  26. print("Location from 'goto_definition':")
  27. print(" {}".format(locations))
  28. if locations is not None:
  29. print(" " + locations[-1].module_path)
  30. print(" " + locations[-1].full_name)
  31. print(" line: {}, col: {}"
  32. .format(locations[-1].line, locations[-1].column))
  33. if (locations and locations[0].module_path is None):
  34. locations = run_with_debug(jedi, 'goto_assignments',
  35. source=source, line=line,
  36. column=column,
  37. path=filename, encoding='utf-8')
  38. print("Location from 'goto_assignments':")
  39. print(" {}".format(locations))
  40. if locations is not None:
  41. print(" " + locations[-1].module_path)
  42. print(" " + locations[-1].full_name)
  43. print(" line: {}, col: {}"
  44. .format(locations[-1].line, locations[-1].column))
  45. if not locations:
  46. return None
  47. else:
  48. loc = locations[-1]
  49. print("Returned location: {}".format(loc))
  50. return loc.module_path
  51.  
  52.  
  53. line = 17
  54. column = 29
  55. filename = "trading.py"
  56. with open('trading.py', 'r') as f:
  57. source = "".join(f.readlines())
  58. source = None
  59. rpc_get_definition(filename=filename, source=source,
  60. line=line, column=column)
Add Comment
Please, Sign In to add comment