예제 #1
0
    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
0
    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
0
    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
0
    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, 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)

        plus_parser = Plus.MsnPlusMarkupMohrtutchy()

        if msg.alias:
            template = template.replace(
                '%sender%', escape(plus_parser.removeMarkup(msg.alias)))
        else:
            template = template.replace(
                '%sender%', escape(plus_parser.removeMarkup(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', '')
예제 #5
0
    def pre_process_message(self,
                            contact,
                            message,
                            incomming,
                            cedict,
                            cepath,
                            tstamp=None,
                            mtype=None,
                            cstyle=None):
        '''Create a new gui.Message
        '''
        msg = gui.Message.from_contact(contact,
                                       message,
                                       self.first,
                                       incomming,
                                       tstamp,
                                       mtype=mtype,
                                       mstyle=cstyle)

        msg.message = MarkupParser.escape(msg.message)
        if self.config.b_show_emoticons:
            msg.message = MarkupParser.replace_emotes(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
예제 #6
0
파일: AdiumTheme.py 프로젝트: Roger/emesene
    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", "")