Esempio n. 1
0
def get_parser(parser, fmt='html'):
	if fmt == 'raw':
		return RawParser()
	elif fmt == 'text':
		return TextParser()
	else:
		if parser == 'signature':
			parser_instance = HtmlParser(supported_tags=ONELINE_TAGS_LIST)
			parser_instance.auto_paragraphs = False
			return parser_instance
		elif parser == 'profile':
			parser_instance = HtmlParser(supported_tags=FULL_TAGS_LIST)
			parser_instance.add_nofollow = False
			return parser_instance
		elif parser == 'blog' or parser == 'full':
			parser_instance = HtmlParser(supported_tags=FULL_TAGS_LIST)
			parser_instance.auto_paragraphs = False
			return parser_instance
		elif parser == 'news_short':
			parser_instance = HtmlParser(supported_tags=DEFAULT_TAG_LIST)
			parser_instance.add_nofollow = False
			return parser_instance
		elif parser == 'news_long':
			parser_instance = HtmlParser(supported_tags=FULL_TAGS_LIST)
			parser_instance.add_nofollow = False
			return parser_instance
		else:
			return HtmlParser()
Esempio n. 2
0
def get_parser(editor_type):
	if editor_type == 'signature':
		supported_tags = copy(ONELINE_TAGS)
		supported_tags['a'] = deepcopy(supported_tags['a'])
		supported_tags['a'].req_attributes['rel'] = 'nofollow'
		supported_tags['a'].attribute_validators = {'rel': [NofollowValidator()]}
		parser = HtmlParser(supported_tags = supported_tags)
		parser.auto_paragraphs = False
		return parser
	elif editor_type == 'profile':
		supported_tags = copy(DEFAULT_TAGS)
		supported_tags['img'] = HtmlTag('img', opt_attributes=['title'], req_attributes={'src': '', 'alt': ''}, empty=True, attribute_validators = {'src': [HrefValidator()]})
		supported_tags[''] = deepcopy(supported_tags[''])
		supported_tags[''].opt.add('img')
		return HtmlParser(supported_tags = supported_tags)
	elif editor_type == 'blog':
		supported_tags = copy(FULL_TAGS)
		supported_tags['a'] = deepcopy(supported_tags['a'])
		supported_tags['a'].req_attributes['rel'] = 'nofollow'
		supported_tags['a'].attribute_validators = {'rel': [NofollowValidator()]}
		parser = HtmlParser(supported_tags=supported_tags)
		parser.auto_paragraphs = False
		return parser
	else:
		return HtmlParser()
Esempio n. 3
0
def get_parser(parser, fmt='html'): #pylint: disable=too-many-return-statements
	if fmt == 'raw':
		return RawParser()
	elif fmt == 'text':
		return TextParser()
	else:
		if parser == 'signature':
			supported_tags = copy(ONELINE_TAGS)
			supported_tags['a'] = deepcopy(supported_tags['a'])
			supported_tags['a'].req_attributes['rel'] = 'nofollow'
			supported_tags['a'].attribute_validators = {'rel': [NofollowValidator()]}
			parser_instance = HtmlParser(supported_tags=supported_tags)
			parser_instance.auto_paragraphs = False
			return parser_instance
		elif parser == 'profile':
			supported_tags = copy(DEFAULT_TAGS)
			supported_tags['img'] = HtmlTag('img', opt_attributes=['title'], req_attributes={'src': '', 'alt': ''}, empty=True, attribute_validators={'src': [HrefValidator()]})
			supported_tags[''] = deepcopy(supported_tags[''])
			supported_tags[''].opt.add('img')
			return HtmlParser(supported_tags=supported_tags)
		elif parser == 'blog' or parser == 'full':
			supported_tags = copy(FULL_TAGS)
			supported_tags['a'] = deepcopy(supported_tags['a'])
			supported_tags['a'].req_attributes['rel'] = 'nofollow'
			supported_tags['a'].attribute_validators = {'rel': [NofollowValidator()]}
			parser_instance = HtmlParser(supported_tags=supported_tags)
			parser_instance.auto_paragraphs = False
			return parser_instance
		elif parser == 'news_short':
			return HtmlParser()
		elif parser == 'news_long':
			supported_tags = copy(FULL_TAGS)
			parser_instance = HtmlParser(supported_tags=supported_tags)
			return parser_instance
		else:
			return HtmlParser()