Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

55 lignes
1.0 KiB

  1. # coding: utf-8
  2. """
  3. Exports the following items:
  4. - unwrap()
  5. - APIException()
  6. """
  7. from __future__ import unicode_literals, division, absolute_import, print_function
  8. import re
  9. import textwrap
  10. class APIException(Exception):
  11. """
  12. An exception indicating an API has been removed from asn1crypto
  13. """
  14. pass
  15. def unwrap(string, *params):
  16. """
  17. Takes a multi-line string and does the following:
  18. - dedents
  19. - converts newlines with text before and after into a single line
  20. - strips leading and trailing whitespace
  21. :param string:
  22. The string to format
  23. :param *params:
  24. Params to interpolate into the string
  25. :return:
  26. The formatted string
  27. """
  28. output = textwrap.dedent(string)
  29. # Unwrap lines, taking into account bulleted lists, ordered lists and
  30. # underlines consisting of = signs
  31. if output.find('\n') != -1:
  32. output = re.sub('(?<=\\S)\n(?=[^ \n\t\\d\\*\\-=])', ' ', output)
  33. if params:
  34. output = output % params
  35. output = output.strip()
  36. return output