Example #1
0
    def do_latex_xml(self, doc_node):

        preamble = []
        macros = []

        for node in doc_node.childNodes:
            name = node.nodeName

            if name == "macros":
                for child in node.childNodes:
                    if child.nodeName == "file":
                        source = child.firstChild.data.strip()
                        try:
                            macros_file = toolbox.openAnything(source)
                            macros.append(macros_file.read())
                            macros_file.close()
                        except:
                            print "error in opening macro file."
                    else:
                        if child.nodeName == "#text":
                            stripped = child.data.strip()
                            if len(stripped) > 0:
                                macros.append(stripped)

            if name == "preamble":
                for child in node.childNodes:
                    if child.nodeName == "file":
                        source = child.firstChild.data.strip()
                        try:
                            preamble_file = toolbox.openAnything(source)
                            preamble.append(preamble_file.read())
                            preamble_file.close()
                        except:
                            print "error in opening preamble file."
                    else:
                        if child.nodeName == "#text":
                            stripped = child.data.strip()
                            if len(stripped) > 0:
                                preamble.append(stripped)

        if len(macros) == 0:
            macros_file = toolbox.openAnything(default_macros)
            macros.append(macros_file.read())
            macros_file.close()

        if len(preamble) == 0:
            preamble_file = toolbox.openAnything(default_preamble)
            preamble.append(preamble_file.read())
            preamble_file.close()

        self.tex_lines.extend(preamble)
        self.tex_lines.extend(macros)

        for node in doc_node.childNodes:
            name = node.nodeName
            if name == "document":
                self.parse(node)
Example #2
0
 def _load(self, source):
     """load XML input source, return parsed XML document
     """
     sock = toolbox.openAnything(source)
     xmldoc = minidom.parse(sock).documentElement
     sock.close()
     return xmldoc
Example #3
0
	def __init__(self,filename=None):
		if not filename :
			print "Error : filename is nessary"
		else:
			sock = toolbox.openAnything( filename )
			self.xml = minidom.parse( sock )
			sock.close()
			if not self.xml :
				print "Error : file is not exists"
				exit()
Example #4
0
 def _load(self, source):
     '''load XML input source, return parsed XML document
     - a URL of remote XML file ('http://divintopython.org/kant.xml')
     - a filename of a local XML file('~/divintopytho/py/kant.xml')
     - standard input('-')
     - the actual XML document, as a string
     '''
     sock = toolbox.openAnything(source)
     xmldoc = minidom.parse(sock).documentElement
     sock.close()
     return xmldoc
 def _load(self, source):
     """load XML input source, return parsed XML document
         − a URL of a remote XML file ("http://diveintopython.org/kant.xml")
         − a filename of a local XML file ("~/diveintopython/common/py/kant.xml")
         − standard input ("−")
         − the actual XML document, as a string
     """
     sock = toolbox.openAnything(source)
     xmldoc = minidom.parse(sock).documentElement
     sock.close()
     return xmldoc
Example #6
0
 def _load(self, source):
     '''load XML input source, return parsed XML document
     -a URL of a remote XML file ("http://diveintopythonorg/kant.xml")
     -a filename of local XML file ("/diveintopython/common/py/kant.xml")
     - standard input ("-")
     - the actual XML document, as a string
     '''
     sock = toolbox.openAnything(source)
     xmldoc = minidom.parse(sock).documentElement
     sock.close()
     return xmldoc
Example #7
0
 def _load(self, source):
     """load XML input source, return parsed XML document
         − a URL of a remote XML file ("http://diveintopython.org/kant.xml")
         − a filename of a local XML file ("~/diveintopython/common/py/kant.xml")
         − standard input ("−")
         − the actual XML document, as a string
     """
     sock = toolbox.openAnything(source)
     xmldoc = minidom.parse(sock).documentElement
     sock.close()
     return xmldoc
Example #8
0
    def __init__(self, input, asfile=True, aslines=False):
        asfile = not aslines

        # parse input
        if asfile is True:
            sock = toolbox.openAnything(input)
            self.xmldoc = minidom.parse(sock).documentElement
            sock.close()
        elif aslines is True:

            inp = StringIO.StringIO("\n".join(input))
            self.xmldoc = minidom.parse(inp)
Example #9
0
 def _load(self, source):
     """XML input source can be:
     - a URL of a remote XML file        ("http://.../grammar.xml")
     - a filename of a local XML file    ("~/.../grammar.xml")
     - standard input                    ("-")
     - the actual XML, as a string       ("<choice><s>Dog</s><s>Cat</s></choice>")
     """
     try:
         sock = toolbox.openAnything(source)
         xmldoc = minidom.parse(sock).documentElement
         sock.close()
     except:
         print "There is an error in the grammar file \"" + source + "\""
         sys.exit(2)
     return xmldoc
Example #10
0
def localsearch():
    param = urllib.urlencode({'key':app.config['NAVER_APIKEY'], 'target':'local', 'query':request.form['key'].encode('utf-8')})
    sock = toolbox.openAnything('http://openapi.naver.com/search?' + param)
    xmldoc = minidom.parse(sock)
    sock.close()
    nodes = xmldoc.getElementsByTagName('item')
    res = []
    dg = ""
    for item in nodes:
        tmp = item.childNodes
        #res.append(tmp.length)
        n_title = tmp[0].firstChild.nodeValue
        n_desc = tmp[2].firstChild.nodeValue if tmp[2].hasChildNodes()==True else ""
        n_tel = tmp[3].hasChildNodes() and tmp[3].firstChild.nodeValue or ""
        n_addr = tmp[4].hasChildNodes() and tmp[4].firstChild.nodeValue or ""
        n_x = tmp[5].firstChild.nodeValue
        n_y = tmp[6].firstChild.nodeValue
        res.append({'title':n_title, 'desc':n_desc, 'tel':n_tel, 'addr':n_addr, 'x':n_x, 'y':n_y})
    xmldoc.unlink()
    return json.dumps(res)
Example #11
0
File: ch10.py Project: mamund/dip
ssock.seek(0)
print ssock.read(15)
print ssock.read()
ssock.close()

#pg 201
ssock = StringIO.StringIO(contents)
xmldoc = minidom.parse(ssock)
ssock.close()
print xmldoc.toxml()

#pg 202
print "-- openAnything --"
import toolbox

sock = toolbox.openAnything("http://amundsen.com/blog/feed/")
xmldoc = minidom.parse(sock)
sock.close()
print xmldoc.toxml()

#pg 203
for i in range(3):
  print 'Dive In'

import sys
for i in range(3):
  sys.stdout.write('Dive In\n')

for i in range(3):
  sys.stderr.write('Dive In\n')
Example #12
0
    if output_fname[l-4:l] == ".pre":
        output_fname = output_fname[0:l-4]
    
    tex_fname = output_fname + ".tex"
    output_fname += ".pdf"

output_fname_root, dummy = os.path.splitext(output_fname) 


# Parse to xml:

import genXml
import toolbox


input_file = toolbox.openAnything(input_fname)
input_lines = input_file.readlines()
input_file.close()

xml_lines, xml_line_numbers = genXml.to_xml(input_lines)

if options.debug_xml is True:
    print "\n"
    for num, line in enumerate(xml_lines):
        print str(num+1) + ': ', line
    print "\n"


# Parse to tex

import xml2tex
Example #13
0
        print(line)
        print(l.encode('ISO-8859-1'))
    if i > 200:
        break
    # if len(str([l])) > 1:
    #     print([l])
    i += 1

# print(contents[158].encode('gb2312'))
# print(contents.encode('gb2312'))


exit()


fsock = openAnything("binary.xml")
xmldoc = minidom.parse(fsock).documentElement

fsock.close()
print(xmldoc.getAttributeNS)
print(xmldoc.toxml())
exit()
print("\n".join(dir(xmldoc)))
exit()
i = 0
while False:
    sock = urllib.urlopen("http://www.yii2cms.com")
    htmlSource = sock.read()
    sock.close()
    if not i:
        break