constants.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. # The MIT License (MIT)
  3. # Copyright (c) 2014-2017 Matias Bordese
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  19. # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20. # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
  21. # OR OTHER DEALINGS IN THE SOFTWARE.
  22. """Useful constants and regexes used by the package."""
  23. from __future__ import unicode_literals
  24. import re
  25. RE_SOURCE_FILENAME = re.compile(
  26. r'^--- (?P<filename>[^\t\n]+)(?:\t(?P<timestamp>[^\n]+))?')
  27. RE_TARGET_FILENAME = re.compile(
  28. r'^\+\+\+ (?P<filename>[^\t\n]+)(?:\t(?P<timestamp>[^\n]+))?')
  29. # @@ (source offset, length) (target offset, length) @@ (section header)
  30. RE_HUNK_HEADER = re.compile(
  31. r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?\ @@[ ]?(.*)")
  32. # kept line (context)
  33. # \n empty line (treat like context)
  34. # + added line
  35. # - deleted line
  36. # \ No newline case
  37. RE_HUNK_BODY_LINE = re.compile(
  38. r'^(?P<line_type>[- \+\\])(?P<value>.*)', re.DOTALL)
  39. RE_HUNK_EMPTY_BODY_LINE = re.compile(
  40. r'^(?P<line_type>[- \+\\]?)(?P<value>[\r\n]{1,2})', re.DOTALL)
  41. RE_NO_NEWLINE_MARKER = re.compile(r'^\\ No newline at end of file')
  42. DEFAULT_ENCODING = 'UTF-8'
  43. LINE_TYPE_ADDED = '+'
  44. LINE_TYPE_REMOVED = '-'
  45. LINE_TYPE_CONTEXT = ' '
  46. LINE_TYPE_EMPTY = ''
  47. LINE_TYPE_NO_NEWLINE = '\\'
  48. LINE_VALUE_NO_NEWLINE = ' No newline at end of file'