utils.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import re
  2. # stolen from python docs
  3. def trim(docstring):
  4. if not docstring:
  5. return ""
  6. # Convert tabs to spaces (following the normal Python rules)
  7. # and split into a list of lines:
  8. lines = docstring.expandtabs().splitlines()
  9. # Determine minimum indentation (first line doesn't count):
  10. indent = 232323
  11. for line in lines[1:]:
  12. stripped = line.lstrip()
  13. if stripped:
  14. indent = min(indent, len(line) - len(stripped))
  15. # Remove indentation (first line is special):
  16. trimmed = [lines[0].strip()]
  17. if indent < 232323:
  18. for line in lines[1:]:
  19. trimmed.append(line[indent:].rstrip())
  20. # Strip off trailing and leading blank lines:
  21. while trimmed and not trimmed[-1]:
  22. trimmed.pop()
  23. while trimmed and not trimmed[0]:
  24. trimmed.pop(0)
  25. # Return a single string:
  26. return "\n".join(trimmed)
  27. def env_name_format(str):
  28. # KeyCorridorEnv
  29. split = re.findall(r"[A-Z](?:[a-z]+|[A-Z]*(?=[A-Z]|$))", str)
  30. # ['Key', 'Corridor', 'Env']
  31. split = filter(lambda x: x.upper() != "ENV", split)
  32. return " ".join(split)