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

Python saxutils.xmlescape函数代码示例

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

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



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

示例1: create

    def create(self, overwrite, dryrun, tag=None):
        # Append autojobs-information.
        info_el = etree.SubElement(self.xml, 'createdByJenkinsAutojobs')
        ref_el  = etree.SubElement(info_el, 'ref')
        ref_el.text = xmlescape(self.branch)

        # Tag builds (this will be reworked in the future).
        if tag:
            tag_el = etree.SubElement(info_el, 'tag')
            tag_el.text = xmlescape(tag)

        # method='c14n' is only available in more recent versions of lxml
        self.xml = self.canonicalize(self.xml)

        if self.exists and overwrite:
            job_config_dom = etree.fromstring(self.config.encode('utf8'))

            if self.canonicalize(job_config_dom) == self.xml:
                print('. job does not need to be reconfigured')
                return

            if not dryrun:
                job = self.jenkins.job(self.name)
                job.config = self.xml
            print('. job updated')

        elif not self.exists:
            if not dryrun:
                self.jenkins.job_create(self.name, self.xml)
            print('. job created')

        elif not overwrite:
            print('. overwrite disabled - skipping job')
开发者ID:PaulKlumpp,项目名称:jenkins-autojobs,代码行数:33,代码来源:job.py


示例2: write

	def write(self, fileobj = sys.stdout, indent = u""):
		fileobj.write(self.start_tag(indent))
		for c in self.childNodes:
			if c.tagName not in self.validchildren:
				raise ligolw.ElementError("invalid child %s for %s" % (c.tagName, self.tagName))
			c.write(fileobj, indent + ligolw.Indent)
		if self.pcdata is not None:
			if self.Type == u"yaml":
				try:
					yaml
				except NameError:
					raise NotImplementedError("yaml support not installed")
				fileobj.write(xmlescape(yaml.dump(self.pcdata).strip()))
			else:
				# we have to strip quote characters from
				# string formats (see comment above).  if
				# the result is a zero-length string it
				# will get parsed as None when the document
				# is loaded, but on this code path we know
				# that .pcdata is not None, so as a hack
				# until something better comes along we
				# replace zero-length strings here with a
				# bit of whitespace.  whitespace is
				# stripped from strings during parsing so
				# this will turn .pcdata back into a
				# zero-length string.  NOTE:  if .pcdata is
				# None, then it will become a zero-length
				# string, which will be turned back into
				# None on parsing, so this mechanism is how
				# None is encoded (a zero-length Param is
				# None)
				fileobj.write(xmlescape(ligolwtypes.FormatFunc[self.Type](self.pcdata).strip(u"\"") or u" "))
		fileobj.write(self.end_tag(u"") + u"\n")
开发者ID:lpsinger,项目名称:lalsuite,代码行数:33,代码来源:param.py


示例3: tag_config

    def tag_config(self, tag=None, method='description'):
        if method == 'description':
            mark = '\n(created by jenkins-autojobs)'
            tag = ('\n(jenkins-autojobs-tag: %s)' % tag) if tag else ''

            mark = xmlescape(mark)
            tag  = xmlescape(tag)
            desc_el = Job.find_or_create_description_el(self.xml)

            if desc_el.text is None:
                desc_el.text = ''
            if mark not in desc_el.text:
                desc_el.text += mark
            if tag not in desc_el.text:
                desc_el.text += tag

        elif method == 'element':
            info_el = lxml.etree.SubElement(self.xml, 'createdByJenkinsAutojobs')
            ref_el  = lxml.etree.SubElement(info_el, 'ref')
            ref_el.text = xmlescape(self.branch)

            # Tag builds.
            if tag:
                tag_el = lxml.etree.SubElement(info_el, 'tag')
                tag_el.text = xmlescape(tag)
开发者ID:gvalkov,项目名称:jenkins-autojobs,代码行数:25,代码来源:job.py


示例4: tag_config

    def tag_config(self, tag=None, method='description'):
        if method == 'description':
            mark = '\n(created by jenkins-autojobs)'
            tag = ('\n(jenkins-autojobs-tag: %s)' % tag) if tag else ''

            mark = xmlescape(mark)
            tag  = xmlescape(tag)

            desc_el = self.xml.xpath('//project/description')
            if not desc_el:
                desc_el = lxml.etree.Element('description')
                self.xml.insert(1, desc_el)
            else:
                desc_el = desc_el[0]

            if desc_el.text is None:
                desc_el.text = ''
            if mark not in desc_el.text:
                desc_el.text += mark
            if tag not in desc_el.text:
                desc_el.text += tag

        elif method == 'element':
            info_el = lxml.etree.SubElement(self.xml, 'createdByJenkinsAutojobs')
            ref_el  = lxml.etree.SubElement(info_el, 'ref')
            ref_el.text = xmlescape(self.branch)

            # Tag builds.
            if tag:
                tag_el = lxml.etree.SubElement(info_el, 'tag')
                tag_el.text = xmlescape(tag)
开发者ID:quetzai,项目名称:jenkins-autojobs,代码行数:31,代码来源:job.py


示例5: dump_config

def dump_config(d, source_path, out):
  """
  Dump a Hadoop-style XML configuration file.

  'd': a dictionary of name/value pairs.
  'source_path': the path where 'd' was parsed from.
  'out': stream to write to
  """
  header = """\
      <?xml version="1.0"?>
      <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
      <!--

      NOTE: THIS FILE IS AUTO-GENERATED FROM:
        {source_path}

      EDITS BY HAND WILL BE LOST!

      -->
      <configuration>""".format(source_path=os.path.abspath(source_path))
  print >>out, dedent(header)
  for k, v in sorted(d.iteritems()):
    try:
      v = _substitute_env_vars(v)
    except KeyError, e:
      raise Exception("failed environment variable substitution for value {k}: {e}"
                      .format(k=k, e=e))
    print >>out, """\
      <property>
        <name>{name}</name>
        <value>{value}</value>
      </property>""".format(name=xmlescape(k), value=xmlescape(v))
开发者ID:apache,项目名称:incubator-impala,代码行数:32,代码来源:generate_xml_config.py


示例6: create

    def create(self, overwrite, dryrun, scope_name = None):
        # append autojobs-information
        info_el = etree.SubElement(self.xml, 'createdByJenkinsAutojobs')
        
        ref_el = etree.SubElement(info_el, 'ref')
        ref_el.text = xmlescape(self.branch)

        # scope_name is scope used for projects deleting.
        # during deletion only projects with scope equal to template project will be deleted
        if scope_name:
            project_el = etree.SubElement(info_el, 'scopeName')
            project_el.text = xmlescape(scope_name)

        # method='c14n' is only available in more recent versions of lxml
        self.xml = self.canonicalize(self.xml)

        if self.exists and overwrite:
            job_config_dom = etree.fromstring(self.config.encode('utf8'))

            if self.canonicalize(job_config_dom) == self.xml:
                print('. job does not need to be reconfigured')
                return

            if not dryrun:
                job = self.jenkins.job(self.name)
                job.config = self.xml
            print('. job updated')

        elif not self.exists:
            if not dryrun:
                self.jenkins.job_create(self.name, self.xml)
            print('. job created')

        elif not overwrite:
            print('. overwrite disabled - skipping job')
开发者ID:piotrsynowiec,项目名称:jenkins-autojobs,代码行数:35,代码来源:job.py


示例7: tag_config

    def tag_config(self, tag=None, method="description"):
        if method == "description":
            mark = "\n(created by jenkins-autojobs)"
            tag = ("\n(jenkins-autojobs-tag: %s)" % tag) if tag else ""

            mark = xmlescape(mark)
            tag = xmlescape(tag)

            desc_el = self.xml.xpath("/project/description")[0]
            if desc_el.text is None:
                desc_el.text = ""
            if mark not in desc_el.text:
                desc_el.text += mark
            if tag not in desc_el.text:
                desc_el.text += tag

        elif method == "element":
            info_el = lxml.etree.SubElement(self.xml, "createdByJenkinsAutojobs")
            ref_el = lxml.etree.SubElement(info_el, "ref")
            ref_el.text = xmlescape(self.branch)

            # Tag builds.
            if tag:
                tag_el = lxml.etree.SubElement(info_el, "tag")
                tag_el.text = xmlescape(tag)
开发者ID:Musiqua,项目名称:jenkins-autojobs,代码行数:25,代码来源:job.py


示例8: escapeit

 def escapeit(self, sval, EXTRAS=None):
     # note, xmlescape and unescape do not work with utf-8 bytestrings
     sval = unicode_str(sval)
     if EXTRAS:
         res = xmlescape(unescapeit(sval), EXTRAS)
     else:
         res = xmlescape(unescapeit(sval))
     return res
开发者ID:jpeezzy,项目名称:kindleunpack-calibre-plugin,代码行数:8,代码来源:mobi_opf.py


示例9: escapeit

 def escapeit(self, sval, EXTRAS=None):
     # note, xmlescape and unescape do not work with utf-8 bytestrings
     # so pre-convert to full unicode and then convert back since opf is utf-8 encoded
     uval = sval.decode('utf-8')
     if EXTRAS:
         ures = xmlescape(self.h.unescape(uval), EXTRAS)
     else:
         ures = xmlescape(self.h.unescape(uval))
     return ures.encode('utf-8')
开发者ID:holy-donkey,项目名称:HolyDonkeyPack,代码行数:9,代码来源:mobi_opf.py


示例10: dumpXML

    def dumpXML(self):
        t = datetime.datetime.now()

        # Document header
        s = """\
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>
<Head>
  <Timestamp>%s</Timestamp>
</Head>
<Entries>
""" % t

        # Process single HTTP entries
        for entry in self.__history:
            s += "  <Entry>\n"
            s += "    <ID>%d</ID>\n" % entry.id

            for attr, name in [
                ("oreq", "OriginalRequest"),
                ("mreq", "MangledRequest"),
                ("ores", "OriginalResponse"),
                ("mres", "MangledResponse"),
                ]:

                v = getattr(entry, attr)
                t = getattr(entry, attr + "_time")
                if v is not None:
                    s += """\
    <%s>
      <Timestamp>%s</Timestamp>
      <Data>
""" % (name, t)

                    # Process entry headers
                    for hname, hvalues in v.headers.iteritems():
                        for hvalue in hvalues:
                            s += """\
          <Header>
            <Name>%s</Name>
            <Value>%s</Value>
          </Header>
""" % (xmlescape(hname), xmlescape(hvalue))

                    # Process entry body and close tag
                    s += """\
        <Body>%s</Body>
      </Data>
    </%s>
""" % (base64.encodestring(v.body), name)

            s += "  </Entry>\n"

        s += "</Entries>\n"

        return s
开发者ID:AgentKWang,项目名称:proxpy,代码行数:55,代码来源:history.py


示例11: enqueue_job

def enqueue_job(event):
    event_id = str(event['id'])
    work_doc = os.path.join(tempdir.name, event_id + '.motn')
    intermediate_clip = os.path.join(tempdir.name, event_id + '.mov')

    with open(args.motn, 'r') as fp:
        xmlstr = fp.read()

    for key, value in event.items():
        xmlstr = xmlstr.replace("$" + str(key), xmlescape(str(value)))

    with open(work_doc, 'w') as fp:
        fp.write(xmlstr)

    compressor_info = run_output(
        '/Applications/Compressor.app/Contents/MacOS/Compressor -batchname {batchname} -jobpath {jobpath} -settingpath apple-prores-4444.cmprstng -locationpath {locationpath}',
        batchname=describe_event(event),
        jobpath=work_doc,
        locationpath=intermediate_clip)

    match = re.search(r"<jobID ([A-Z0-9\-]+) ?\/>", compressor_info)
    if not match:
        event_print(event, "unexpected output from compressor: \n" + compressor_info)
        return

    return match.group(1)
开发者ID:voc,项目名称:intro-outro-generator,代码行数:26,代码来源:make-apple-motion.py


示例12: _xml

def _xml(value, attr=False):
    if is_sequence(value):
        return (' ' if attr else '').join(_xml(x) for x in value)
    elif isinstance(value, Node):
        return str(value)
    else:
        return xmlescape(str(value))
开发者ID:orbnauticus,项目名称:silk,代码行数:7,代码来源:common.py


示例13: notify_error

def notify_error(text, title='Alert'):
    """Error-display wrapper for various notification/dialog backends.

    @todo: Add support for HTML notifications.
    @todo: Generalize for different notification types.
    @todo: Add support for using D-Bus directly.
    @todo: Add KDE detection and kdialog support.
    """
    params = {
            'title'   : title,
            'text'    : str(text),
            'text_xml': xmlescape(str(text))
            }

    for backend in NOTIFY_BACKENDS:
        if which(backend[0]):
            try:
                subprocess.check_call([x % params for x in backend])
            except subprocess.CalledProcessError:
                continue
            else:
                break
    else:
        # Just in case it's run from a console-only shell.
        print "%s:" % title
        print text
开发者ID:HyunChul71,项目名称:profile,代码行数:26,代码来源:address_bar.py


示例14: write

	def write(self, fileobj = sys.stdout, indent = u""):
		if self.pcdata:
			fileobj.write(self.start_tag(indent))
			fileobj.write(xmlescape(self.pcdata))
			fileobj.write(self.end_tag(u"") + u"\n")
		else:
			fileobj.write(self.start_tag(indent) + self.end_tag(u"") + u"\n")
开发者ID:smirshekari,项目名称:lalsuite,代码行数:7,代码来源:ligolw.py


示例15: write

	def write(self, fileobj = sys.stdout, indent = u""):
		# avoid symbol and attribute look-ups in inner loop
		delim = self.Delimiter
		linefmtfunc = lambda seq: xmlescape(delim.join(seq))
		elemfmtfunc = ligolwtypes.FormatFunc[self.parentNode.Type]
		elems = self.parentNode.array.T.flat
		nextelem = elems.next
		linelen = self.parentNode.array.shape[0]
		totallen = self.parentNode.array.size
		newline = u"\n" + indent + ligolw.Indent
		w = fileobj.write

		# This is complicated because we need to not put a
		# delimiter after the last element.
		w(self.start_tag(indent))
		if totallen:
			# there will be at least one line of data
			w(newline)
		newline = delim + newline
		while True:
			w(linefmtfunc(elemfmtfunc(nextelem()) for i in xrange(linelen)))
			if elems.index >= totallen:
				break
			w(newline)
		w(u"\n" + self.end_tag(indent) + u"\n")
开发者ID:ligo-cbc,项目名称:pycbc-glue,代码行数:25,代码来源:array.py


示例16: plotaxes

def plotaxes(title=None):
    """Plot crosshair and circles at 30N and 60N.  Outputs an
    SVG fragment.
    """
    if title:
        print "<g class='title'>"
        print "<text x='%.1f' y='16' text-anchor='middle'>%s</text>" % (scale*0.5, xmlescape(title))
        print "</g>"
    print "<g class='axes'>"
    # Crosshair at N pole.
    print "<path d='M%.1f %.1fL%.1f %.1f' />" % (xform(0,180) + xform(0,0))
    print "<path d='M%.1f %.1fL%.1f %.1f' />" % (xform(0,-90) + xform(0,+90))
    # Circles at 30N and 60N
    circles = {
        30: 'major',
        40: 'minor',
        50: 'minor',
        60: 'major',
        70: 'minor',
        80: 'minor',
    }
    # Compute radii by using distance between North pole and (somethingN, 0).
    nx,ny = xform(90,0)
    for lat,rank in circles.iteritems():
        radius = math.hypot(*[v-c for v,c in zip(xform(lat,0),(nx,ny))])
        print "<circle class='%s' cx='%.1f' cy='%.1f' r='%.1f' />" % (rank, nx,ny,radius)
    # Labels
    for lat in [k for k,v in circles.items() if v == 'major'] + [90]:
        print "<text x='%.1f' y='%.1f'>%sN</text>" % (xform(lat,90) + (lat,))
    print "</g>"
开发者ID:carriercomm,项目名称:scraperwiki-scraper-vault,代码行数:30,代码来源:canada_weather_stations_static_map.py


示例17: _recursive_add

 def _recursive_add(parent_iter, supercoll):
     for coll in self._library.backend.get_collections_in_collection(
       supercoll):
         name = self._library.backend.get_collection_name(coll)
         child_iter = self._treestore.append(parent_iter,
             [xmlescape(name), coll])
         _recursive_add(child_iter, coll)
开发者ID:ZhanruiLiang,项目名称:Comix,代码行数:7,代码来源:library.py


示例18: write

	def write(self, fileobj = sys.stdout, indent = u""):
		fileobj.write(self.start_tag(indent))
		if self.pcdata is not None:
			if self.Type == u"ISO-8601":
				fileobj.write(xmlescape(unicode(self.pcdata.isoformat())))
			elif self.Type == u"GPS":
				fileobj.write(xmlescape(unicode(self.pcdata)))
			elif self.Type == u"Unix":
				fileobj.write(xmlescape(u"%.16g" % self.pcdata))
			else:
				# unsupported time type.  not impossible.
				# assume correct thing to do is cast to
				# unicode and let calling code figure out
				# how to ensure that does the correct
				# thing.
				fileobj.write(xmlescape(unicode(self.pcdata)))
		fileobj.write(self.end_tag(u"") + u"\n")
开发者ID:Solaro,项目名称:lalsuite,代码行数:17,代码来源:ligolw.py


示例19: write_simple_tag

def write_simple_tag(xmlfile, name, content, indent=""):
    xmlfile.write(indent)
    xmlfile.write("<")
    xmlfile.write(name)
    xmlfile.write(">")
    xmlfile.write(xmlescape(content))
    xmlfile.write("</")
    xmlfile.write(name)
    xmlfile.write(">\n")
开发者ID:leonardcj,项目名称:Time-Line,代码行数:9,代码来源:timelinexml.py


示例20: write

	def write(self, fileobj = sys.stdout, indent = u""):
		# avoid symbol and attribute look-ups in inner loop
		linelen = self.parentNode.array.shape[0]
		lines = self.parentNode.array.size / linelen
		tokens = itertools.imap(ligolwtypes.FormatFunc[self.parentNode.Type], self.parentNode.array.T.flat)
		islice = itertools.islice
		join = self.Delimiter.join
		w = fileobj.write

		w(self.start_tag(indent))
		if lines:
			newline = u"\n" + indent + ligolw.Indent
			w(newline)
			w(xmlescape(join(islice(tokens, linelen))))
			newline = self.Delimiter + newline
			for i in xrange(lines - 1):
				w(newline)
				w(xmlescape(join(islice(tokens, linelen))))
		w(u"\n" + self.end_tag(indent) + u"\n")
开发者ID:mattpitkin,项目名称:lalsuite,代码行数:19,代码来源:array.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python saxutils.XMLFilterBase类代码示例发布时间:2022-05-26
下一篇:
Python saxutils.xml_escape函数代码示例发布时间: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