This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

102 řádky
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. from . import core as html5
  3. def unescape(val, maxLength = 0):
  4. """
  5. Unquotes several HTML-quoted characters in a string.
  6. :param val: The value to be unescaped.
  7. :type val: str
  8. :param maxLength: Cut-off after maxLength characters.
  9. A value of 0 means "unlimited". (default)
  10. :type maxLength: int
  11. :returns: The unquoted string.
  12. :rtype: str
  13. """
  14. val = val \
  15. .replace("&lt;", "<") \
  16. .replace("&gt;", ">") \
  17. .replace("&quot;", "\"") \
  18. .replace("&#39;", "'")
  19. if maxLength > 0:
  20. return val[0:maxLength]
  21. return val
  22. def doesEventHitWidgetOrParents(event, widget):
  23. """
  24. Test if event 'event' hits widget 'widget' (or *any* of its parents)
  25. """
  26. while widget:
  27. if event.target == widget.element:
  28. return widget
  29. widget = widget.parent()
  30. return None
  31. def doesEventHitWidgetOrChildren(event, widget):
  32. """
  33. Test if event 'event' hits widget 'widget' (or *any* of its children)
  34. """
  35. if event.target == widget.element:
  36. return widget
  37. for child in widget.children():
  38. if doesEventHitWidgetOrChildren(event, child):
  39. return child
  40. return None
  41. def textToHtml(node, text):
  42. """
  43. Generates html nodes from text by splitting text into content and into
  44. line breaks html5.Br.
  45. :param node: The node where the nodes are appended to.
  46. :param text: The text to be inserted.
  47. """
  48. for (i, part) in enumerate(text.split("\n")):
  49. if i > 0:
  50. node.appendChild(html5.Br())
  51. node.appendChild(html5.TextNode(part))
  52. def parseInt(s, ret = 0):
  53. """
  54. Parses a value as int
  55. """
  56. if not isinstance(s, str):
  57. return int(s)
  58. elif s:
  59. if s[0] in "+-":
  60. ts = s[1:]
  61. else:
  62. ts = s
  63. if ts and all([_ in "0123456789" for _ in ts]):
  64. return int(s)
  65. return ret
  66. def parseFloat(s, ret = 0.0):
  67. """
  68. Parses a value as float.
  69. """
  70. if not isinstance(s, str):
  71. return float(s)
  72. elif s:
  73. if s[0] in "+-":
  74. ts = s[1:]
  75. else:
  76. ts = s
  77. if ts and ts.count(".") <= 1 and all([_ in ".0123456789" for _ in ts]):
  78. return float(s)
  79. return ret