Пример #1
0
 def plot(self):
     g = Plot(
         dict(
             width=640,
             height=480,
             graph_title="Plot",
             show_graph_title=True,
             no_css=True,
             key=True,
             scale_x_integers=True,
             scale_y_integers=True,
             min_x_value=0,
             min_y_value=0,
             show_data_labels=True,
             show_x_guidelines=True,
             show_x_title=True,
             x_title="Time",
             show_y_title=True,
             y_title="Ice Cream Cones",
             y_title_text_direction='bt',
         ))
     # add a few random datasets
     for n in range(1, 4):
         g.add_data(
             dict(data=flatten(get_data_set()), title='series %d' % n))
     res = XML(g.burn())
     return render(chart=res)
Пример #2
0
    def filter_stream(self, req, method, filename, stream, data):
        match = re.match(r'/ticket/([0-9]+)$', req.path_info)
        if match and req.perm.has_permission('WORK_LOG'):
            ticket = int(match.group(1))
            add_stylesheet(req, "worklog/worklogplugin.css")

            add_script(req, 'worklog/jqModal.js')
            add_stylesheet(req, 'worklog/jqModal.css')

            add_script(req, 'worklog/ui.datepicker.js')
            add_stylesheet(req, 'worklog/ui.datepicker.css')

            add_script(req, 'worklog/jquery.mousewheel.pack.js')
            add_script(req, 'worklog/jquery.timeentry.pack.js')

            add_script(req, 'worklog/tracWorklog.js')

            mgr = WorkLogManager(self.env, self.config, req.authname)
            task_markup = ''
            if req.authname != 'anonymous':
                task = mgr.get_active_task()
                if task:
                    task_markup = self.get_task_markup(req, ticket, task)

            who, since = mgr.who_is_working_on(ticket)
            ticket_markup = ''
            if who:
                # If who == req.authname then we will have some text from above.
                if who != req.authname:
                    ticket_markup = self.get_ticket_markup(who, since)
            else:
                ticket_markup = self.get_ticket_markup_noone()

            button_markup = ''
            if req.authname != 'anonymous':
                if mgr.can_work_on(ticket):
                    # Display a "Work on Link" button.
                    button_markup = self.get_button_markup(req, ticket)
                elif task and task['ticket'] == ticket:
                    # We are currently working on this, so display the stop button...
                    button_markup = self.get_button_markup(req, ticket, True)

            # User's current task information
            html = XML('''
              <fieldset class="workloginfo">
                <legend>Work Log</legend>
                %s
                <ul>
                  %s
                  %s
                </ul>
              </fieldset>
              ''' % (button_markup, task_markup, ticket_markup))
            stream |= Transformer('.//div[@id="ticket"]').before(html)
        return stream
Пример #3
0
def langXML(text, lang, fragment=True, encoding=None):
    if text.startswith('<?xml ') or text.startswith('<!DOCTYPE '):
        fragment = False
    if fragment:
        text = '<xml>%s</xml>' % text
    if isinstance(text, unicode):
        encoding = 'utf-16'
        text = text.encode(encoding)
    stream = XML(text)
    lang_filter = filter_language(lang)
    if fragment:
        return stream | skip_outer | lang_filter
    else:
        return stream | lang_filter
Пример #4
0
def test_renameElement():
    """
    Check that renameElementFilter renames the root element of a stream.

    """
    xmlStream = XML(
        '''<foo xmlns="http://example.com" flub="2"><bar baz="1">fofof</bar></foo>'''
    )

    f = RenameElementFilter(QName('waze'))

    xml = (xmlStream | f).render()

    print xml

    assert xml == '<waze xmlns="http://example.com" flub="2"><bar baz="1">fofof</bar></waze>'
Пример #5
0
    def parse(self):
        """
        Read through the stringified XML and parse it into a tree of Element
        objects. This method assumes a filename was specified when the class
        constructor was called. Otherwise, there will be nothing to parse.

        A new tree of Element objects is created each time this method is
        called. This is not the way to process multiple XML files into a
        single parse tree.
        """

        if self.__xml_string == None:
            return
        else:
            self.__node_stack = list()

        for token, content, loc in XML(self.__xml_string):

            # This next line presents a problem procesing XML with special
            # formatting characters. It generates an exception. Since it is
            # only debug, we'll just comment this out until the XML is
            # updated to remove the special characters.
            #
            #            DEBUG.debug( 'token, content, loc are %s=%s %s=%s %s=%s'
            #                         % (type(token).__name__,str(token),
            #                            type(content).__name__,str(content),
            #                            type(loc).__name__,str(loc) ) )

            if token == "START":
                name = content[0]
                attr = content[1]
                self._startElement(name, attr)
            elif token == "TEXT":
                self._cData(content)
            elif token == "END":
                name = content[0]
                self._endElement(name)

        return self.__root
Пример #6
0
    def parse_file(self, filename):
        """
        Parse the specified XML file into a tree of Element objects. Since the
        objects are appended to any existing Element objects, this method can
        be used to parse multiple XML files into a single tree. Just call this
        method with each filename.
        """

        root_name_checked = False

        xml_text = self._make_string(filename)

        for token, content, loc in XML(xml_text):

            if token == "START":

                name = content[0]
                attr = content[1]

                # We are building a tree of Element objects. The issue with
                # parsing multiple files is that each XML file needs a common
                # root Element to form the top of the tree. Therefore, the
                # requirement for parsing a second file is that it has a same
                # named root Element.

                if self.__root != None and root_name_checked == False:

                    if self.__root.getName() == name:

                        # We already have a root element, and that root element
                        # has the same name as the root element in this second
                        # file. Continue with the parse.

                        # Potential issue is that doing this will not call the
                        # registered start visitor. Is that okay since we are
                        # treating it as a common node.

                        self.__node_stack.append(self.__root)

                    else:

                        # We already have a root element, but that root element
                        # name does not match the root element name from the
                        # previously parsed file. Stop since this will result
                        # in an orphaned tree branch.

                        print(
                            "XML file (%s) has invalid root name: %s (expected: %s)."
                            % (filename, name, self.__root.getName()))
                        return

                else:
                    self._startElement(name, attr)

                root_name_checked = True

            elif token == "TEXT":
                self._cData(content)

            elif token == "END":
                name = content[0]
                self._endElement(name)

        return self.__root
Пример #7
0
def to_xml(recipes):
    c = '<?xml version="1.0" encoding="ISO-8859-1"?><RECIPES>${xml}</RECIPES>'
    tmpl = MarkupTemplate(c)
    return tmpl.generate(xml=XML(''.join([r.to_xml()
                                          for r in recipes])), ).render()