From 739236bc47d15c37bda5316335af7b22452b7ca5 Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Tue, 3 Jan 2023 14:07:28 +0100 Subject: [PATCH] check: Protected quotes and bcodes (+stats) in main fonction protect_bcodes_quotes() --- src/var/lib/tyto/program/tyto.py | 114 +++++++++++++------------------ 1 file changed, 49 insertions(+), 65 deletions(-) diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index 4efa14a..c593a59 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -345,88 +345,72 @@ def protect_icodes(post_bottom, article_bottom): def protect_bcodes_quotes(process, post_bottom, article_bottom): global protect_article + global nbr_titles, nbr_bcodes, nbr_quotes # Stats for DB in_bcode = in_quote = False protect_article = '' temp_article = article_bottom + nbr_titles = nbr_bcodes = nbr_quotes = 0 + bcode = quote = '' + end_bcode = end_quote = False - if process == 'check': - global nbr_titles, nbr_bcodes, nbr_quotes # Stats for DB - nbr_titles = nbr_bcodes = nbr_quotes = 0 - - for line in post_bottom: + for line in post_bottom: + # Bcode + if not in_quote: if line.startswith(words_tags[12][0]): in_bcode = True - nbr_bcodes += 1 - continue + if process == 'check': + if not protect_article: protect_article = line + else: protect_article = '%s\n%s'%(protect_article, line) + nbr_bcodes += 1 elif line.startswith(words_tags[12][1]): - in_bcode = False - continue - elif line.startswith('#'): # As convention - if line.startswith(titles_tags): nbr_titles += 1 - else: continue - - if in_bcode: continue - elif line.startswith(words_tags[11][0]): - in_quote = True - nbr_quotes += 1 - continue - elif line.startswith(words_tags[11][1]): - in_quote = False - continue - - if in_quote: - if not line in (words_tags[10][0], words_tags[10][1]): - continue - - if not protect_article: protect_article = line - else: protect_article = '%s\n%s'%(protect_article, line) - - - # For wip, bcodes are converted to base64 - #---------------------------------------- - elif process == 'wip': - bcode = quote = '' - end_bcode = end_quote = False - - for line in post_bottom: - # Bcode - if not in_quote: - if line.startswith(words_tags[12][0]): - in_bcode = True - elif line.startswith(words_tags[12][1]): + if process == "wip": bcode = '%s\n%s'%(bcode, line) b64_bcode = b64('Encode', bcode, 'B64.', '.B64') line = b64_bcode end_bcode = True - in_bcode = False - - # Quote - if not in_bcode: - if line.startswith(words_tags[11][0]): - in_quote = True - elif line.startswith(words_tags[11][1]): + in_bcode = False + + # Quote + if not in_bcode: + if line.startswith(words_tags[11][0]): + in_quote = True + if process == 'check': + if not protect_article: protect_article = line + else: protect_article = '%s\n%s'%(protect_article, line) + nbr_quotes += 1 + elif line.startswith(words_tags[11][1]): + if process == "wip": quote = '%s\n%s'%(quote, line) b64_quote = b64('Encode', quote, 'Q64.', '.Q64') line = b64_quote end_quote = True - in_quote = False - - if in_bcode: - if not bcode: bcode = line - else: bcode = '%s\n%s'%(bcode, line) - - elif in_quote: - if not quote: quote = line - else: quote = '%s\n%s'%(quote, line) + in_quote = False - if end_bcode: bcode = ''; end_bcode = False ; in_bcode = False - elif end_quote: quote = ''; end_quote = False ; in_quote = False + # Count titles for check + # Pass if line is a comment + if not in_bcode or not in_quote: + if line.startswith(titles_tags): + if process == 'check': + nbr_titles += 1 + elif line.startswith('#'): + continue + + if in_bcode: + if not bcode: bcode = line + else: bcode = '%s\n%s'%(bcode, line) + + elif in_quote: + if not quote: quote = line + else: quote = '%s\n%s'%(quote, line) - if in_quote or in_bcode: - continue - else: - if not protect_article: protect_article = line - else: protect_article = '%s\n%s'%(protect_article, line) + if end_bcode: bcode = ''; end_bcode = False ; in_bcode = False + elif end_quote: quote = ''; end_quote = False ; in_quote = False + + if in_quote or in_bcode: + continue + else: + if not protect_article: protect_article = line + else: protect_article = '%s\n%s'%(protect_article, line) #=====================================#