@@ -1,6 +1,6 @@ | |||||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
# | # | ||||
# Copyright (C) 2012-2017 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
# Copyright (C) 2012-2019 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
# | # | ||||
# Permission is hereby granted, free of charge, to any person obtaining a copy | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
# of this software and associated documentation files (the "Software"), to deal | # of this software and associated documentation files (the "Software"), to deal | ||||
@@ -193,3 +193,16 @@ UNSAFE = (TEMPLATE_NAME + WIKILINK_TITLE + EXT_LINK_TITLE + | |||||
DOUBLE = TEMPLATE_PARAM_KEY + TAG_CLOSE + TABLE_ROW_OPEN | DOUBLE = TEMPLATE_PARAM_KEY + TAG_CLOSE + TABLE_ROW_OPEN | ||||
NO_WIKILINKS = TEMPLATE_NAME + ARGUMENT_NAME + WIKILINK_TITLE + EXT_LINK_URI | NO_WIKILINKS = TEMPLATE_NAME + ARGUMENT_NAME + WIKILINK_TITLE + EXT_LINK_URI | ||||
NO_EXT_LINKS = TEMPLATE_NAME + ARGUMENT_NAME + WIKILINK_TITLE + EXT_LINK | NO_EXT_LINKS = TEMPLATE_NAME + ARGUMENT_NAME + WIKILINK_TITLE + EXT_LINK | ||||
def describe(context): | |||||
"""Return a string describing the given context value, for debugging.""" | |||||
flags = [] | |||||
for name, value in globals().items(): | |||||
if not isinstance(value, int) or name.startswith("GL_"): | |||||
continue | |||||
if bin(value).count("1") != 1: | |||||
continue # Hacky way to skip aggregate contexts | |||||
if context & value: | |||||
flags.append((name, value)) | |||||
flags.sort(key=lambda it: it[1]) | |||||
return "|".join(it[0] for it in flags) |
@@ -1,6 +1,6 @@ | |||||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
# | # | ||||
# Copyright (C) 2012-2016 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
# Copyright (C) 2012-2019 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
# | # | ||||
# Permission is hereby granted, free of charge, to any person obtaining a copy | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
# of this software and associated documentation files (the "Software"), to deal | # of this software and associated documentation files (the "Software"), to deal | ||||
@@ -23,6 +23,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import unittest | import unittest | ||||
from mwparserfromhell.parser import contexts | |||||
from mwparserfromhell.parser.tokenizer import Tokenizer | from mwparserfromhell.parser.tokenizer import Tokenizer | ||||
from ._test_tokenizer import TokenizerTestCase | from ._test_tokenizer import TokenizerTestCase | ||||
@@ -40,5 +41,10 @@ class TestPyTokenizer(TokenizerTestCase, unittest.TestCase): | |||||
self.assertFalse(Tokenizer.USES_C) | self.assertFalse(Tokenizer.USES_C) | ||||
self.assertFalse(Tokenizer().USES_C) | self.assertFalse(Tokenizer().USES_C) | ||||
def test_describe_context(self): | |||||
self.assertEqual("", contexts.describe(0)) | |||||
ctx = contexts.describe(contexts.TEMPLATE_PARAM_KEY|contexts.HAS_TEXT) | |||||
self.assertEqual("TEMPLATE_PARAM_KEY|HAS_TEXT", ctx) | |||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
unittest.main(verbosity=2) | unittest.main(verbosity=2) |