regexes.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/env python
  2. # vim:set et sw=4:
  3. """
  4. Central repository of regexes for dak
  5. @contact: Debian FTP Master <ftpmaster@debian.org>
  6. @copyright: 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org>
  7. @copyright: 2009 Mark Hymers <mhy@debian.org>
  8. @copyright: 2009, 2010 Joerg Jaspert <joerg@debian.org>
  9. @license: GNU General Public License version 2 or later
  10. """
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. ###############################################################################
  23. import re
  24. #: Is it a number?
  25. re_isanum = re.compile (r"^\d+$")
  26. #: Looking for the default reply
  27. re_default_answer = re.compile(r"\[(.*)\]")
  28. #: Detect a binnmu
  29. re_bin_only_nmu = re.compile(r"\+b\d+$")
  30. #: To sort out comment lines
  31. re_comments = re.compile(r"\#.*")
  32. #: To ignore comment and whitespace lines.
  33. re_whitespace_comment = re.compile(r"^\s*(#|$)")
  34. re_no_epoch = re.compile(r"^\d+\:")
  35. re_extract_src_version = re.compile (r"(\S+)\s*\((.*)\)")
  36. re_isadeb = re.compile (r"(.+?)_(.+?)_(.+)\.u?deb$")
  37. orig_source_ext_re = r"orig(?:-.+)?\.tar\.(?:gz|bz2|xz)"
  38. re_source_ext = re.compile("(" + orig_source_ext_re + r"|debian\.tar\.(?:gz|bz2|xz)|diff\.gz|tar\.(?:gz|bz2|xz)|dsc|asc)$")
  39. re_issource = re.compile(r"(.+)_(.+?)\." + re_source_ext.pattern)
  40. re_single_line_field = re.compile(r"^(\S*?)\s*:\s*(.*)")
  41. re_multi_line_field = re.compile(r"^\s(.*)")
  42. re_taint_free = re.compile(r"^[-+~/\.\w]+$")
  43. re_parse_maintainer = re.compile(r"^\s*(\S.*\S)\s*\<([^\>]+)\>")
  44. re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$")
  45. re_verwithext = re.compile(r"^(\d+)(?:\.(\d+))(?:\s+\((\S+)\))?$")
  46. html_escaping = {'"':'&quot;', '&':'&amp;', '<':'&lt;', '>':'&gt;'}
  47. re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys())))
  48. # From clean_proposed_updates.py
  49. re_isdeb = re.compile (r"^(.+)_(.+?)_(.+?).u?deb$")
  50. # From examine_package.py
  51. re_package = re.compile(r"^(.+?)_.*")
  52. re_doc_directory = re.compile(r".*/doc/([^/]*).*")
  53. re_contrib = re.compile('^contrib/')
  54. re_nonfree = re.compile('^non\-free/')
  55. re_localhost = re.compile("localhost\.localdomain")
  56. re_version = re.compile('^(.*)\((.*)\)')
  57. re_newlinespace = re.compile('\n')
  58. re_spacestrip = re.compile('(\s)')
  59. # From new_security_install.py
  60. re_taint_free = re.compile(r"^['/;\-\+\.~\s\w]+$")
  61. # From process_unchecked.py
  62. re_changelog_versions = re.compile(r"^\w[-+0-9a-z.]+ \([^\(\) \t]+\)")
  63. # From dak/rm.py
  64. re_strip_source_version = re.compile (r'\s+.*$')
  65. re_build_dep_arch = re.compile(r"\[[^]]+\]")
  66. # From dak/transitions.py
  67. re_broken_package = re.compile(r"[a-zA-Z]\w+\s+\-.*")
  68. # From dak/add_user.py
  69. re_gpg_fingerprint_colon = re.compile(r"^fpr:+(.*):$", re.MULTILINE);
  70. # The next one is dirty
  71. re_user_address = re.compile(r"^pub:.*<(.*)@.*>.*$", re.MULTILINE);
  72. re_user_mails = re.compile(r"^(pub|uid):[^rdin].*<(.*@.*)>.*$", re.MULTILINE);
  73. re_user_name = re.compile(r"^pub:.*:(.*)<.*$", re.MULTILINE);
  74. re_re_mark = re.compile(r'^RE:')
  75. re_parse_lintian = re.compile(r"^(?P<level>W|E|O): (?P<package>.*?): (?P<tag>[^ ]*) ?(?P<description>.*)$")
  76. # in generate-releases
  77. re_gensubrelease = re.compile (r".*/(binary-[0-9a-z-]+|source)$")
  78. re_includeinrelease = re.compile (r"(Translation-[a-zA-Z_]+\.(?:bz2|xz)|Contents-[0-9a-z-]+.gz|Index|Packages(.gz|.bz2|.xz)?|Sources(.gz|.bz2|.xz)?|MD5SUMS|SHA256SUMS|Release)$")
  79. # in generate_index_diffs
  80. re_includeinpdiff = re.compile(r"(Translation-[a-zA-Z_]+\.(?:bz2|xz))")
  81. ######################################################################
  82. # Patterns matching filenames #
  83. ######################################################################
  84. # Match safe filenames
  85. re_file_safe = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_.~+-]*$')
  86. # Match safe filenames, including slashes
  87. re_file_safe_slash = re.compile(r'^[a-zA-Z0-9][/a-zA-Z0-9_.~+-]*$')
  88. # Prefix of binary and source filenames
  89. _re_file_prefix = r'^(?P<package>[a-z0-9][a-z0-9.+-]+)_(?P<version>[A-Za-z0-9.~+-]+?)'
  90. # Match binary packages
  91. # Groups: package, version, architecture, type
  92. re_file_binary = re.compile(_re_file_prefix + r'_(?P<architecture>[a-z0-9-]+)\.(?P<type>u?deb)$')
  93. # Match changes files
  94. # Groups: package, version, suffix
  95. re_file_changes = re.compile(_re_file_prefix + r'_(?P<suffix>[a-zA-Z0-9+-]+)\.changes$')
  96. # Match dsc files
  97. # Groups: package, version
  98. re_file_dsc = re.compile(_re_file_prefix + r'\.dsc$')
  99. # Match other source files
  100. # Groups: package, version
  101. re_file_source = re.compile(_re_file_prefix + r'(?:(?:\.orig(?:-[a-zA-Z0-9-]+)?|\.debian)?\.tar\.(?:bz2|gz|xz)|\.diff\.gz|\.asc)$')
  102. # Match upstream tarball
  103. # Groups: package, version
  104. re_file_orig = re.compile(_re_file_prefix + r'\.orig(?:-[a-zA-Z0-9-]+)?(?:\.tar\.(?:bz2|gz|xz)|\.asc)')
  105. ######################################################################
  106. # Patterns matching fields #
  107. ######################################################################
  108. # Match package name
  109. re_field_package = re.compile(r'^[a-z0-9][a-z0-9.+-]+$')
  110. # Match version
  111. # Groups: without-epoch
  112. re_field_version = re.compile(r'^(?:[0-9]+:)?(?P<without_epoch>[A-Za-z0-9.:~+-]+)$')
  113. # Extract upstream version
  114. # Groups: upstream
  115. re_field_version_upstream = re.compile(r'^(?:[0-9]+:)?(?P<upstream>.*)-[^-]*$')
  116. # Match source field
  117. # Groups: package, version
  118. re_field_source = re.compile(r'^(?P<package>[a-z0-9][a-z0-9.+-]+)(?:\s*\((?P<version>[A-Za-z0-9.:~+-]+)\))?$')