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


Python saxutils.quoteattr方法代码示例

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


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

示例1: update_file

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def update_file(filename, items):
    '''Edits the given file in place, replacing any instances of {key} with the
    appropriate value from the provided items dict. If the given filename ends
    with ".xml" values will be quoted and escaped for XML.
    '''
    # TODO: Implement something in the templates to denote whether the value
    # being replaced is an XML attribute or a value. Perhaps move to dyanmic
    # XML tree building rather than string replacement.
    should_escape = filename.endswith('addon.xml')

    with open(filename, 'r') as inp:
        text = inp.read()

    for key, val in items.items():
        if should_escape:
            val = saxutils.quoteattr(val)
        text = text.replace('{%s}' % key, val)
    output = text

    with open(filename, 'w') as out:
        out.write(output) 
开发者ID:jmarth,项目名称:plugin.video.kmediatorrent,代码行数:23,代码来源:create.py

示例2: _display_xml_table_elem

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def _display_xml_table_elem(doc, first=False, name=None, out=sys.stdout):
    if first:
        assert name is None
    name = '' if name is None else ' key=%s' % saxutils.quoteattr(name)
    if isinstance(doc, list):
        if not first:
            out.write('<table%s>\n' % name)
        for subdoc in doc:
            _display_xml_table_elem(subdoc, out=out)
        if not first:
            out.write('</table>\n')
    elif isinstance(doc, dict):
        if not first:
            out.write('<table%s>\n' % name)
        for key, subdoc in viewitems(doc):
            _display_xml_table_elem(subdoc, name=key, out=out)
        if not first:
            out.write('</table>\n')
    else:
        out.write('<elem%s>%s</elem>\n' % (name,
                                           saxutils.escape(
                                               str(doc),
                                               entities={'\n': '&#10;'},
                                           ))) 
开发者ID:cea-sec,项目名称:ivre,代码行数:26,代码来源:activecli.py

示例3: update_file

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def update_file(filename, items):
    """Edits the given file in place, replacing any instances of {key} with the
    appropriate value from the provided items dict. If the given filename ends
    with ".xml" values will be quoted and escaped for XML.
    """
    # TODO: Implement something in the templates to denote whether the value
    # being replaced is an XML attribute or a value. Perhaps move to dyanmic
    # XML tree building rather than string replacement.
    should_escape = filename.endswith('addon.xml')

    with open(filename, 'r') as inp:
        text = inp.read()

    for key, val in items.items():
        if should_escape:
            val = saxutils.quoteattr(val)
        text = text.replace('{%s}' % key, val)
    output = text

    with open(filename, 'w') as out:
        out.write(output) 
开发者ID:afrase,项目名称:kodiswift,代码行数:23,代码来源:create.py

示例4: getFamilyXmlReport

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def getFamilyXmlReport(self):
        """Reports on all families found as XML.
        """
        lines = []
        lines.append('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>')
        lines.append("<font_families>")
        for dirName in self._dirs:
            lines.append("    <directory name=%s/>" % quoteattr(dirName))
        for familyName in self.getFamilyNames():
            if familyName:  #skip null case
                lines.append('    <family name=%s>' % quoteattr(familyName))
                for font in self.getFontsInFamily(familyName):
                    lines.append('        ' + font.getTag())
                lines.append('    </family>')
        lines.append("</font_families>")
        return '\n'.join(lines) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:fontfinder.py

示例5: encode

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def encode(self, *args):
        if len(args) > 2:
            raise TypeError("too much arguments for encode()")
        elif not args:
            encoding = getdefaultencoding()
        else:
            encoding = args[0]

        if not self.startswith("<?xml"):
            body = self
        else:
            try:
                i = self.index("?>")
            except ValueError:
                raise ValueError("unproper XML declaration")
            body = self[i + 2:].lstrip()

        decl = '<?xml version="1.0" encoding=%s?>\n' % quoteattr(encoding)
        return decl + unicode(body).encode(*args) 
开发者ID:ActiveState,项目名称:code,代码行数:21,代码来源:recipe-526626.py

示例6: handle_starttag

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def handle_starttag(self, tag, method, attrs):
        if tag not in self.permitted_tags:
            self.result += xssescape("<%s>" %  tag)
        else:
            bt = "<" + tag
            if tag in self.allowed_attributes:
                attrs = dict(attrs)
                self.allowed_attributes_here = \
                  [x for x in self.allowed_attributes[tag] if x in attrs \
                   and len(attrs[x]) > 0]
                for attribute in self.allowed_attributes_here:
                    if attribute in ['href', 'src', 'background']:
                        if self.url_is_acceptable(attrs[attribute]):
                            bt += ' %s="%s"' % (attribute, attrs[attribute])
                    else:
                        bt += ' %s=%s' % \
                           (xssescape(attribute), quoteattr(attrs[attribute]))
            if bt == "<a" or bt == "<img":
                return
            if tag in self.requires_no_close:
                bt += "/"
            bt += ">"                     
            self.result += bt
            self.open_tags.insert(0, tag) 
开发者ID:knightmare2600,项目名称:d4rkc0de,代码行数:26,代码来源:xxsdefense.py

示例7: _out_tag

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def _out_tag(self, name, attrs, isLeaf):
        # sorted attributes -- don't want attributes output in random order, which is what the XMLGenerator class does
        self.output.write(" " * self.indent)
        self.output.write("<%s" % name)
        sortedNames = sorted( attrs.keys() )  # sorted list of attribute names
        for name in sortedNames:
            value = attrs[ name ]
            # if not of type string,
            if not isinstance(value, str):
                # turn it into a string
                value = str(value)
            self.output.write(" %s=%s" % (name, quoteattr(value)))
        if isLeaf:
            self.output.write("/")
        else:
            self.indent += 4
        self.output.write(">\n") 
开发者ID:OGRECave,项目名称:blender2ogre,代码行数:19,代码来源:xml.py

示例8: toprettyxml

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def toprettyxml(self, lines, indent ):
        s = '<%s ' % self.tagName
        sortedNames = sorted( self.attributes.keys() )
        for name in sortedNames:
            value = self.attributes[name]
            if not isinstance(value, str):
                value = str(value)
            s += '%s=%s ' % (name, quoteattr(value))
        if not self.childNodes:
            s += '/>'; lines.append( ('  '*indent)+s )
        else:
            s += '>'; lines.append( ('  '*indent)+s )
            indent += 1
            for child in self.childNodes:
                child.toprettyxml( lines, indent )
            indent -= 1
            lines.append(('  '*indent) + '</%s>' % self.tagName ) 
开发者ID:OGRECave,项目名称:blender2ogre,代码行数:19,代码来源:xml.py

示例9: add_starttag

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def add_starttag(self, tag, ident = 0, attribs = '', text = '', close = False):
        '''
        Add a starttag with optional attributestring, textstring and optionally close it.
        Give it the proper ident.
        '''
        if isinstance(attribs, dict):
            a = ''
            for k, v in attribs.items():
                a = '%s %s=%s' % (a, k, saxutils.quoteattr(v))

            attribs = a

        if attribs != '':
            attribs = ' %s' % attribs

        if close and text == '':
            return u'%s<%s%s/>\n' % (''.rjust(ident), self.xmlescape(tag), attribs)

        if close and text != '':
            return u'%s<%s%s>%s</%s>\n' % (''.rjust(ident), self.xmlescape(tag), attribs, self.xmlescape(text), self.xmlescape(tag))

        else:
            return u'%s<%s%s>%s\n' % (''.rjust(ident), self.xmlescape(tag), attribs, self.xmlescape(text)) 
开发者ID:tvgrabbers,项目名称:tvgrabpyAPI,代码行数:25,代码来源:tv_grab_channel.py

示例10: import_users

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def import_users(self, users):
        """ Import users, returns import result (http://confluence.jetbrains.net/display/YTD2/Import+Users)
            Example: importUsers([{'login':'vadim', 'fullName':'vadim', 'email':'eee@ss.com', 'jabber':'fff@fff.com'},
                                  {'login':'maxim', 'fullName':'maxim', 'email':'aaa@ss.com', 'jabber':'www@fff.com'}])
        """
        if len(users) <= 0:
            return

        known_attrs = ('login', 'fullName', 'email', 'jabber')

        xml = '<list>\n'
        for u in users:
            xml += '  <user ' + "".join(k + '=' + quoteattr(u[k]) + ' ' for k in u if k in known_attrs) + '/>\n'
        xml += '</list>'
        # TODO: convert response xml into python objects
        if isinstance(xml, str):
            xml = xml.encode('utf-8')
        return self._req_xml('PUT', '/import/users', xml, 400).toxml() 
开发者ID:devopshq,项目名称:youtrack,代码行数:20,代码来源:connection.py

示例11: import_work_items

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def import_work_items(self, issue_id, work_items):
        xml = ''
        for work_item in work_items:
            xml += '<workItem>'
            xml += '<date>%s</date>' % work_item.date
            xml += '<duration>%s</duration>' % work_item.duration
            if hasattr(work_item, 'description') and work_item.description is not None:
                xml += '<description>%s</description>' % escape(work_item.description)
            if hasattr(work_item, 'worktype') and work_item.worktype is not None:
                xml += '<worktype><name>%s</name></worktype>' % work_item.worktype
            xml += '<author login=%s></author>' % quoteattr(work_item.authorLogin)
            xml += '</workItem>'
        if isinstance(xml, str):
            xml = xml.encode('utf-8')
        if xml:
            xml = '<workItems>' + xml + '</workItems>'
            self._req_xml('PUT',
                          '/import/issue/%s/workitems' % urlquote(issue_id), xml) 
开发者ID:devopshq,项目名称:youtrack,代码行数:20,代码来源:connection.py

示例12: write

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def write(self, output, ntabs):
        obj = self.obj

        tabs = self.tabs(ntabs)
        tabs1 = self.tabs(ntabs + 1)

        if obj is None or obj.name == "spacer":
            output.append( tabs + '<object class="spacer">\n' )
        else:
            output.append( tabs + '<object class="spacer" name=%s>\n'%quoteattr(obj.name) )
        if obj is not None:
            # a real spacer
            output.append( tabs1 + '<size>%s, %s</size>\n' % (obj.width, obj.height) )
            if obj.proportion:
                output.append(tabs1 + '<option>%s</option>\n' % obj.proportion)
            if obj.flag:
                flag = obj.properties["flag"].get_string_value()
                output.append(tabs1 + '<flag>%s</flag>\n' % self.cn_f(flag))
            if obj.border:
                output.append(tabs1 + '<border>%s</border>\n' % obj.border)
        else:
            # just an empty sizer slot
            output.append( tabs1 + '<size>0, 0</size>\n' )
        output.append(tabs + '</object>\n') 
开发者ID:wxGlade,项目名称:wxGlade,代码行数:26,代码来源:xrc_codegen.py

示例13: WriteXmlString

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def WriteXmlString(self, streamWriter, indent=""):
        attr, text = self.GetData()
        attribStrs = "".join(
            ' %s=%s' % (k, quoteattr(unicode(v)).encode("UTF-8"))
            for k, v in attr
        )
        streamWriter("%s<%s%s" % (indent, self.xmlTag, attribStrs))
        if not text and len(self.childs) == 0:
            streamWriter(" />\r\n")
        else:
            streamWriter(">\r\n")
            newIndent = indent + "    "
            if text is not None:
                streamWriter(newIndent + escape(text).encode("UTF-8"))
                streamWriter("\r\n")
            self.WriteXmlChilds(streamWriter, newIndent)
            streamWriter(indent + "</%s>\r\n" % self.xmlTag) 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:19,代码来源:TreeItem.py

示例14: _display_xml_script

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def _display_xml_script(s, out=sys.stdout):
    out.write('<script id=%s' % saxutils.quoteattr(s['id']))
    if 'output' in s:
        out.write(' output=%s' % saxutils.quoteattr(s['output']))
    key = xmlnmap.ALIASES_TABLE_ELEMS.get(s['id'], s['id'])
    if key in s:
        out.write('>')
        _display_xml_table_elem(s[key], first=True, out=out)
        out.write('</script>')
    else:
        out.write('/>') 
开发者ID:cea-sec,项目名称:ivre,代码行数:13,代码来源:activecli.py

示例15: _quoteattr

# 需要导入模块: from xml.sax import saxutils [as 别名]
# 或者: from xml.sax.saxutils import quoteattr [as 别名]
def _quoteattr(self, attr):
        """Escape an XML attribute. Value can be unicode."""
        attr = xml_safe(attr)
        return saxutils.quoteattr(attr) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:6,代码来源:xunit.py


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