• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ElementTree.tostring函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xml.etree.ElementTree.tostring函数的典型用法代码示例。如果您正苦于以下问题:Python tostring函数的具体用法?Python tostring怎么用?Python tostring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: allCitiesAndEventsXML

def allCitiesAndEventsXML():
    # Query to get data of interest
    city = session.query(City).all()

    # Declare root node of XML
    top = Element('allEvents')
    comment = Comment('XML Response with all cities and events')
    top.append(comment)

    # Loop through query responses and format as XML 
    for c in city:
        event = SubElement(top, 'event')
        child = SubElement(event, 'id')
        child.text = str(c.id)
        child = SubElement(event, 'city')
        child.text = c.name
        child = SubElement(event, 'state')
        child.text = c.state
        eventInfo = SubElement(event, 'eventInfo')  # Add new node for Events
        for e in c.events:
            en = SubElement(eventInfo, 'event_name')
            en.text = e.name
            child = SubElement(en, 'description')
            child.text = e.description
            child = SubElement(en, 'event_date')
            child.text = str(e.event_date)
            child = SubElement(en, 'event_url')
            child.text = e.event_url
            child = SubElement(en, 'user_id')
            child.text = str(e.user_id)
     
        print tostring(top)
    return app.response_class(tostring(top), mimetype='application/xml')
开发者ID:twhetzel,项目名称:item-catalog,代码行数:33,代码来源:project.py


示例2: _enable_wms_caching

def _enable_wms_caching(layer, cache_secs, disable=False):
    '''This should go into gsconfig'''
    layer.resource.fetch()
    # ensure we fetch stuff fresh or we'll overwrite
    layer.catalog._cache.pop(layer.resource.href, None)
    dom = layer.resource.dom
    metadata = dom.find('metadata')
    if metadata is None:
        metadata = _el('metadata')
        dom.append(metadata)
    def set_entry(k, v):
        entries = metadata.findall("entry")
        entries = [ e for e in entries if e.attrib.get('key', None) == k]
        entry = entries[0] if entries else None
        if v:
            if entry is None:
                entry = _el('entry', v, key=k)
                metadata.append(entry)
            else:
                entry.text = str(v)
        elif entry is not None:
            metadata.remove(entry)
    set_entry('cacheAgeMax', cache_secs)
    set_entry('cachingEnabled', 'false' if disable or cache_secs is 0 else 'true')
    print tostring(dom)

    headers, resp = layer.resource.catalog.http.request(
        layer.resource.href, 'PUT', tostring(dom), {'content-type' : 'text/xml'})
    if headers.status != 200:
        raise Exception('error enabling wms caching: %s' % resp)
开发者ID:Geocent,项目名称:mapstory,代码行数:30,代码来源:gwc_config.py


示例3: qInequalities_template

def qInequalities_template():
    '''Solve inequalities. e.g. 2-3x <= 8.'''
    leftside_section1 = randint(-100,100)
    leftside_section2 = randint(-100,100)
    left_side = leftside_section1 + leftside_section2
    right_side = randint(-100,100)
    equality_type = randint(0,3) #<, <=, >, >=
    question = None 
    x = Symbol('x', real=True) #For 4U Maths use complex=True for ImaginaryNum
    question_str = "Solve "
    if equality_type == 0:
        question = Lt(leftside_section1 + leftside_section2*x, right_side)
    elif equality_type == 1:
        question = Le(leftside_section1 + leftside_section2*x, right_side)
    elif equality_type == 2:
        question = Gt(leftside_section1 + leftside_section2*x, right_side)
    elif equality_type == 3:
        question = Ge(leftside_section1 + leftside_section2*x, right_side)
    question_str += tostring(am.parse(str(question)))

    steps = []
    if leftside_section1 < 0:
        steps.append('Move by +' + str(leftside_section1*-1) + ' to both ' \
                     +'sides')
    else:
        steps.append('Move by -' + str(leftside_section1) + ' to both ' \
                     +'sides')
    steps.append('Divide left and right side by ' + str(leftside_section2))

    answer = []
    answer.append(steps)
    answer.append(tostring(am.parse(str(solve(question, x)))))

    return question_str, answer
开发者ID:shaond,项目名称:mathbrain,代码行数:34,代码来源:mathbrain.py


示例4: test_xml

def test_xml():
    the_tree = etree.parse('test.xml')
    for test in the_tree.getiterator('test'):
        name = test.get('name')
        if not name:
            raise ValueError('test element does not have a name attribute')
        the_string = ''
        for string in test.getiterator('string'):
            the_string += string.text
        test_xml = ascii_to_math_tree(the_string)
        indent(test_xml)
        test_xml_string = tostring(test_xml).encode('utf8')
        standard_test_xml_string = xml_copy_tree(test_xml_string)
        match = None
        for result in test.getiterator('result'):
            math_tree = result[0]
            indent(math_tree)
            xml_string = tostring(math_tree)
            standard_result_xml_string = xml_copy_tree(xml_string)
            if standard_test_xml_string == standard_result_xml_string:
                match = True
                break
        if not match:
            sys.stderr.write('Error for test "%s"\n' % (name))
            sys.stderr.write(standard_test_xml_string.encode("utf8"))
            sys.stderr.write('\ndoes not match\n')
            sys.stderr.write(standard_result_xml_string.encode("utf8"))
开发者ID:Distrotech,项目名称:docutils,代码行数:27,代码来源:test_asciimath.py


示例5: update

  def update(self):
    ResourceInfo.update(self)
    doc = self.metadata
    title = doc.find("title")
    abstract = doc.find("description")
    projection = doc.find("srs")
    enabled = doc.find("enabled")
    native_format = doc.find("nativeFormat")
    default_interpolation_method = doc.find("defaultInterpolationMethod")
    request_srs = doc.find("requestSRS/string")
    response_srs = doc.find("responseSRS/string")

    if title is None:
        print self.href
        print tostring(doc)

    self.title = title.text if title is not None else None
    self.abstract = abstract.text if abstract is not None else None
    self.keywords = [(kw.text or None) for kw in doc.findall("keywords/string")]
    self.native_bbox = bbox(doc.find("nativeBoundingBox"))
    self.latlon_bbox = bbox(doc.find("latLonBoundingBox"))
    self.projection = projection.text if projection is not None else None
    self.enabled = enabled.text == "true" if enabled is not None else False
    self.extra_config = dict((entry.attrib['key'], entry.text) for entry in doc.findall("metadata/entry"))
    self.dimensions = [coverage_dimension(d) for d in doc.findall("dimensions/coverageDimension")]
    self.native_format = native_format.text if native_format is not None else None
    self.grid = None # TODO: i guess this merits a little class of its own
    self.supported_formats = [format.text for format in doc.findall("supportedFormats/string")]
    self.default_interpolation_method = default_interpolation_method.text if default_interpolation_method is not None else None
    self.interpolation_methods = [method.text for method in doc.findall("interpolationMethods/string")]
    self.request_srs = request_srs.text if request_srs is not None else None
    self.response_srs = response_srs.text if response_srs is not None else None
    self.metadata_links = [md_link(n) for n in self.metadata.findall("metadataLinks/metadataLink")]
开发者ID:happybob007,项目名称:gsconfig.py,代码行数:33,代码来源:resource.py


示例6: brandsCatalogXML

def brandsCatalogXML(brand_id):
    if 'username' not in login_session:
        response = make_response(json.dumps("You are not authorized, Login is required"), 401)
        response.headers['Content-Type'] = 'application/json'
        return response
    else:
        brand = session.query(Brand).filter_by(id=brand_id).one()
        items = session.query(Item).filter_by(brand_id=brand_id).all()
    
    root = Element('html')
    for i in items:
        body = SubElement(root, 'body')
        ID = SubElement(body, 'ID')
        ID.text = str(i.id)
        name = SubElement(body, 'name')
        name.text = i.name
        price = SubElement(body, 'price')
        price.text = i.price
        description = SubElement(body, 'description')
        description.text = i.description
        image = SubElement(body, 'image')
        image.text = i.image
        print tostring(root)

    return app.response_class(tostring(root), mimetype='application/xml')
开发者ID:konqlonq,项目名称:Project-3,代码行数:25,代码来源:project.py


示例7: verify

    def verify(self, manager, uri, response, respdata, args): #@UnusedVariable
        # Get arguments
        files = args.get("filepath", [])
        
        # status code must be 200, 207
        if response.status not in (200,207):
            return False, "        HTTP Status Code Wrong: %d" % (response.status,)
        
        # look for response data
        if not respdata:
            return False, "        No response body"
        
        # look for one file
        if len(files) != 1:
            return False, "        No file to compare response to"
        
        # read in all data from specified file
        fd = open( files[0], "r" )
        try:
            try:
                data = fd.read()
            finally:
                fd.close()
        except:
            data = None

        if data is None:
            return False, "        Could not read data file"

        data = manager.server_info.subs(data)

        result = True
        if data != respdata:
            data = data.replace("\n", "\r\n")
            if data != respdata:
                # If we have an iCalendar file, then unwrap data and do compare
                if files[0].endswith(".ics"):
                    data = data.replace("\r\n ", "")
                    respdata = respdata.replace("\r\n ", "")
                    if data != respdata:
                        result = False
                elif files[0].endswith(".xml"):
                    try:
                        respdata = tostring(ElementTree(file=StringIO(respdata)).getroot())
                    except Exception:
                        return False, "        Could not parse XML response: %s" %(respdata,)
                    try:
                        data = tostring(ElementTree(file=StringIO(data)).getroot())
                    except Exception:
                        return False, "        Could not parse XML data: %s" %(data,)
                    if data != respdata:
                        result = False
                else:
                    result = False

        if result:
            return True, ""
        else:
            error_diff = "\n".join([line for line in unified_diff(data.split("\n"), respdata.split("\n"))])
            return False, "        Response data does not exactly match file data %s" % (error_diff,)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:60,代码来源:dataMatch.py


示例8: getItemsXML

def getItemsXML(expedition_id, category_id):
    """
    Endpoint to return an XML List of all items associated
    with a certain expedition and category
    :param expedition_id:
    :param category_id:
    """
    items = session.query(Item).filter_by(
        expedition_id=expedition_id,
        category_id=category_id).all()
    root = Element('allItems')
    comment = Comment('XML Endpoint Listing '
                      'all Item for a specific Category and Expedition')
    root.append(comment)
    for i in items:
        ex = SubElement(root, 'expedition')
        ex.text = i.expedition.title
        category_name = SubElement(ex, 'category_name')
        category_description = SubElement(category_name,
                                          'category_description')
        category_picture = SubElement(category_name, 'category_picture')
        category_name.text = i.category.name
        category_description.text = i.category.description
        category_picture.text = i.category.picture
        item_name = SubElement(category_name, 'item_name')
        item_decription = SubElement(item_name, 'item_description')
        item_picture = SubElement(item_name, 'item_picture')
        item_name.text = i.name
        item_decription.text = i.description
        item_picture.text = i.picture
    print tostring(root)
    return app.response_class(tostring(root), mimetype='application/xml')
开发者ID:capt-marwil,项目名称:Udacity-Item-Catalog,代码行数:32,代码来源:main.py


示例9: qSignificantFigures_template

def qSignificantFigures_template():
    '''Significant figures. e.g. Evaluate cuberoot(651/3) to 5 sig fig.'''
    sig_fig = randint(2,5)
    root_val = randint(2,5)
    numerator = randint(1,1000)
    denom = randint(1,1000)
    val = 'root%s(%s/(%s*pi))' % (root_val, numerator, denom)
    question = 'Evaluate ' +  tostring(am.parse(val)) + ' to %s' % (sig_fig)
    question += ' Significant Figures.'

    steps = []
    inside_root = (numerator/(denom*pi)).evalf() 
    val = root(inside_root, root_val)
    steps.append('This has to be done with a calculator.')
    steps.append('Do the inside calucation first: ' + 
                 tostring(am.parse('%s/(%s*pi)'%(numerator,denom))) + tostring(am.parse('*'))
                 + str(am.parse('pi')))
    steps.append('This should give ' + tostring(am.parse(str(inside_root))))
    steps.append('Then you need to square root the answer.')
    steps.append('Use either [1/y] key or similar on calculator and press ' 
                 + str(root_val))
    steps.append('Please refer to your calculator manual if in doubt.')
    steps.append('Then look for %s significant figures.' % sig_fig)
    steps.append('Note: First non-zero digit is 1st signifiant figure,' + \
                 ' going from left to right. Each digit after that is a' + \
                 ' significant figure.')
    answer = []
    answer.append(steps)
    answer.append(round(val, sig_fig-int(floor(log10(val)))-1))

    return question, answer
开发者ID:shaond,项目名称:mathbrain,代码行数:31,代码来源:mathbrain.py


示例10: _serverParseXML_QueryRQ

 def _serverParseXML_QueryRQ(self, e_root, e_header, e_body):
     #
     # start to parse a query class
     #
     e_query = e_root.find(".//fiap:query", namespaces=_NSMAP)
     if e_query == None:
         self.emsg = "query is not specified. [%s]" % tostring(e_root)
         return None
     #
     # check uuid.
     # XXX it's not used.
     #
     uuid = e_query.get("id")
     #
     # check the type attribute.
     # either storage or stream is valid.
     #
     type = e_query.get("type")
     if type == None:
         self.emsg = "type is not specified. [%s]" % tostring(e_query)
         return None
     elif type == "storage":
         return self._serverParseXML_FETCH(e_root, e_query)
     elif type == "stream":
         return self._serverParseXML_TRAP(e_root, e_query)
     else:
         self.emsg = "invalid type is specified. [%s]" % type
         return None
开发者ID:xiangdn,项目名称:fiapy,代码行数:28,代码来源:fiapProto.py


示例11: sign_file

def sign_file(xml_file, root_id, assert_id, key_file, cert_file):
    """sign *xml_file* with *key_file* and include content of *cert_file*.
    *xml_file* can be a file, a filename string or an HTTP/FTP url.

    *key_file* contains the PEM encoded private key. It must be a filename string.

    *cert_file* contains a PEM encoded certificate (corresponding to *key_file*),
    included as `X509Data` in the dynamically created `Signature` template.
    """
    # template aware infrastructure
    from dm.xmlsec.binding.tmpl import parse, Element, SubElement, \
         fromstring, XML
    from dm.xmlsec.binding.tmpl import Signature

    doc = parse(xml_file)

    xmlsec.addIDs(doc.getroot(),['ID'])

    assertion = doc.findall('saml:Assertion', {"saml": "urn:oasis:names:tc:SAML:2.0:assertion"})[0]



    assertion_xml = sign_xml(tostring(assertion), assert_id, key_file, cert_file)

    assertion_doc = fromstring(assertion_xml)
    doc.getroot().remove(doc.findall("saml:Assertion", {"saml": "urn:oasis:names:tc:SAML:2.0:assertion"})[0])
    doc.getroot().insert(0, assertion_doc)

    

    return sign_xml(tostring(doc), root_id, key_file, cert_file)
开发者ID:DaveLemanowicz,项目名称:PythonSAML,代码行数:31,代码来源:server.py


示例12: deploy_product

    def deploy_product(self, ip, product_name, product_version, attributes_string):
        url = "%s/%s/%s/%s" % (self.sdc_url, "vdc", self.vdc, "productInstance")
        headers = {'X-Auth-Token': self.token, 'Tenant-Id': self.vdc,
                   'Accept': "application/json", 'Content-Type':  "application/xml"}

        productrequest = ProductRequest(self.keystone_url, self.sdc_url, self.tenant, self.user, self.password)

        productrequest.get_product_info(product_name)
        attributes = self.__process_attributes(attributes_string)

        product_release = ProductReleaseDto(product_name, product_version)

        productInstanceDto = ProductInstanceDto(ip, product_release, attributes)
        payload = productInstanceDto.to_xml()
        print url
        print headers
        print tostring(payload)
        response = http.post(url, headers, tostring(payload))

        ## Si la respuesta es la adecuada, creo el diccionario de los datos en JSON.
        if response.status != 200:
            print 'error to add the product sdc ' + str(response.status)
            sys.exit(1)
        else:
            http.processTask(headers, json.loads(response.read()))
开发者ID:Fiware,项目名称:cloud.PaaS,代码行数:25,代码来源:productrinstanceequest.py


示例13: codeToXML

 def codeToXML(self, code):
     self.code = code
     #root = 0
     f=tempfile.NamedTemporaryFile(suffix='.cpp', delete=False)
     #code='//this is the content\n'
     f.write(code)
     f.close()
     #print f.name
     #fpath='./test.c'
     #g=open(f.name)
     #print '\n'.join(g.readlines())
     #g.close()
     try:
         p1 = Popen([os.path.dirname(os.path.realpath(__file__))+"/../bin/src2srcml", f.name], stdout=PIPE)
     except:
         print 'unable to open src2srcml binary'
         exit(-1)
     #print p1.stdout.read()
     #content='<unit>\n'+'\n'.join(p1.stdout.read().split('\n')[2:])
     content='\n'.join(p1.stdout.read().split('\n')[1:])
     content=content.replace('xmlns=','namsp=')
     #content=content.replace('xmlns:cpp=','namsp=')
     #content=p1.stdout.read()
     if DEBUG: print content
     #os.remove(f.name)
     root = ET.fromstring(content)
     if DEBUG: print tostring(root)
     #del root.attrib["xmlns"]
     self.root = root
     return root
开发者ID:ebads67,项目名称:ipmacc,代码行数:30,代码来源:wrapper-old.py


示例14: srcml_code2xml

def srcml_code2xml(code):
    srcml_sample = srcML()
    if DEBUG:
        print 'HERE:'
        tostring(srcml_sample.codeToXML(code))
        print '2HERE:'
    return srcml_sample.codeToXML(code)
开发者ID:ebads67,项目名称:ipmacc,代码行数:7,代码来源:wrapper-old.py


示例15: orgHandler

def orgHandler(node):
    """
    node is the start node of an Organization
    orHandler parses the xml info for this organizaton
    gathered info is stored in django module database
    """
    assert node is not None
    o = getEntity(Organization, node.attrib.get('ID'))
    o.name = node.attrib.get('Name')
    for attr in node:
        if attr.tag == 'Crises':
            for elem in attr:
                o.crises.add(getEntity(Crisis, elem.attrib.get('ID')))
        if attr.tag == 'People':
            for elem in attr:
                o.people.add(getEntity(Person, elem.attrib.get('ID')))
        if attr.tag == 'Kind':
            o.kind = attr.text
        if attr.tag == 'Location':
            o.location = attr.text
        if attr.tag == 'History':
            o.history += ''.join([v for v in [tostring(li).strip() for li in attr] if v not in o.history])
        if attr.tag == 'ContactInfo':
            o.contact += ''.join([v for v in [tostring(li).strip() for li in attr] if v not in o.contact])
        if attr.tag == 'Common':
            comHandler(attr, o)
    assert o is not None
    o.save()
开发者ID:JohnnyLee10,项目名称:cs373-wcdb,代码行数:28,代码来源:upload.py


示例16: test_package_serialization

    def test_package_serialization(self):
        items = [
            self.request_delivery_factory.factory_item(
                ware_key=uuid.uuid1().get_hex()[:10],
                cost=Decimal(450.0 * 30),
                payment=Decimal(450.0),
                weight=500,
                weight_brutto=600,
                amount=4,
                comment=u'Комментарий на русском',
                link=u'http://shop.ru/item/44'
            ),
            self.request_delivery_factory.factory_item(
                ware_key=uuid.uuid1().get_hex()[:10],
                cost=Decimal(250.0 * 30),
                payment=Decimal(250.0),
                weight=500,
                weight_brutto=600,
                amount=4,
                comment=u'Комментарий на русском',
                link=u'http://shop.ru/item/42'
            )
        ]

        package = self.request_delivery_factory.factory_package(
            number=uuid.uuid1().hex[:10],
            weight=3000,
            items=items
        )
        self.assertIsInstance(package, PackageRequestObject)
        tostring(package.to_xml_element(u'Package'), encoding='UTF-8').replace("'", "\"")
开发者ID:rebranch,项目名称:rebranch-cdek-api,代码行数:31,代码来源:tests.py


示例17: createAndWriteXML

def createAndWriteXML(upload_id, writeToDB):
    completeVase = Element('vase')
    
    for i in range(len(finalRight)):
        pointpair = SubElement(completeVase, 'pointpair')
        left = SubElement(pointpair, 'left')
        right = SubElement(pointpair, 'right')
        
        t = SubElement(pointpair, 't')
        
        xRight = SubElement(right, 'x')
        xLeft = SubElement(left, 'x')
        yRight = SubElement(right, 'y')
        yLeft = SubElement(left, 'y')
        
        t.text = "0"
        xRight.text = str(finalRight[i][0])
        xLeft.text = str(finalLeft[i][0])
        yRight.text = str(finalRight[i][1])
        yLeft.text = str(finalLeft[i][1])
    
    if writeToDB == 'True':
        writeToDB(upload_id, tostring(completeVase))
    #print "Content-type: text/html"
    #print
    print tostring(completeVase)
开发者ID:ohaicristina,项目名称:viv-website,代码行数:26,代码来源:VaseCreation.py


示例18: video_notification

def video_notification(request):
    """Receive video completion notifications from encoding.com

    A URL pointing to this view should be sent to encoding.com with transcode
    requests so that the hit this page and trigger EncodedVideo model updates
    """
    logger = logging.getLogger('vod_aws.views.video_notification')

    # Only handle POST requests, otherwise just show a blank page
    if request.method == 'POST':
        try:
            result = fromstring(request.POST['xml'])
        except KeyError:
            logger.error('request POST contained no XML data')
            return HttpResponseBadRequest()
        except ExpatError, e:
            logger.error('request POST xml parse error: %s' % (e.message))
            return HttpResponseBadRequest()

        # At this point, we should have XML that looks like this:
        #=======================================================================
        # <result>
        #    <mediaid>[MediaID]</mediaid>
        #    <source>[SourceFile]</source>
        #    <status>[MediaStatus]</status>
        #    <description>[ ErrorDescription]</description> <!-- Only in case of Status = Error -->
        #    <format>
        #        <output>[OutputFormat]</output>
        #        <destination>[DestFile]</destination> <!-- Only in case of Status = Finished -->
        #        <status>[TaskStatus]</status>
        #        <description>[ErrorDescription]</description> <!-- Only in case of Status = Error -->
        #        <suggestion>[ErrorSuggestion]</suggestion> <!-- Only in case of Status = Error -->
        #    </format>
        #    <format>
        #        ...
        #    </format>
        # </result>
        #
        # Note the lowercase 'mediaid', instead of 'MediaID' as it is elsewhere
        #=======================================================================

        # TODO: Currently this only acts on videos for which we've been notified.
        #  Doing a batch "GetStatus" on the MediaID we've been told about as well as
        #  old jobs that (for whatever reason) we don't know about would be a good idea

        # status can be "Error" or "Finished"
        status = result.findtext('status')
        if status == 'Finished':
            mediaid = result.findtext('mediaid')
            logger.info('Encoding.com job with MediaID %s is finished.' % mediaid)
            vod_aws.tasks.process_video_notification.delay(mediaid)
        elif status == 'Error':
            # Error message is result.find('description').text
            # Log the XML to get more debugging from encoding.com
            logger.error('Encoding.com reported an error: "%s". Enable DEBUG logging for full XML.' % result.findtext('description'))
            logger.debug(tostring(result))
        else:
            logger.error('Unknown status %s from encoding.com. Enable DEBUG logging for full XML.' % status)
            logger.debug(tostring(result))
开发者ID:AmericanResearchInstitute,项目名称:poweru-server,代码行数:59,代码来源:views.py


示例19: handle_noargs

 def handle_noargs(self, **options):
     """
     Poll flickr for photos and create save an onject to the database for
     each that isn't currently represented.
     
     Todo: keys and ids from settings
     """
     for account in settings.DJANGR_ACCOUNTS:
     
         flickr = flickrapi.FlickrAPI(settings.DJANGR_APIKEY)
         photos_el = flickr.photos_search(user_id=account['user_id'])
     
         for photo_el in photos_el.findall('photos/photo'):
             
             id = int(photo_el.get('id'))
             secret = photo_el.get('secret')
             
             # Reference existing photo or create new
             try:
                 photo = Photo.objects.get(id=id)
                 print 'Updating photo %s' % id
             except Photo.DoesNotExist:
                 print 'Creating a new photo %s' % id
                 photo = Photo()
                 photo.id = id
                 photo.active = True
                 photo.secret = secret
             
             # Request more information on the photo
             info_el = flickr.photos_getinfo(
                 user_id=account['user_id'],
                 photo_id=id, secret=secret)
             photoinfo_el = info_el.find('photo')
             photo.infoxml = tostring(photoinfo_el)
             
             # Parse xml
             photo.username = photoinfo_el.find('owner').get('username')
             photo.dateuploaded = datetime.fromtimestamp(float(
                 photoinfo_el.get('dateuploaded')))
             datetaken = photoinfo_el.find('dates').get('taken', '')
             photo.date = datetime.strptime(datetaken, '%Y-%m-%d %H:%M:%S')
             photo.description = photoinfo_el.findtext('description')
             photo.title = photoinfo_el.findtext('title')
             photo.farm = int(photoinfo_el.get('farm'))
             photo.server = int(photoinfo_el.get('server'))
             photo.xml = tostring(photo_el)
             photo.owner = photo_el.get('owner')
             
             # Parse optional properties, always delete from object when 
             # none exist - they may be newly removed
             location = photoinfo_el.find('location')
             if location:
                 photo.latitude = location.get('latitude')
                 photo.longitude = location.get('longitude')
             else:
                 photo.longitude = None
                 photo.latitude = None
                 
             photo.save()
开发者ID:benglynn,项目名称:djangr,代码行数:59,代码来源:djangrc.py


示例20: test_address3

	def test_address3(self):
		root = fromstring(address3)
		model = createFullAddress(root)
		elem = Element('test')
		buildAddress(elem, model)
		rootstring = tostring(root)
		elemstring = tostring(elem[0])
		self.assert_(rootstring == elemstring)
开发者ID:hychyc071,项目名称:cs373-wc2-tests,代码行数:8,代码来源:rshwarts-TestWC2.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ElementTree.Element类代码示例发布时间:2022-05-26
下一篇:
Python ElementTree.parse函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap