当前位置: 首页>>代码示例>>Python>>正文


Python MarkupParser类代码示例

本文整理汇总了Python中MarkupParser的典型用法代码示例。如果您正苦于以下问题:Python MarkupParser类的具体用法?Python MarkupParser怎么用?Python MarkupParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MarkupParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _pre_process_message

    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
开发者ID:arielj,项目名称:emesene,代码行数:31,代码来源:Conversation.py

示例2: replace

    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', '')
开发者ID:dkasak,项目名称:emesene,代码行数:30,代码来源:AdiumTheme.py

示例3: replace

    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', '')
开发者ID:imfromksa,项目名称:emesene,代码行数:54,代码来源:AdiumTheme.py

示例4: _update_single_information

    def _update_single_information(self, account):
        """set the data of the conversation to the data of the account"""
        contact = self.session.contacts.get(account)

        if contact:
            message = MarkupParser.escape(contact.message)
            nick = MarkupParser.escape(contact.display_name)
        else:
            message = ""
            nick = account

        self.update_single_information(nick, message, account)
开发者ID:xblimeyx,项目名称:emesene,代码行数:12,代码来源:Conversation.py

示例5: _update_single_information

    def _update_single_information(self, account):
        '''set the data of the conversation to the data of the account'''
        contact = self.session.contacts.safe_get(account)

        if contact.media == '':
            message = MarkupParser.escape(contact.message)
        else:
            message = MarkupParser.escape(contact.media)

        nick = MarkupParser.escape(contact.display_name)

        self.update_single_information(nick, message, account)
开发者ID:Stiveknx,项目名称:emesene,代码行数:12,代码来源:Conversation.py

示例6: _on_message

    def _on_message(self, cid, account, message, cedict=None):
        '''called when a message is received'''
        conversation = self.conversations.get(float(cid), None)

        if conversation is None:
            (exists, conversation) = self.new_conversation(cid, [account])

        contact = self.session.contacts.get(account)
        if contact:
            nick = contact.display_name
        else:
            nick = account

        if message.type == e3.Message.TYPE_MESSAGE:
            (is_raw, consecutive, outgoing, first, last) = \
                conversation.formatter.format(contact)

            middle = MarkupParser.escape(message.body)
            if not is_raw:
                middle = self.format_from_message(message)

            conversation.output.append(first + middle + last, cedict,self.session.config.b_allow_auto_scroll)
            conversation.play_send()

        elif message.type == e3.Message.TYPE_NUDGE:
            conversation.output.append(
                conversation.formatter.format_information(
                    '%s just sent you a nudge!' % (nick,)),self.session.config.b_allow_auto_scroll)
            conversation.play_nudge()

        if message.type != e3.Message.TYPE_TYPING:
            self.set_message_waiting(conversation, True)
开发者ID:DarKprince,项目名称:emesene2,代码行数:32,代码来源:ConversationManager.py

示例7: add_style_to_message

def add_style_to_message(text, stl, escape=True):
    '''add the style in a xhtml like syntax to text'''
    style_start = ''
    style_end = ''
    style = 'color: #' + stl.color.to_hex() + ';'

    if stl.bold:
        style_start = style_start + '<b>'
        style_end = '</b>' + style_end

    if stl.italic:
        style_start = style_start + '<i>'
        style_end = '</i>' + style_end

    if stl.underline:
        style_start = style_start + '<u>'
        style_end = '</u>' + style_end

    if stl.strike:
        style_start = style_start + '<s>'
        style_end = '</s>' + style_end

    if stl.font:
        style += 'font-family: ' + stl.font

    style_start += '<span style="%s; ">' % (style, )
    style_end = '</span>' + style_end

    if escape:
        text = MarkupParser.escape(text)

    return style_start + text + style_end
开发者ID:Otacon,项目名称:emesene,代码行数:32,代码来源:utils.py

示例8: _on_send_message

    def _on_send_message(self, text, cedict=None):
        '''method called when the user press enter on the input text'''
        self.session.send_message(self.cid, text, self.cstyle)
        nick = self.session.contacts.me.display_name

        (is_raw, consecutive, outgoing, first, last) = \
            self.formatter.format(self.session.contacts.me)

        if is_raw:
            middle = MarkupParser.escape(text)
        else:
            middle = MarkupParser.escape(text)
            middle = e3.common.add_style_to_message(middle, self.cstyle, False)

        all = first + middle + last
        self.output.append(all, cedict,self.session.config.b_allow_auto_scroll)
        self.play_type()
开发者ID:DarKprince,项目名称:emesene2,代码行数:17,代码来源:Conversation.py

示例9: replace

    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", "")
开发者ID:Roger,项目名称:emesene,代码行数:45,代码来源:AdiumTheme.py

示例10: on_contact_left

    def on_contact_left(self, account):
        '''called when a contact leaves the conversation'''
        if len(self.members) > 1 and account in self.members:
            self.members.remove(account)
            self.update_data()
            contact = self.session.contacts.safe_get(account)
            message = e3.base.Message(e3.base.Message.TYPE_MESSAGE, \
            _('%s has left the conversation') % (MarkupParser.escape(contact.display_name)), \
            account)
            msg = gui.Message.from_information(contact, message)

            self.output.information(msg)
            self.conv_status.post_process_message(msg)
开发者ID:Smile4ever,项目名称:emesene,代码行数:13,代码来源:Conversation.py

示例11: on_contact_joined

    def on_contact_joined(self, account):
        '''called when a contact joins the conversation'''
        if account not in self.members:
            self.members.append(account)
            contact = self.session.contacts.safe_get(account)
            if len(self.members) > 1:
                message = e3.base.Message(e3.base.Message.TYPE_MESSAGE, \
                _('%s has joined the conversation') % (MarkupParser.escape(contact.display_name)), \
                account)
                msg = gui.Message.from_information(contact, message)

                self.output.information(msg)
                self.conv_status.post_process_message(msg)

        self.update_data()
开发者ID:Smile4ever,项目名称:emesene,代码行数:15,代码来源:Conversation.py

示例12: on_receive_message

    def on_receive_message(self, message, account, received_custom_emoticons):
        '''method called when a message arrives to the conversation'''
        for callback in self.session.cb_gui_recv_message.sorted():
            callback(message)

        contact = self.session.contacts.safe_get(account)

        if message.type == e3.Message.TYPE_MESSAGE or \
           message.type == e3.Message.TYPE_FLNMSG:

            if self.session.config.b_override_text_color:
                message.style.color = \
                e3.base.Color.from_hex(self.session.config.override_text_color)

            user_emcache = self.caches.get_emoticon_cache(account)

            #XXX: when we send messages from the web iface we get those here, so show them propertly
            if contact.account == self.session.contacts.me.account:
                self.output_message(message, None)
                return

            self.input_message(message, contact,
                               received_custom_emoticons, user_emcache.path)

            self.play_type()

        elif message.type == e3.Message.TYPE_NUDGE:
            message.body = _('%s just sent you a nudge!') % (MarkupParser.escape(contact.display_name),)
            msg = gui.Message.from_information(contact, message)

            self.output.information(msg)
            self.conv_status.post_process_message(msg)

            self.play_nudge()

        elif message.type == e3.Message.TYPE_INFO:
            msg = gui.Message.from_information(contact, message)

            self.output.information(msg)
            self.conv_status.post_process_message(msg)

        elif message.type == e3.Message.TYPE_PICTURE:
            msg = gui.Message.from_contact(contact, message)

            self.output.information(msg)
            self.conv_status.post_process_message(msg)

        self.conv_status.update_status()
开发者ID:RealDoll,项目名称:emesene,代码行数:48,代码来源:Conversation.py

示例13: get_body

    def get_body(self, source, target, target_display, source_img, target_img):
        '''return the template to put as html content
        '''
        #first try load custom Template.html from theme
        path = urljoin(self.resources_path, 'Template.html')
        if not os.path.exists(path):
            path = urljoin("gui", "base", "template.html")
        template = read_file(path)
        resources_url = MarkupParser.path_to_url(self.resources_path)
        css_path = urljoin(resources_url, "main.css")

        if self.variant:
            variant_name = self.variant
        else:
            variant_name = self.info.get('DefaultVariant', None)
        template = template.replace("%@", resources_url + "/", 1)
        template = template.replace("%@", css_path, 1)

        if variant_name is not None:
            variant_css_path = urljoin(resources_url,
                    "Variants", variant_name + ".css")
            variant_tag = '<style id="mainStyle" type="text/css"' + \
                'media="screen,print">	@import url( "' + variant_css_path + '" ); </style>'
        else:
            variant_tag = ""

        template = template.replace("%@", variant_tag, 1)

        header = read_file(self.resources_path, 'Header.html') or ""

        if header:
            header = self.replace_header_or_footer(header, source, target,
                    target_display, source_img, target_img)

        template = template.replace("%@", header, 1)
        footer = read_file(self.resources_path, 'Footer.html') or ""

        if footer:
            footer = self.replace_header_or_footer(footer, source, target,
                    target_display, source_img, target_img)

        template = template.replace("%@", footer, 1)

        return template
开发者ID:19MiRkO91,项目名称:emesene,代码行数:44,代码来源:AdiumTheme.py

示例14: get_body

    def get_body(self, source, target, target_display, source_img, target_img):
        """return the template to put as html content
        """
        # first try load custom Template.html from theme
        path = urljoin(self.resources_path, "Template.html")
        if not os.path.exists(path):
            path = urljoin("gui", "base", "template.html")
        template = read_file(path)
        resources_url = MarkupParser.path_to_url(self.resources_path)
        css_path = urljoin(resources_url, "main.css")

        template = template.replace("%@", resources_url + "/", 1)
        template = template.replace("%@", css_path, 1)

        if self.variant is not None:
            variant_css_path = urljoin(resources_url, "Variants", self.variant + ".css")
            variant_tag = (
                '<style id="mainStyle" type="text/css"'
                + 'media="screen,print">	@import url( "'
                + variant_css_path
                + '" ); </style>'
            )
        else:
            variant_tag = ""

        template = template.replace("%@", variant_tag, 1)

        target = Plus.msnplus_strip(target)
        target_display = Plus.msnplus_strip(target_display)

        header = read_file(self.resources_path, "Header.html") or ""

        if header:
            header = self.replace_header_or_footer(header, source, target, target_display, source_img, target_img)

        template = template.replace("%@", header, 1)
        footer = read_file(self.resources_path, "Footer.html") or ""

        if footer:
            footer = self.replace_header_or_footer(footer, source, target, target_display, source_img, target_img)

        template = template.replace("%@", footer, 1)

        return template
开发者ID:Roger,项目名称:emesene,代码行数:44,代码来源:AdiumTheme.py

示例15: get_body

    def get_body(self, source, target, target_display, source_img, target_img):
        '''return the template to put as html content
        '''
        template = self.template
        resources_url = MarkupParser.path_to_url(self.resources_path)
        css_path = urljoin(resources_url, "main.css")

        template = template.replace("%@", resources_url + "/", 1)
        template = template.replace("%@", css_path, 1)

        if self.variant is not None:
            variant_css_path = urljoin(resources_url,
                    "Variants", self.variant + ".css")
            variant_tag = '<style id="mainStyle" type="text/css"' + \
                'media="screen,print">	@import url( "' + variant_css_path + '" ); </style>'
        else:
            variant_tag = ""

        template = template.replace("%@", variant_tag, 1)

        target = Plus.msnplus_strip(target)
        target_display = Plus.msnplus_strip(target_display)

        header = self.header

        if header:
            header = self._replace_header_or_footer(header, source, target,
                    target_display, source_img, target_img)

        template = template.replace("%@", header, 1)

        footer = self.footer
        if footer:
            footer = self._replace_header_or_footer(footer, source, target,
                    target_display, source_img, target_img)

        template = template.replace("%@", footer, 1)

        return template
开发者ID:Hangman228,项目名称:emesene,代码行数:39,代码来源:AdiumTheme.py


注:本文中的MarkupParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。