Beispiel #1
0
def message_template_to_kpm(template):
	files = []
	cursor = 0
	match = True
	while match:
		match = KPM_INLINE_IMAGE_REGEXP.search(template[cursor:])
		if not match:
			break
		file_path = unescape_single_quote(match.group(1)[1:-1])
		files.append(file_path)
		file_name = os.path.basename(file_path)
		start = cursor + match.start()
		end = cursor + match.end()
		inline_tag = "{{{{ inline_image('{0}') }}}}".format(escape_single_quote(file_name))
		template = template[:start] + inline_tag + template[end:]
		cursor = start + len(inline_tag)
	return template, files
Beispiel #2
0
def message_template_to_kpm(template):
	files = []
	cursor = 0
	match = True
	while match:
		match = KPM_INLINE_IMAGE_REGEXP.search(template[cursor:])
		if not match:
			break
		file_path = unescape_single_quote(match.group(1)[1:-1])
		files.append(file_path)
		file_name = os.path.basename(file_path)
		start = cursor + match.start()
		end = cursor + match.end()
		inline_tag = "{{{{ inline_image('{0}') }}}}".format(escape_single_quote(file_name))
		template = template[:start] + inline_tag + template[end:]
		cursor = start + len(inline_tag)
	return template, files
Beispiel #3
0
def message_template_from_kpm(template, files):
	files = dict(zip(map(os.path.basename, files), files))
	cursor = 0
	match = True
	while match:
		match = KPM_INLINE_IMAGE_REGEXP.search(template[cursor:])
		if not match:
			break
		file_name = unescape_single_quote(match.group(1)[1:-1])
		file_path = files.get(file_name)
		start = cursor + match.start()
		end = cursor + match.end()
		if not file_path:
			cursor = end
			continue
		insert_tag = "{{{{ inline_image('{0}') }}}}".format(escape_single_quote(file_path))
		template = template[:start] + insert_tag + template[end:]
		cursor = start + len(insert_tag)
	return template
Beispiel #4
0
def message_template_from_kpm(template, files):
	files = dict(zip(map(os.path.basename, files), files))
	cursor = 0
	match = True
	while match:
		match = KPM_INLINE_IMAGE_REGEXP.search(template[cursor:])
		if not match:
			break
		file_name = unescape_single_quote(match.group(1)[1:-1])
		file_path = files.get(file_name)
		start = cursor + match.start()
		end = cursor + match.end()
		if not file_path:
			cursor = end
			continue
		insert_tag = "{{{{ inline_image('{0}') }}}}".format(escape_single_quote(file_path))
		template = template[:start] + insert_tag + template[end:]
		cursor = start + len(insert_tag)
	return template
Beispiel #5
0
 def test_unescape_single_quote(self):
     unescaped_string = utilities.unescape_single_quote(
         SINGLE_QUOTE_STRING_ESCAPED)
     self.assertEqual(unescaped_string, SINGLE_QUOTE_STRING_UNESCAPED)
	def test_unescape_single_quote(self):
		unescaped_string = utilities.unescape_single_quote(SINGLE_QUOTE_STRING_ESCAPED)
		self.assertEqual(unescaped_string, SINGLE_QUOTE_STRING_UNESCAPED)