A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

55 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2012-2016 Ben Kurtovic <ben.kurtovic@gmail.com>
  4. # Copyright (C) 2019-2020 Yuri Astrakhan <YuriAstrakhan@gmail.com>
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to deal
  8. # in the Software without restriction, including without limitation the rights
  9. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. # copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included in
  14. # all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. from __future__ import unicode_literals
  24. from sys import maxsize
  25. __all__ = []
  26. def inheritdoc(method):
  27. """Set __doc__ of *method* to __doc__ of *method* in its parent class.
  28. Since this is used on :class:`.SmartList`, the "parent class" used is
  29. ``list``. This function can be used as a decorator.
  30. """
  31. method.__doc__ = getattr(list, method.__name__).__doc__
  32. return method
  33. class _SliceNormalizerMixIn(object):
  34. """MixIn that provides a private method to normalize slices."""
  35. def _normalize_slice(self, key, clamp=False):
  36. """Return a slice equivalent to the input *key*, standardized."""
  37. if key.start is None:
  38. start = 0
  39. else:
  40. start = (len(self) + key.start) if key.start < 0 else key.start
  41. if key.stop is None or key.stop == maxsize:
  42. stop = len(self) if clamp else None
  43. else:
  44. stop = (len(self) + key.stop) if key.stop < 0 else key.stop
  45. return slice(start, stop, key.step or 1)