ParserServer.py 939 B

12345678910111213141516171819202122232425262728293031
  1. import anvil.tables as tables
  2. import anvil.tables.query as q
  3. from anvil.tables import app_tables
  4. import anvil.server
  5. import yaml
  6. import json
  7. import pprint
  8. # This is a server module. It runs on the Anvil server,
  9. # rather than in the user's browser.
  10. #
  11. # To allow anvil.server.call() to call functions here, we mark
  12. # them with @anvil.server.callable.
  13. # Here is an example - you can replace it with your own:
  14. #
  15. @anvil.server.callable
  16. def parse_yaml(yaml_data):
  17. try:
  18. return (0,pprint.pformat(yaml.safe_load(yaml_data), indent=2),"",0,0)
  19. except yaml.YAMLError as exc:
  20. return (1,pprint.pformat(yaml_data, indent=2), exc.problem, exc.problem_mark.line, exc.problem_mark.column)
  21. @anvil.server.callable
  22. def parse_json(json_data):
  23. try:
  24. return (0,pprint.pformat(json.loads(json_data), indent=2),"",0,0)
  25. except json.JSONDecodeError as exc:
  26. return (1,pprint.pformat(json_data, indent=2), exc.msg, exc.lineno, exc.colno)