本文整理汇总了Python中MarkupParser.urlify方法的典型用法代码示例。如果您正苦于以下问题:Python MarkupParser.urlify方法的具体用法?Python MarkupParser.urlify怎么用?Python MarkupParser.urlify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MarkupParser
的用法示例。
在下文中一共展示了MarkupParser.urlify方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pre_process_message
# 需要导入模块: import MarkupParser [as 别名]
# 或者: from MarkupParser import urlify [as 别名]
def _pre_process_message(self, contact, message, incomming, cedict, cepath, tstamp=None, mtype=None, cstyle=None):
'''Create a new gui.Message and calculates if it's first message
'''
msg = gui.Message.from_contact(contact,
message, self.first, incomming, tstamp, mtype = mtype, mstyle=cstyle)
if self.session.config.b_show_emoticons:
msg.message = MarkupParser.replace_emotes(MarkupParser.escape(msg.message),
cedict, cepath, msg.sender)
msg.message = MarkupParser.urlify(msg.message)
b_nick_check = bool(self.last_incoming_nickname != msg.display_name)
if b_nick_check:
self.last_incoming_nickname = msg.display_name
if msg.incoming:
if self.last_incoming is None:
self.last_incoming = False
msg.first = not self.last_incoming
if self.last_incoming_account != msg.sender or b_nick_check:
msg.first = True
else:
if self.last_incoming is None:
self.last_incoming = True
msg.first = self.last_incoming
return msg
示例2: replace
# 需要导入模块: import MarkupParser [as 别名]
# 或者: from MarkupParser import urlify [as 别名]
def replace(self, template, msg, style=None, cedict={}, cedir=None):
'''replace the variables on template for the values on msg
'''
msgtext = MarkupParser.replace_emotes(escape(msg.message), cedict, cedir)
msgtext = MarkupParser.urlify(msgtext)
if style is not None:
msgtext = style_message(msgtext, style)
template = template.replace('%sender%', escape(msg.alias))
template = template.replace('%senderScreenName%', escape(msg.sender))
template = template.replace('%senderDisplayName%',
escape(msg.display_name))
template = template.replace('%userIconPath%', escape(msg.image_path))
template = template.replace('%senderStatusIcon%',
escape(msg.status_path))
template = template.replace('%messageDirection%',
escape(msg.direction))
template = template.replace('%message%', msgtext)
template = template.replace('%time%',
escape(time.strftime(self.timefmt)))
template = re.sub("%time{(.*?)}%", replace_time, template)
template = template.replace('%shortTime%',
escape(time.strftime("%H:%M")))
template = template.replace('%service%', escape(msg.service))
template = template.replace('%messageClasses%', escape(msg.classes))
template = template.replace('%status%', escape(msg.status))
return template.replace('\n', '')
示例3: replace
# 需要导入模块: import MarkupParser [as 别名]
# 或者: from MarkupParser import urlify [as 别名]
def replace(self, template, msg, style=None, cedict={}, cedir=None):
'''replace the variables on template for the values on msg
'''
msg.alias = Plus.msnplus_strip(msg.alias)
msg.display_name = Plus.msnplus_strip(msg.display_name)
if(len(msg.alias) > DISPLAY_NAME_LIMIT):
msg.alias = msg.alias.decode('utf-8')[0:DISPLAY_NAME_LIMIT] + "..."
if(len(msg.display_name) > DISPLAY_NAME_LIMIT):
msg.display_name = msg.display_name.decode('utf-8')[0:DISPLAY_NAME_LIMIT] + "..."
msgtext = MarkupParser.replace_emotes(escape(msg.message), cedict, cedir, msg.sender)
msgtext = MarkupParser.urlify(msgtext)
image_path = escape(MarkupParser.path_to_url(msg.image_path))
status_path = escape(MarkupParser.path_to_url(msg.status_path))
if style is not None:
msgtext = style_message(msgtext, style)
if msg.alias:
template = template.replace('%sender%', escape(msg.alias))
else:
template = template.replace('%sender%', escape(msg.display_name))
template = template.replace('%senderScreenName%', escape(msg.sender))
template = template.replace('%senderDisplayName%',
escape(msg.display_name))
template = template.replace('%userIconPath%', image_path)
template = template.replace('%senderStatusIcon%',
status_path)
template = template.replace('%messageDirection%',
escape(msg.direction))
template = template.replace('%message%', msgtext)
if msg.timestamp is None:
template = template.replace('%time%',
escape(time.strftime("%H:%M")))
else:
def utc_to_local(t):
secs = calendar.timegm(t)
return time.localtime(secs)
l_time = utc_to_local(msg.timestamp.timetuple()) #time.struct_time
d_time = datetime.datetime.fromtimestamp(time.mktime(l_time))
template = template.replace('%time%',
escape(d_time.strftime('%x %X')))
template = re.sub("%time{(.*?)}%", replace_time, template)
template = template.replace('%shortTime%',
escape(time.strftime("%H:%M")))
template = template.replace('%service%', escape(msg.service))
template = template.replace('%messageClasses%', escape(msg.classes))
template = template.replace('%status%', escape(msg.status))
return template.replace('\n', '')
示例4: replace
# 需要导入模块: import MarkupParser [as 别名]
# 或者: from MarkupParser import urlify [as 别名]
def replace(self, template, msg, style=None, cedict={}, cedir=None):
"""replace the variables on template for the values on msg
"""
msg.alias = Plus.msnplus_strip(msg.alias)
msg.display_name = Plus.msnplus_strip(msg.display_name)
msgtext = MarkupParser.replace_emotes(escape(msg.message), cedict, cedir, msg.sender)
msgtext = MarkupParser.urlify(msgtext)
image_path = escape(MarkupParser.path_to_url(msg.image_path))
status_path = escape(MarkupParser.path_to_url(msg.status_path))
if style is not None:
msgtext = style_message(msgtext, style)
if msg.alias:
template = template.replace("%sender%", escape(msg.alias))
else:
template = template.replace("%sender%", escape(msg.display_name))
template = template.replace("%senderScreenName%", escape(msg.sender))
template = template.replace("%senderDisplayName%", escape(msg.display_name))
template = template.replace("%userIconPath%", image_path)
template = template.replace("%senderStatusIcon%", status_path)
template = template.replace("%messageDirection%", escape(msg.direction))
template = template.replace("%message%", msgtext)
if msg.timestamp is None:
template = template.replace("%time%", escape(time.strftime(self.timefmt)))
else:
def utc_to_local(t):
secs = calendar.timegm(t)
return time.localtime(secs)
l_time = utc_to_local(msg.timestamp.timetuple()) # time.struct_time
d_time = datetime.datetime.fromtimestamp(time.mktime(l_time))
template = template.replace("%time%", escape(d_time.strftime("%x %X")))
template = re.sub("%time{(.*?)}%", replace_time, template)
template = template.replace("%shortTime%", escape(time.strftime("%H:%M")))
template = template.replace("%service%", escape(msg.service))
template = template.replace("%messageClasses%", escape(msg.classes))
template = template.replace("%status%", escape(msg.status))
return template.replace("\n", "")