예제 #1
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', '')
예제 #2
0
    def _replace(self, template, msg):
        '''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] + "..."

        image_path = escape(MarkupParser.path_to_url(msg.image_path))
        status_path = escape(MarkupParser.path_to_url(msg.status_path))

        if msg.style is not None:
            msg.message = style_message(msg.message, msg.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%', escape_no_xml(msg.message))

        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', '')
예제 #3
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', '')
예제 #4
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", "")
예제 #5
0
    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
예제 #6
0
파일: AdiumTheme.py 프로젝트: Roger/emesene
    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
예제 #7
0
    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")
        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 = "file://" + 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
예제 #8
0
    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
예제 #9
0
    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