当前位置: 首页>>代码示例>>Python>>正文


Python XMLWriter.close方法代码示例

本文整理汇总了Python中elementtree.SimpleXMLWriter.XMLWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Python XMLWriter.close方法的具体用法?Python XMLWriter.close怎么用?Python XMLWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elementtree.SimpleXMLWriter.XMLWriter的用法示例。


在下文中一共展示了XMLWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: persist

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
    def persist(self):
        # Create an xml 
        outs = cStringIO.StringIO()
        w = XMLWriter(outs)
        root = w.start("parsedlog", submitter=self.__submitter)
        #self.parser.asXml(w)
        self.loot.asXml(w)
        self.attendance.asXml(w)
        self.kills.asXml(w)
        w.close(root)

        # Stuff the xml into an http post
        headers = {"Content-type": "application/xml",
                   "Accept": "text/plain"}

        #conn = httplib.HTTPConnection('beauty.quonic.net')
        #conn.request("POST", "/~erik/eqlogdb/submit.psp", outs.getvalue())
        conn = httplib.HTTPConnection('beauty.quonic.net')
        conn.request("POST", "/~erik/eqlogdb/submit.psp", outs.getvalue())
        response = conn.getresponse()
        if response.status == 200:
                self.loot.clear()
                self.attendance.clear()
                self.kills.clear()
        print response.read()
        conn.close()
开发者ID:easel,项目名称:gamestats,代码行数:28,代码来源:logparse.py

示例2: create_gpx

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def create_gpx(track, positions):
    f = StringIO()
    w = XMLWriter(f, 'utf-8')

    gpx = w.start('gpx', creator='Gypsum', version='1.1')

    w.start('trk')
    w.start('name')
    w.data(track.__unicode__())
    w.end('name')

    w.start('trkseg')

    for p in positions:
        w.start('trkpt', lat=str(p.latitude), lon=str(p.longitude))

        if p.altitude != None:
            w.start('ele')
            w.data(str(p.altitude))
            w.end('ele')
        w.start('time')
        w.data(datetime.datetime.strftime(p.time, '%Y-%m-%dT%H:%M:%S.%fZ'))
        w.end('time')

        w.end('trkpt')

    w.end('trkseg')

    w.end('trk')

    w.close(gpx)

    return f.getvalue()
开发者ID:patsy,项目名称:gypsum,代码行数:35,代码来源:gpxparser.py

示例3: createMetadata

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def createMetadata(item_ID):
	# get number of files
	images = os.listdir("/processing/"+item_ID+"/images")
	leaf_count = len(images) - 1 #accounts for /thumbs directory in there		

	# get dimensions of cover and create cover image
	cover_path = Template('/processing/$item_ID/images/$item_ID').substitute(item_ID=item_ID) + "00001.jpg"
	im = Image.open(cover_path)
	width, height = im.size #returns tuple

	# generate cover thumbnail
	max_cover_width = 200
	max_cover_height = 200
	im.thumbnail((max_cover_width, max_cover_height), Image.ANTIALIAS)				
	im.save(Template('/processing/$item_ID/$item_ID').substitute(item_ID=item_ID) + "_cover.jpg")
	print "Cover created for",item_ID	

	# write to xml
	fhand = Template("/processing/$item_ID/$item_ID$suffix.xml").substitute(item_ID=item_ID, suffix="_metadata")
	w = XMLWriter(fhand, "utf-8")

	metadata = w.start("add")
	w.start("doc")
	w.element("field", Template("meta:$item_ID").substitute(item_ID=item_ID), name="id") 
	w.element("field", Template("$item_ID").substitute(item_ID=item_ID), name="ItemID") #no underscore for solr index in "ItemID"
	#creats overall ratio - height / width
	w.element("field", str(height), name="pheight")
	w.element("field", str(width), name="pwidth")
	w.element("field", str(leaf_count), name="leafs")
	w.element("field", Template("$item_ID").substitute(item_ID=item_ID), name="item_title") #how will we generate this? ItemID for now... 
	w.end() #closes <doc>

	w.close(metadata)
开发者ID:ghukill,项目名称:fedora_utilities,代码行数:35,代码来源:WSU-PDF_process_incoming_to_Fedora_152.py

示例4: project_save1

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def project_save1(tree):
    f = open('resar.xml', 'w')
    w = XMLWriter(f)
    html = w.start("data")
    w.element("empresa", '"' + tree.GetItemText(tree.GetRootItem(), 0) + '"')
    w.start('items')

    def printChildren(tree, treeItem):
        subItem = tree.GetFirstChild(treeItem)[0]
        name = tree.GetItemText(treeItem, 1)
        index = tree.GetItemText(treeItem, 0)
        try:
            parent = tree.GetItemText(tree.GetItemParent(treeItem), 1)
        except Exception:
            parent = 'root'

        if not subItem.IsOk():
            w.element("item", nombre=name, indice=index, parent=parent)

        else:
            w.element("item", nombre=name, indice=index, parent='root')

        while subItem.IsOk():
            printChildren(tree, subItem)
            subItem = tree.GetNextSibling(subItem)

    printChildren(tree, tree.GetRootItem())
   
    w.end('items')
    w.close(html)
    f.close()
开发者ID:moqca,项目名称:Legajos,代码行数:33,代码来源:project_handle.py

示例5: installerLog

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def installerLog(package_details):
    '''
    This module writes the required fields of a package to a temporary 
    XML file which is then appended to the list of installedLog.xml.
    Right now - only name and version written to the installedLog.xml.
    '''
    
    #package_details contain all the info about the package
    w = XMLWriter('tempholder.xml')
    xml = w.start("xml")
    w.start("Package")
    w.element("name", package_details[0])
    w.element("version", package_details[1])
    #w.element("architecture", package_details[2])
    #w.element("short-description",package_details[3])
    #w.element("installed",package_details[4])
    #w.element("long-description",package_details[4])
    #-----^basic logging data above^------
    #w.element("section",package_details[5])
    #w.element("installed-size",package_details[6])
    #w.element("maintainer",package_details[7])
    #w.element("original-maintainer",package_details[8])
    #w.element("replaces",package_details[9])
    #w.element("provides",package_details[10])
    #w.element("pre-depends",package_details[11])
    #w.element("depends",package_details[5])
    #w.element("recomends",package_details[13])
    #w.element("suggests",package_details[14])
    #w.element("conflicts",package_details[15])
    #w.element("filename",package_details[16])
    #w.element("size",package_details[17])
    #w.element("md5sum",package_details[18])
    #w.element("homepage",package_details[19])
    w.end()
    w.close(xml)
开发者ID:pombredanne,项目名称:winlibre_pm,代码行数:37,代码来源:installerXMLLog.py

示例6: process

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
    def process(self, args):
        # Perform any base class processing.
        if not super(NfoProcess, self).process(args):
            return

        # If we don't have an output parameter, we figure it out from
        # the input filename.
        output = args.output

        if not output:
            output = os.path.splitext(args.tmdb)[0] + ".nfo"

        # Check to see if the file exists.
        if os.path.isfile(output) and not args.force:
            print "Cannot overwrite file: " + output
            return False

        # Open up the output file.
        xml = open(output, 'w')
        xml.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")

        w = XMLWriter(xml, 'utf-8')
        tag = w.start("movie", ThumbGen="1")
        w.element("hasrighttoleftdirection", "false")
        w.element("title", self.movie['title'])
        w.element("originaltitle", self.movie['original_title'])
        w.element("filename", os.path.splitext(args.tmdb)[0] + ".mp4")
        w.element("tagline", self.movie['tagline'])
        w.element("releasedate", self.movie['release_date'])
        w.element("id", self.movie['imdb_id'])
        w.element("runtime", format(self.movie['runtime']))
        w.element("plot", self.movie['overview'])

        # Write out the genres.
        w.start("genre")

        for genre in self.movie['genres']:
            w.element("name", genre['name'])

        w.end()

        # Media information
        w.start("mediainfo")
        w.start("Resolution")
        w.element("Flag", "Resolution_480p")
        w.end()
        w.element("resolution", "480P")
        w.end()

        # Finish up the document.
        w.end()
        w.close(tag)
        xml.close()

        # Report that we created the file.
        self.log.info("Created " + output)
开发者ID:dmoonfire,项目名称:mfgames-media-python,代码行数:58,代码来源:themoviedb.py

示例7: asXml

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
 def asXml(self):
     outs = cStringIO.StringIO()
     w = XMLWriter(outs)
     root = w.start("parsedlog", submitter=self.myname)
     self.fights.asXml(w)
     self.loot.asXml(w)
     self.attendance.asXml(w)
     self.kills.asXml(w)
     w.close(root)
     return str(outs.getvalue())
开发者ID:easel,项目名称:gamestats,代码行数:12,代码来源:parser.py

示例8: post

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def post():
   try:
      d = request.form['thedata']
      ds = json.loads(d)['activity']
      stime = ds['startTimeUtc']
      stime = dateutil.parser.parse(stime)
      points = ds['geo']['waypoints']
      name = ds['name']

      f = StringIO.StringIO()
      w = XMLWriter(f)
      gpx_attribs = {"version":"1.1",
                        "creator":"unrealduck.com",
                        "xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
                        "xmlns:gpxtpx":"http://www.garmin.com/xmlschemas/TrackPointExtension/v1",
                        "xmlns":"http://www.topografix.com/GPX/1/1",
                        "xsi:schemaLocation":"http://www.topografix.com/GPX/1/1 http://www.topografix.com/gpx/1/1/gpx.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"}
      gpx = w.start("gpx", gpx_attribs)
      w.start("metadata")
      w.element("name", name)
      w.element("time", str(stime).replace(" ", "T"))
      w.element("desc", "Import from nikeplus.com")
      w.end()

      w.start("trk")
      w.element("name", name)
      w.start("trkseg")

      for i,pt in zip(range(len(points)), points):            
         time = stime + datetime.timedelta(seconds=i)
         w.start("trkpt", lon=str(pt['lon']), lat=str(pt['lat']))
         w.element("ele", str(pt['ele']))
         w.element("time", str(time).replace(" ", "T"))
         w.end()
                     
      w.end()
      w.end()
         
      w.close(gpx)

      filename = '_'.join([ds['activityType'], ds['deviceType'], str(stime.date()), str(stime.time())])
      response = make_response("<?xml version=\"1.0\" ?>"+f.getvalue())
      response.headers['Content-Type'] = 'application/gpx+xml'         
      response.headers['Content-Disposition'] = 'attachment; filename='+filename+'.gpx'                 
      return response
      
   except KeyError:
      print "KeyError"
      return make_response("KeyError")
   except:
      print "UnexpectedError"
      print sys.exc_info()[0]
      return make_response("Unexpected error")
开发者ID:jussini,项目名称:np2gpx,代码行数:55,代码来源:np2gpx.py

示例9: create_project

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def create_project(name, path, template=None):
    os.mkdir(path)
    os.mkdir(os.path.join(path, 'bin'))
    os.mkdir(os.path.join(path, 'contabilidad'))
    os.mkdir(os.path.join(path, 'documentos'))
    f = open(os.path.join(path, 'bin','empresa.xml'), 'w')
    w = XMLWriter(f)
    html = w.start("data")
    w.element("empresa", '"' + name + '"')
    w.start('items')
    w.element('item', nombre=name, indice='', parent='root')
    w.end('items')
    w.close(html)
    f.close()
开发者ID:moqca,项目名称:Legajos,代码行数:16,代码来源:project_handle.py

示例10: run1

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def run1():
	x = XMLWriter("test.xml")

	musicLibrary = x.start("musciLibrary")

	x.start("song")
	x.element("id", "2")
	x.element("title", "Jigga What/Faint")
	x.element("artist", "Linkin Park/Jay Z")
	x.element("year", "2004")
	x.element("trackNumber", "3")
	x.element("totalTracks", "6")
	x.element("genre", "Rap/Nu Metal")
	x.end("song")
	x.close(musicLibrary)
开发者ID:atdalman,项目名称:music-stats,代码行数:17,代码来源:parseXML.py

示例11: tagcloudxml

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def tagcloudxml(request):
    xml = cStringIO.StringIO()
    w = XMLWriter(xml)
    tags = w.start("tags")
    for tag in tagcloud():
        w.element("a",
            text=tag['tag'],
            attrs={'href': "http://www.bhamtechevents.org/browse_events/%s".format(tag['tag']),
                   'title': "%s topics".format(tag["count"]), 'rel': "tag",
                   'style': "font-size: %s".format(tag["size"])}
        )
    w.end()
    w.close(tags)
    w.flush()
    return HttpResponse(xml.read())
开发者ID:Nonpython,项目名称:BHamTechEvents,代码行数:17,代码来源:shared.py

示例12: write_keymap

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def write_keymap(keymap, filename):
  contexts = list(set([ c for c,a,k in keymap ]))
  actions  = list(set([ a for c,a,k in keymap ]))
  
  w = XMLWriter(filename, "utf-8")
  doc = w.start("keymap")
  
  for context in contexts:
    w.start(context)
    w.start("keyboard")
    for c,a,k in keymap:
      if c==context:
        w.element("key", a, id=k)
    w.end()
    w.end()
  w.end()
  w.close(doc)
开发者ID:curtisgibby,项目名称:xbmc-addon-keymap-config,代码行数:19,代码来源:io.py

示例13: _record_key

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def _record_key():
    	dialog = KeyListener()
    	dialog.doModal()
    	key = dialog.key
    	del dialog
	w = XMLWriter(twitter_file, "utf-8")
	doc = w.start("keymap")
	w.start("global")
	w.start("keyboard")
        w.element("key", "addon.opensettings(script.service.twitter)", id=str(key))
	w.end()
	w.end()
	w.start("fullscreenvideo")
	w.start("keyboard")
	w.element("key", "addon.opensettings(script.service.twitter)", id=str(key))
	w.end()
	w.end()
	w.end()
	w.close(doc)
开发者ID:Romans-I-XVI,项目名称:script.service.twitter,代码行数:21,代码来源:default.py

示例14: intWriter

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def intWriter(path, camMat, distCoe, calibError={}):
    try:
        print 'Generating Intrinsic Parameters to:', path, '...'
        with open(path, 'w') as int_xml:
            w = XMLWriter(int_xml)
            w.declaration()
            
            # Camera Intrinsic (Root)
            root = w.start('StdIntrinsic')
            
            # Camera Matrix
            w.element('CamMat',
                     fx=str(camMat[0][0]), fy=str(camMat[1][1]),
                     cx=str(camMat[0][2]), cy=str(camMat[1][2]))
            
            # Distortion Coefficients
            if (len(distCoe[0]) == 8): # 8 coefficients Rational Model, k4 k5 k6 enabled
                w.element('DistCoe', k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
                          p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
                          k3=str(distCoe[0][4]), k4=str(distCoe[0][5]),
                          k5=str(distCoe[0][6]), k6=str(distCoe[0][7]))
            elif (len(distCoe[0]) == 12): # 12 coefficients Prism Model, c1, c2, c3, c4 enabled, new in OpenCV 3.0.0
                w.element('DistCoe', k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
                               p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
                               k3=str(distCoe[0][4]), k4=str(distCoe[0][5]),
                               k5=str(distCoe[0][6]), k6=str(distCoe[0][7]),
                               c1=str(distCoe[0][8]), c2=str(distCoe[0][9]),
                                c3=str(distCoe[0][10]),c4=str(distCoe[0][11]))
            else:
                w.element('DistCoe', k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
                          p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
                          k3=str(distCoe[0][4]))
            
            # Error values
            if len(calibError) > 0:
                w.element('Error', rms=str(calibError['rms']), total=str(calibError['tot_err']), arth=str(calibError['arth_err']))
            
            w.close(root)
        print 'Intrinsic calibration has been generated successfully.'
        
    except Exception as e:
        print 'ERROR: occurred in writing intrinsic XML file.'
        raise e # keep it bubbling up, to catch in main()
开发者ID:gwillz,项目名称:EagleEye,代码行数:45,代码来源:stdcalib.py

示例15: writeXML

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import close [as 别名]
def writeXML(frames, path, args):
    out_xml = XMLWriter(path)
    out_xml.declaration()
    doc = out_xml.start("AnnotationEvaluation")
    
    # source information
    out_xml.element("video", mark_in=str(args[4]), mark_out=str(args[5]))
    out_xml.element("mapper", os.path.basename(args[1]))
    out_xml.element("annotation", os.path.basename(args[2]))
    out_xml.element("comparison", mean_err=str(calMean(frames)))
    # compared points
    out_xml.start("frames", total=str((args[5]-1) - (args[4]+1)+1), compared=str(len(frames)))
    for f in frames.keys():
        out_xml.start("frame", num=str(f))
        for key in frames[f]:
            out_xml.start("object", lens=Theta.name(frames[f][key]["lens"]), name=key, err=str(frames[f][key]["err"]))
            out_xml.element("annotatedCentroid", x=str(frames[f][key]["ann_x"]), y=str(frames[f][key]["ann_y"]))
            out_xml.element("mappedCentroid", x=str(frames[f][key]["map_x"]), y=str(frames[f][key]["map_y"]))
            out_xml.end() # object
        out_xml.end() # frames
    
    # clean up
    out_xml.close(doc)
开发者ID:gwillz,项目名称:EagleEye,代码行数:25,代码来源:evaluate.py


注:本文中的elementtree.SimpleXMLWriter.XMLWriter.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。