Esempio n. 1
0
    def test_insertPrevNextText(self):
        """
        L{insertPrevNextLinks} appends a text node with the title of the
        previous slide to each node with a I{previous} class and the title of
        the next slide to each node with a I{next} class.
        """
        next = Element('span')
        next.setAttribute('class', 'next')
        container = Element('div')
        container.appendChild(next)
        slideWithNext = HTMLSlide(container, 'first', 0)

        previous = Element('span')
        previous.setAttribute('class', 'previous')
        container = Element('div')
        container.appendChild(previous)
        slideWithPrevious = HTMLSlide(container, 'second', 1)

        insertPrevNextLinks(
            [slideWithNext, slideWithPrevious], None, None)

        self.assertEqual(
            next.toxml(), '<span class="next">second</span>')
        self.assertEqual(
            previous.toxml(), '<span class="previous">first</span>')
Esempio n. 2
0
    def test_insertImages(self):
        """
        L{formulaeToImages} replaces any elements with the I{latexformula}
        class with I{img} elements which refer to external images generated
        based on the latex in the original elements.
        """
        parent = Element('div')
        base = FilePath(self.mktemp())
        base.makedirs()

        macros = Element('span')
        macros.setAttribute('class', 'latexmacros')
        text = Text()
        text.data = 'foo'
        macros.appendChild(text)
        parent.appendChild(macros)

        formula = Element('span')
        formula.setAttribute('class', 'latexformula')
        text = Text()
        text.data = 'bar'
        formula.appendChild(text)
        parent.appendChild(formula)

        # Avoid actually executing the commands to generate images from the
        # latex.  It might be nice to have some assertions about what commands
        # are executed, or perhaps even execute them and make sure an image
        # file is created, but that is a task for another day.
        commands = []
        formulaeToImages(parent, base.path, _system=commands.append)

        self.assertEqual(
            parent.toxml(),
            '<div><span><br/><img src="latexformula0.png"/><br/></span></div>')
Esempio n. 3
0
 def xml_encode(self, text):
     from xml.dom.minidom import Text, Element
     t = Text()
     t.data = text
     e = Element('x')
     e.appendChild(t)
     return e.toxml()[3:-4]
Esempio n. 4
0
    def fetch(self, output_directory='none'):

        element = Element('Water_meter001')
        element.setAttribute('Meter_Reading','%f' % self._data)
        self.output_directory.write("\r\n")
        self.output_directory.write(element.toxml())
        
        #element.toxml()
        pass
Esempio n. 5
0
    def test_insertPrevNextText(self):
        """
        L{insertPrevNextLinks} appends a text node with the title of the
        previous slide to each node with a I{previous} class and the title of
        the next slide to each node with a I{next} class.
        """
        next = Element('span')
        next.setAttribute('class', 'next')
        container = Element('div')
        container.appendChild(next)
        slideWithNext = HTMLSlide(container, 'first', 0)

        previous = Element('span')
        previous.setAttribute('class', 'previous')
        container = Element('div')
        container.appendChild(previous)
        slideWithPrevious = HTMLSlide(container, 'second', 1)

        insertPrevNextLinks([slideWithNext, slideWithPrevious], None, None)

        self.assertEqual(next.toxml(), '<span class="next">second</span>')
        self.assertEqual(previous.toxml(),
                         '<span class="previous">first</span>')
Esempio n. 6
0
    def _thread_run(self):

        logging.debug('started Thread')
        self._counter = 0
        while self._start:
            #print ('started Thread')
	    #print self._sensor_channel
            self._data = self._adc.readADCSingleEnded(0, gain, sps)/1000
            #print self._data
            if self._data > 2:
                #print self._sensor_channel
                self._counter = self._counter+1
                #print self._counter
                element = Element('PeopleCounter')
                element.setAttribute('Record','%d' % self._counter)
                element.setAttribute('Time','%f' % time.time())
                element.setAttribute('DateTime','%s' % time.strftime('%c'))            
                self.output_directory.write("\r\n")
                self.output_directory.write(element.toxml())
                logging.debug(element.toxml())
                sleep(5)
            pass
			
        pass
Esempio n. 7
0
 def render_GET(self, request):
     """
     Render as HTML a listing of all known users with links to their
     personal resources.
     """
     listing = Element('ul')
     for link, text in self._users():
         linkElement = Element('a')
         linkElement.setAttribute('href', link + '/')
         textNode = Text()
         textNode.data = text
         linkElement.appendChild(textNode)
         item = Element('li')
         item.appendChild(linkElement)
         listing.appendChild(item)
     return self.template % {'users': listing.toxml()}
Esempio n. 8
0
 def render(self, request):
     """
     Render as HTML a listing of all known users with links to their
     personal resources.
     """
     listing = Element("ul")
     for link, text in self._users():
         linkElement = Element("a")
         linkElement.setAttribute("href", link + "/")
         textNode = Text()
         textNode.data = text
         linkElement.appendChild(textNode)
         item = Element("li")
         item.appendChild(linkElement)
         listing.appendChild(item)
     return self.template % {"users": listing.toxml()}
Esempio n. 9
0
#e.appendChild(t)

#Then you will get nicely escaped XML string:

#>>> e.toxml()

if __name__ == "__main__":
  csvfile = open(sys.argv[1],'r')
  reader = csv.DictReader(csvfile,delimiter=',',strict=True,escapechar='\\')
  attributeNames = ['title','tid', 'url', 'year']
  fieldValues = dict([(fn,[]) for fn in attributeNames])
  for row in reader:
    for fn in attributeNames:
      fieldValues[fn].append(row[fn])
  csvfile.close()
  xmlfile = open('/home/orges/empfehlung/app/res/values/imdb.xml','w')
  xmlfile.write('<?xml version="1.0" encoding="utf-8"?>\n')
  xmlfile.write('<resources>\n')
  for fn in attributeNames:
    xmlfile.write('  <string-array name="%s">\n' % fn)
    for item in fieldValues[fn]:
      t = Text()
      e = Element('item')
      item = item.replace("'","\\'") #hack
      t.data = item
      e.appendChild(t)
      xmlfile.write(e.toxml()+'\n')
    xmlfile.write('</string-array>\n')
  xmlfile.write('</resources>\n')
  xmlfile.close()
        if node.localName == "add":
            # set type attribute to start and add node as a child to output
            node.setAttribute("type","start")
            open_elements.peek().appendChild(node)
        else:
            open_elements.peek().appendChild(node)
            open_elements.push(node)
    elif event == END_ELEMENT:
        # skip rdg element
        if node.localName == "rdg":
            continue
        # in case of add deal with overlapping hierarchies
        if node.localName == "add":
            # create a clone of the node and set type attribute to end and add node as a child to output
            clone = node.cloneNode(False)
            clone.setAttribute("type","end")
            open_elements.peek().appendChild(clone)
        else:
            open_elements.pop()
    elif event == CHARACTERS:
        tokens = tokenize(node.data)
        if tokens:
            textdata = "\n".join(tokens)
        else:
            textdata = re.sub("[^\S\n]+", "", node.data)
        t = Text()
        t.data = textdata
        open_elements.peek().appendChild(t)

print(output.toxml())