From e615a2ab4fa5a05f92faf2bf5558cabf6303eb9d Mon Sep 17 00:00:00 2001 From: Harshit Bansal Date: Sat, 11 Nov 2017 14:38:02 +0000 Subject: [PATCH] bugdown: Simplify the "opts" parameter of `make_md_engine()`. --- zerver/lib/bugdown/__init__.py | 17 +++++++---------- zerver/tests/test_bugdown.py | 12 ++++++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/zerver/lib/bugdown/__init__.py b/zerver/lib/bugdown/__init__.py index 31e36bda76..cbe120ab96 100644 --- a/zerver/lib/bugdown/__init__.py +++ b/zerver/lib/bugdown/__init__.py @@ -1286,7 +1286,7 @@ ZEPHYR_MIRROR_BUGDOWN_KEY = -2 class Bugdown(markdown.Extension): def __init__(self, *args, **kwargs): - # type: (*Any, **Union[bool, None, Text]) -> None + # type: (*Any, **Union[bool, int, List[Any]]) -> None # define default configs self.config = { "realm_filters": [kwargs['realm_filters'], "Realm-specific filters for realm"], @@ -1466,9 +1466,9 @@ def make_md_engine(key, opts): ), fenced_code.makeExtension(), EscapeHtml(), - Bugdown(realm_filters=opts["realm_filters"][0], - realm=opts["realm"][0], - code_block_processor_disabled=opts["code_block_processor_disabled"][0])]) + Bugdown(realm_filters=opts["realm_filters"], + realm=opts["realm"], + code_block_processor_disabled=opts["code_block_processor_disabled"])]) def subject_links(realm_filters_key, subject): # type: (int, Text) -> List[Text] @@ -1490,13 +1490,10 @@ def make_realm_filters(realm_filters_key, filters, email_gateway): del md_engines[md_engine_key] realm_filter_data[realm_filters_key] = filters - # Because of how the Markdown config API works, this has confusing - # large number of layers of dicts/arrays :( make_md_engine(md_engine_key, - {"realm_filters": [ - filters, "Realm-specific filters for realm_filters_key %s" % (realm_filters_key,)], - "realm": [realm_filters_key, "Realm name"], - "code_block_processor_disabled": [email_gateway, 'Disabled for email mirror']}) + {"realm_filters": filters, + "realm": realm_filters_key, + "code_block_processor_disabled": email_gateway}) def maybe_update_markdown_engines(realm_filters_key, email_gateway): # type: (Optional[int], bool) -> None diff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.py index 147a1b6a13..043e9a7db7 100644 --- a/zerver/tests/test_bugdown.py +++ b/zerver/tests/test_bugdown.py @@ -274,9 +274,9 @@ class BugdownTest(ZulipTestCase): realm = Realm.objects.create(string_id='file_links_test') bugdown.make_md_engine( realm.id, - {'realm_filters': [[], u'file_links_test.example.com'], - 'realm': [u'file_links_test.example.com', 'Realm name'], - 'code_block_processor_disabled': [False, 'Disabled for email gateway']}) + {'realm_filters': [], + 'realm': 'file_links_test.example.com', + 'code_block_processor_disabled': False}) converted = bugdown.convert(msg, message_realm=realm) self.assertEqual(converted, '

Check out this file file:///Volumes/myserver/Users/Shared/pi.py

') @@ -1160,9 +1160,9 @@ class BugdownTest(ZulipTestCase): realm = Realm.objects.create(string_id='code_block_processor_test') bugdown.make_md_engine( realm.id, - {'realm_filters': [[], u'file_links_test.example.com'], - 'realm': [u'file_links_test.example.com', 'Realm name'], - 'code_block_processor_disabled': [True, 'Disabled for email gateway']}) + {'realm_filters': [], + 'realm': 'file_links_test.example.com', + 'code_block_processor_disabled': True}) converted = bugdown.convert(msg, message_realm=realm, email_gateway=True) expected_output = '

Hello,

\n' + \ '

I am writing this message to test something. I am writing this message to test something.

'