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


Python XMLWriter.data方法代码示例

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


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

示例1: create_gpx

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import data [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

示例2: main

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import data [as 别名]
def main(sysargs):
    # settings
    args = EasyArgs(sysargs)
    cfg = EasyConfig(args.config, group="trainer")
    max_clicks = args.clicks or cfg.default_clicks
    window_name = "EagleEye Trainer"
    
    if "help" in args:
        usage()
        return 0
    
    # grab marks from args
    if len(args) > 5:
        mark_in = args[4]
        mark_out = args[5]
        
        # test integer-ness
        try: int(mark_in) and int(mark_out)
        except: 
            usage()
            return 1
        
    elif len(args) > 3:
        ret, mark_in, mark_out = marker_tool(args[1], cfg.buffer_size, window_name)
        if not ret:
            print "Not processing - exiting."
            return 1
    else:
        usage()
        return 1
    
    ## clicking time!
    cropped_total = mark_out - mark_in
    print "video cropped at:", mark_in, "to", mark_out, "- ({} frames)".format(cropped_total)
    
    # clicking function
    def on_mouse(event, x, y, flags, params):
        # left click to mark
        if event == cv2.EVENT_LBUTTONDOWN:
            params['pos'] = (x, y)
            params['status'] = Status.record
            
        # right click to skip
        elif event == cv2.EVENT_RBUTTONDOWN:
            params['status'] = Status.skip
    
    # working variables
    params = {'status': Status.wait, 'pos': None}
    write_xml = False
    textstatus = ""
    dataQuality = 0   # 0 = good, >0 = bad/potentially bad
    
    # default right side (buttonside)
    if cfg.dual_mode:
        lens = Theta.Right
        trainer_points = {Theta.Right:{}, Theta.Left:{}}
    else: # both sides otherwise
        lens = Theta.Both
        trainer_points = {Theta.Both:{}}
    
    print "Minimum reflectors: {} | Ignore Negative xyz: {}".format(cfg.min_reflectors, cfg.check_negatives)
        
    # load video (again)
    in_vid = BuffSplitCap(args[1], crop=(0,0,0,0), rotate=BuffSplitCap.r0, buff_max=cfg.buffer_size)
    in_vid.restrict(mark_in, mark_out)
    
    # load csv (with appropriate ratio)
    in_csv = Memset(args[2])
    in_csv.restrict()
    in_csv.setRatio(cropped_total)
    
    # test for marker data
    if len(in_csv.row()) < 10:
        print "This CSV contains no marker data!\nAborting."
        return 1
    
    # status
    print ""
    print "Writing to:", args[3]
    print "Number of clicks at:", max_clicks
    print ""
    
    cv2.namedWindow(window_name)
    cv2.setMouseCallback(window_name, on_mouse, params)
    
    # grab clicks (Process 2)
    while in_vid.isOpened():
        frame = in_vid.frame(side=lens)
        
        sys.stdout.write(in_vid.status() + " | Clicks {} / {}\r".format(
                                                len(trainer_points[lens]), max_clicks))
        sys.stdout.flush()
        
        # prepare CSV data, click data
        tx = float(in_csv.row()[2])
        ty = float(in_csv.row()[3])
        tz = float(in_csv.row()[4])
        rx = float(in_csv.row()[5])
        ry = float(in_csv.row()[6])
        rz = float(in_csv.row()[7])
#.........这里部分代码省略.........
开发者ID:gwillz,项目名称:EagleEye,代码行数:103,代码来源:trainer.py

示例3: XMLReporter

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import data [as 别名]
class XMLReporter(BaseReporter):
    """Reports test results in XML, in a format resembling Ant's JUnit xml
    formatting output."""
    def __init__(self):
        BaseReporter.__init__(self)

        from cStringIO import StringIO
        self._sio = StringIO()
        try:
            from elementtree.SimpleXMLWriter import XMLWriter
        except ImportError:
            from testoob.compatibility.SimpleXMLWriter import XMLWriter
        self.writer = XMLWriter(self._sio, "utf-8")

        self.test_starts = {}

    def start(self):
        BaseReporter.start(self)
        self.writer.start("results")
        self.writer.start("testsuites")

    def done(self):
        BaseReporter.done(self)

        self.writer.element("total_time", value="%.4f"%self.total_time)
        self.writer.end("testsuites")

        if self.cover_amount is not None and self.cover_amount == "xml":
            self._write_coverage(self.coverage)

        self.writer.end("results")

    def get_xml(self):
        return self._sio.getvalue()

    def startTest(self, test_info):
        BaseReporter.startTest(self, test_info)
        self.test_starts[test_info] = time.time()

    def addError(self, test_info, err_info):
        BaseReporter.addError(self, test_info, err_info)
        self._add_unsuccessful_testcase("error", test_info, err_info)

    def addFailure(self, test_info, err_info):
        BaseReporter.addFailure(self, test_info, err_info)
        self._add_unsuccessful_testcase("failure", test_info, err_info)

    def _add_testcase_element(self, test_info, result, add_elements = lambda:None):
        self._start_testcase_tag(test_info)
        self.writer.element("result", result)
        add_elements()
        self.writer.end("testcase")

    def addSuccess(self, test_info):
        BaseReporter.addSuccess(self, test_info)
        self._add_testcase_element(test_info, "success")

    def addSkip(self, test_info, err_info, isRegistered=True):
        BaseReporter.addSkip(self, test_info, err_info, isRegistered)
        def add_elements():
            self.writer.element( "reason", err_info.exception_value() )
        self._add_testcase_element(test_info, "skip")

    def _add_unsuccessful_testcase(self, failure_type, test_info, err_info):
        def add_elements():
            "Additional elements specific for failures and errors"
            self.writer.element(failure_type, str(err_info), type=err_info.exception_type(), message=err_info.exception_value())
        self._add_testcase_element(test_info, failure_type, add_elements)

    def _start_testcase_tag(self, test_info):
        self.writer.start("testcase", name=str(test_info), time=self._test_time(test_info))

    def _test_time(self, test_info):
        result = time.time() - self.test_starts[test_info]
        return "%.4f" % result

    def _write_coverage(self, coverage):
        self.writer.start("coverage")
        for filename, stats in coverage.getstatistics().items():
            # TODO: can probably extract loop body to a method
            self.writer.start("sourcefile", name=filename,
                              statements=str(stats["lines"]),
                              executed=str(stats["covered"]),
                              percent=str(stats["percent"]))
            lines, covered =  coverage.coverage[filename].values()
            missing = [line for line in covered if line not in lines]
            self.writer.data(str(missing)[1:-1].replace(" ", ""))
            self.writer.end("sourcefile")
        self.writer.end("coverage")
开发者ID:algard,项目名称:testoob,代码行数:91,代码来源:xml.py

示例4: XMLWriter

# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import data [as 别名]
@author: jmalinchak
"""

from elementtree.SimpleXMLWriter import XMLWriter
import sys



w = XMLWriter(sys.stdout)

html = w.start("html")

w.start("head")
w.element("title", "my document")
w.element("meta", name="generator", value="my application 1.0")
w.end()

w.start("body")
w.element("h1", "this is a heading")
w.element("p", "this is a paragraph")

w.start("p")
w.data("this is ")
w.element("b", "bold")
w.data(" and ")
w.element("i", "italic")
w.data(".")
w.end("p")

w.close(html)
开发者ID:rtstock,项目名称:rts,代码行数:32,代码来源:serializesortedpairdictionarytoxml_tc2.py


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