fix: b64(). Indev for quotes

This commit is contained in:
Cyrille L 2022-12-18 15:34:29 +01:00
parent eae4f8591c
commit dff84b969a
2 changed files with 25 additions and 6 deletions

View File

@ -287,7 +287,7 @@ def protect_icodes(post_bottom, article_bottom):
if c_a == '}' and not c_b == '\\': if c_a == '}' and not c_b == '\\':
incode = False incode = False
code = '%s%s%s'%(code, src_code, words_tags[9][3]) code = '%s%s%s'%(code, src_code, words_tags[9][3])
b64_code = b64('Encode', code) b64_code = b64('Encode', code, 'I64_', '_I64')
rep_code = "%s%s%s"%( rep_code = "%s%s%s"%(
words_tags[9][0],rep_code,words_tags[9][1] words_tags[9][0],rep_code,words_tags[9][1]
) )
@ -364,7 +364,7 @@ def protect_bcodes_quotes(process, post_bottom, article_bottom):
elif line.startswith(words_tags[12][1]): elif line.startswith(words_tags[12][1]):
bcode = '%s\n%s'%(bcode, line) bcode = '%s\n%s'%(bcode, line)
in_bcode = False in_bcode = False
b64_bcode = b64('Encode', bcode) b64_bcode = b64('Encode', bcode, 'B64_', '_B64')
protect_article = '%s\n%s'%(protect_article, b64_bcode) protect_article = '%s\n%s'%(protect_article, b64_bcode)
bcode = '' bcode = ''
continue continue
@ -380,7 +380,7 @@ def protect_bcodes_quotes(process, post_bottom, article_bottom):
if not in_bcode: if not in_bcode:
quote = '%s\n%s'%(quote, line) quote = '%s\n%s'%(quote, line)
in_quote = False in_quote = False
b64_quote = b64('Encode', quote) b64_quote = b64('Encode', quote, 'Q64_', '_Q64')
protect_article = '%s\n%s'%(protect_article, b64_quote) protect_article = '%s\n%s'%(protect_article, b64_quote)
quote = '' quote = ''
continue continue
@ -402,19 +402,19 @@ def protect_bcodes_quotes(process, post_bottom, article_bottom):
# Encode/Decode string to/from base64 # # Encode/Decode string to/from base64 #
# Data protection # # Data protection #
#-------------------------------------# #-------------------------------------#
def b64(action, content): def b64(action, content, before, after):
if action == 'Encode': if action == 'Encode':
global b64_content global b64_content
b64_base64 = '' b64_base64 = ''
content_bytes = content.encode("ascii") content_bytes = content.encode("ascii")
base64_bytes = base64.b64encode(content_bytes) base64_bytes = base64.b64encode(content_bytes)
b64_content = 'B64_' + base64_bytes.decode("ascii") + '_B64' b64_content = before + base64_bytes.decode("ascii") + after
return b64_content return b64_content
elif action == 'Decode': elif action == 'Decode':
global src_content global src_content
src_content = '' src_content = ''
content_bytes = post_content.encode("ascii") content_bytes = content.encode("ascii")
base64_bytes = base64.b64decode(content_bytes) base64_bytes = base64.b64decode(content_bytes)
src_content = base64_bytes.decode("ascii") src_content = base64_bytes.decode("ascii")
return src_content return src_content

View File

@ -87,6 +87,9 @@ def wip_article(target):
wip_links() # Links_%i from headers in DB wip_links() # Links_%i from headers in DB
wip_images() # Images_%i from headers in DB wip_images() # Images_%i from headers in DB
# Quotes
wip_quotes() # Decode B64 and convert
print(article_bottom) print(article_bottom)
#=================================# #=================================#
@ -273,3 +276,19 @@ def wip_images():
article_bottom.rsplit('\n')[ln], image_html article_bottom.rsplit('\n')[ln], image_html
) )
#
# INDEV: convert quote in article
#
def wip_quotes() :
global article_bottom
for ln, line in enumerate(article_bottom.rsplit('\n')):
if line.startswith('Q64'):
line = line.replace('Q64_', '')
line = line.replace('_Q64', '')
quote = tyto.b64('Decode', line, 'Q64_', '_Q64').rsplit("\n")
# Read the quote
for qline in quote:
print('>', qline)