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')
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)
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')
def write_additions(deltas, out): for lang, (chars, refs, cldr_sources) in sorted(deltas.items()): locale = icu.Locale(lang) out.write('\n\n### %s: %s\n\n' % (lang, locale.getDisplayName())) reflist = ['R%d' % i for i in range(1, len(refs) + 1)] references = ' references="%s"' % ' '.join(reflist) if reflist else '' if locale.getScript() in ('Arab', 'Thaa', 'Nkoo', 'Syrc'): characterOrder = 'right-to-left' else: characterOrder = 'left-to-right' out.write('```xml\n') out.write( CLDR_EXEMPLAR_XML_START % { 'language': locale.getLanguage(), 'script': locale.getScript(), 'characterOrder': characterOrder, 'lineOrder': 'top-to-bottom', 'characters': xmlescape(format_unicodeset(chars)), 'references': xmlescape(references), }) if refs: out.write('\t<references>\n') for i, ref in enumerate(refs): out.write( CLDR_EXEMPLAR_XML_REFERENCE % { 'type': reflist[i], 'uri': xmlescape(ref), 'text': xmlescape(get_reference_description(ref)), }) out.write('\t</references>\n') out.write('</ldml>\n```\n\n')
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')
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')
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")
def POST(self, name): xml = web.data().decode('1251').encode('utf8') #print '*'*40 #print xml #print 'self.kkm:', self.kkm.__name__, self.kkm.PORT, self.kkm.BAUDRATE rr = kkmExec(self.kkm, xml) #print rr #xHandle = hex(id(urls)) if '0000' == rr[0]: #r = '<respons handle="%s" />' % hex(id(urls)) r = '<respons handle="%s">%s</respons>' % (self.xHandle, rr[-1]) elif -2 == rr[0]: print 'web.data:', xml #qnm = 'data/%04d%02d%02d-%02d%02d%02d.xml' % time.localtime()[:6] #with open(qnm, 'wb') as f: # f.write(xml) #time.sleep(0.5) if isinstance(rr[0], int): rc = str(rr[0]) else: rc = int(rr[0], 16) r = '<respons handle="%s" error="%s">%s</respons>' % (self.xHandle, rc, xmlescape(rr[1].encode('1251'))) else: if isinstance(rr[0], int): rc = str(rr[0]) else: rc = int(rr[0], 16) r = '<respons handle="%s" error="%s">%s</respons>' % (self.xHandle, rc, xmlescape(rr[1].encode('1251'))) #print 'respons:', r return r
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)
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)
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))
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))
def create_build(self, environment, task, result, log, duration=None, description=None): ''' Add a build report related environment : name of the casa_distro environment. task : name of the task that is performed by this build (e.g. src, configure, build, etc.) result : integer value representing the result of the build any non-zero value means failure log : console output of the build duration : (optional) duration of the build in milliseconds description : (optional) description text attached to the build ''' # Python 2 need binascii module to convert str # to hex string. In Python 3, bytes have an hex() method. if not isinstance(log, six.binary_type): log = log.encode('UTF8') hex_log = binascii.hexlify(log) r = self.post('job/{0}/postBuildResult'.format(environment), headers={'Content-Type': 'application/xml'}, data=self.build_xml.format( build=xmlescape(str(task)), hex_log=hex_log, result=result or 0, duration=int(round(duration)) if duration else 0, description=xmlescape(description or ''), )) r.raise_for_status()
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
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')
def template_rss(posts: List[dict], config: Optional[dict] = None) -> str: config = config or {} posts = [ post for post in posts if TAG_DRAFT not in post.get('tags', []) and TAG_INDEX not in post.get('tags', []) ] posts = sorted(posts, key=lambda post: post['last_modified'] ) # type: ignore # mypy fails to infer lambda type base_url = xmlescape(config.get('site', {}).get('base_url', '')) title = xmlescape(config.get('site', {}).get('title', '')) title = base_url if (title == '' and base_url != '') else title rss_xml = [] rss_xml.append('''<?xml version="1.0" encoding="utf-8" standalone="yes"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel>''') rss_xml.append(f''' <title>{title}</title>''') rss_xml.append(f''' <link>{base_url}</link>''') rss_xml.append(f''' <description></description>''') rss_xml.append( f''' <generator>Good Generator.py -- ggpy -- https://oliz.io/ggpy</generator>''' ) rss_xml.append( f''' <lastBuildDate>{utils.formatdate()}</lastBuildDate>''') rss_xml.append( f''' <atom:link href="{'rss.xml' if base_url == '' else f'{base_url}/rss.xml'}" rel="self" type="application/rss+xml" />''' ) for post in posts[-10:]: # Limit to the lastest 10 posts escaped_url = xmlescape(post.get('url', '')) escaped_title = xmlescape(post.get('title', '')) escaped_title = escaped_url if ( escaped_title == '' and escaped_url != '') else escaped_title date_to_format = post.get('date', '') date_to_format = post.get( 'last_modified', '') if date_to_format == '' else date_to_format date_to_format = now_utc_formatted( ) if date_to_format == '' else date_to_format pub_date = '' try: pub_date = utils.format_datetime( datetime.datetime.strptime(date_to_format, '%Y-%m-%dT%H:%M:%S%z')) except ValueError: pub_date = utils.format_datetime( datetime.datetime.strptime(date_to_format, '%Y-%m-%d')) rss_xml.append(f''' <item>''') rss_xml.append(f''' <title>{escaped_title}</title>''') rss_xml.append(f''' <link>{escaped_url}</link>''') rss_xml.append(f''' <pubDate>{xmlescape(pub_date)}</pubDate>''') rss_xml.append(f''' <guid>{escaped_url}</guid>''') rss_xml.append( f''' <description>{xmlescape(post.get('html_section', ''))}</description>''' ) rss_xml.append(f''' </item>''') rss_xml.append(''' </channel> </rss>\n''') return '\n'.join(rss_xml)
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
def escapeit(sval, EXTRAS=None): global _h _h = HTMLParser() # note, xmlescape and unescape do not work with utf-8 bytestrings # so pre-convert to full unicode and then convert back since our result xml is utf-8 encoded uval = sval.decode('utf-8') if EXTRAS: ures = xmlescape(_h.unescape(uval), EXTRAS) else: ures = xmlescape(_h.unescape(uval)) return ures.encode('utf-8')
def print_status(metadata): if metadata is None: print(flush=True) return artist = metadata.get("xesam:artist") if artist and artist[0]: print("<span foreground=\"red\">", xmlescape(artist[0]), "</span> ", sep="", end="") title = metadata.get("xesam:title") print(xmlescape(title), flush=True)
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")
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")
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>"
def enqueue_job(event): event_id = str(event['id']) work_doc = os.path.join(tempdir.name, event_id + '.aep') script_doc = os.path.join(tempdir.name, event_id + '.jsx') ascript_doc = os.path.join(tempdir.name, event_id + '.scpt') intermediate_clip = os.path.join(tempdir.name, event_id + '.mov') with open(args.project + 'intro.jsx', 'r') as fp: scriptstr = fp.read() for key, value in event.items(): scriptstr = scriptstr.replace("$" + str(key), xmlescape(str(value))) with open(script_doc, 'w') as fp: fp.write(scriptstr) copyfile(args.project + 'intro.aep', work_doc) copyfile(args.project + 'intro.scpt', ascript_doc) run('osascript {ascript_path} {jobpath} {scriptpath}', jobpath=work_doc, scriptpath=script_doc, ascript_path=ascript_doc) run('/Applications/Adobe\ After\ Effects\ CC\ 2018/aerender -project {jobpath} -comp "intro" -output {locationpath}', jobpath=work_doc, locationpath=intermediate_clip) return event_id
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)
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))
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")
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
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 hd1080p.compressorsetting -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)
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)
def play(files_urls, device): video_data = { "uri_video": files_urls["file_video"], "type_video": os.path.splitext(files_urls["file_video"])[1][1:], } if "file_subtitle" in files_urls and files_urls["file_subtitle"]: video_data.update({ "uri_sub": files_urls["file_subtitle"], "type_sub": os.path.splitext(files_urls["file_subtitle"])[1][1:] }) metadata = pkgutil.get_data( "nanodlna", "templates/metadata-video_subtitle.xml").decode("UTF-8") video_data["metadata"] = xmlescape(metadata.format(**video_data)) else: video_data["metadata"] = "" send_dlna_action(device, video_data, "SetAVTransportURI") send_dlna_action(device, video_data, "Play")
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")
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")
def write_simple_tag(file, name, content, indent=""): file.write(indent) file.write("<") file.write(name) file.write(">") file.write(xmlescape(content)) file.write("</") file.write(name) file.write(">\n")
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"")) fileobj.write(u"\n")
def format(self, tokensource, outfile): # lastval is a string we use for caching # because it's possible that an lexer yields a number # of consecutive tokens with the same token type. # to minimize the size of the generated html markup we # try to join the values of same-type tokens here lastval = '' lasttype = None # wrap the whole output with <pre> outfile.write('<para backcolor="%s"><font name="%s" size="%d">' % (self.background_color, self.font_name, self.font_size)) for ttype, value in tokensource: # if the token type doesn't exist in the stylemap # we try it with the parent of the token type # eg: parent of Token.Literal.String.Double is # Token.Literal.String while ttype not in self.styles: ttype = ttype.parent if ttype == lasttype: # the current token type is the same of the last # iteration. cache it lastval += value else: # not the same token as last iteration, but we # have some data in the buffer. wrap it with the # defined style and write it to the output file if lastval: stylebegin, styleend = self.styles[lasttype] outfile.write(stylebegin + xmlescape(lastval).encode(self.encoding) + styleend) # set lastval/lasttype to current values lastval = value lasttype = ttype # if something is left in the buffer, write it to the # output file, then close the opened <pre> tag if lastval: stylebegin, styleend = self.styles[lasttype] outfile.write(stylebegin + xmlescape(lastval).encode(self.encoding) + styleend) outfile.write('</font></para>\n')
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 if self.parentNode.array.size else 0 tokens = map(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 range(lines - 1): w(newline) w(xmlescape(join(islice(tokens, linelen)))) w(u"\n" + self.end_tag(indent) + u"\n")
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")
def processChapter(self, chapter): self.num_chapters = getattr(self, 'num_chapters', 0) + 1 chapter.id = 'chapter_%02d' % self.num_chapters title = xmlescape(chapter.title) chapter.xml = misc.xhtml_page( title=title, body_content=[E.h1({'style': 'margin-top:15%;font-size:200%;text-align:center;'}, title)] ) self.container.addArticle(chapter)
def _generate_meta(self, m): data = """<?xml version="1.0" encoding="UTF-8"?><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.1.1-Exiv2"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:tiff="http://ns.adobe.com/tiff/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" """ with self._client_lock: post = self._client.get_post(m, wanted=["tagname", "tagdata", "rotate"]) if "rotate" in post and post.rotate.value in orient: data += 'tiff:Orientation="' + str(orient[post.rotate.value]) + '"' data += "><dc:subject><rdf:Bag>" tags = [tag.pname + ((u"=" + unicode(tag.value)) if tag.value else u"") for tag in post.tags] data += "".join(["<rdf:li>" + xmlescape(tn).encode("utf-8") + "</rdf:li>" for tn in sorted(tags)]) data += "</rdf:Bag></dc:subject></rdf:Description></rdf:RDF></x:xmpmeta>" return data
def writeToken(self, ttype, tvalue, outfile): if self.__emit_line_numbers or self.__output_format.endswith("latex"): lines = tvalue.splitlines(True) for line in lines: if self.__emit_line_numbers: self.writeLineNo(self.__line_no, outfile) self.writeOpeningTags(ttype, outfile) outfile.write(xmlescape(line)) self.writeClosingTags(ttype, outfile) if re.search(r"\r|(?:\r)?\n$", line): self.__line_no += self.__line_step self.__new_line = True #end if #end for else: self.writeOpeningTags(ttype, outfile) outfile.write(xmlescape(tvalue)) self.writeClosingTags(ttype, outfile)
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: # we have to strip quote characters from string # formats (see comment above) fileobj.write(xmlescape(ligolwtypes.FormatFunc[self.Type](self.pcdata).strip(u"\""))) fileobj.write(self.end_tag(u"") + u"\n")
def writeToken(self, ttype, tvalue, outfile): if self.__emit_line_numbers or self.__output_format.endswith("latex"): lines = tvalue.splitlines(True) for line in lines: if self.__emit_line_numbers: self.writeLineNo(self.__line_no, outfile) self.writeOpeningTags(ttype, outfile) outfile.write(xmlescape(line)) self.writeClosingTags(ttype, outfile) if re.search(r"\r|(?:\r)?\n$", line): self.__line_no += self.__line_step self.__new_line = True # end if # end for else: self.writeOpeningTags(ttype, outfile) outfile.write(xmlescape(tvalue)) self.writeClosingTags(ttype, outfile)
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) fileobj.write( xmlescape(ligolwtypes.FormatFunc[self.Type]( self.pcdata).strip(u"\""))) fileobj.write(self.end_tag(u"") + u"\n")
def create(self, overwrite, dryrun, description, tag=None): if description: # tag builds (this will be reworked in the future) if tag: desc_el = etree.SubElement(self.xml, "description") desc_el.text = xmlescape(tag) else: # 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")
def write(self, fileobj=sys.stdout, indent=u""): # retrieve the .write() method of the file object to avoid # doing the attribute lookup in loops w = fileobj.write # loop over parent's rows. This is complicated because we # need to not put a delimiter at the end of the last row # unless it ends with a null token w(self.start_tag(indent)) rowdumper = tokenizer.RowDumper(self.parentNode.columnnames, [ ligolwtypes.FormatFunc[coltype] for coltype in self.parentNode.columntypes ], self.Delimiter) rowdumper.dump(self.parentNode) try: line = next(rowdumper) except StopIteration: # table is empty pass else: # write first row newline = u"\n" + indent + ligolw.Indent w(newline) # the xmlescape() call replaces things like "<" # with "<" so that the string will not confuse # an XML parser when the file is read. turning # "<" back into "<" during file reading is # handled by the XML parser, so there is no code # in Glue related to that. w(xmlescape(line)) # now add delimiter and write the remaining rows newline = rowdumper.delimiter + newline for line in rowdumper: w(newline) w(xmlescape(line)) if rowdumper.tokens and rowdumper.tokens[-1] == u"": # the last token of the last row was null: # add a final delimiter to indicate that a # token is present w(rowdumper.delimiter) w(u"\n" + self.end_tag(indent) + u"\n")
def write(self, fileobj = sys.stdout, indent = u""): """ Recursively write an element and it's children to a file. """ fileobj.write(self.start_tag(indent) + u"\n") for c in self.childNodes: if c.tagName not in self.validchildren: raise ElementError("invalid child %s for %s" % (c.tagName, self.tagName)) c.write(fileobj, indent + Indent) if self.pcdata is not None: fileobj.write(xmlescape(self.pcdata)) fileobj.write(u"\n") fileobj.write(self.end_tag(indent) + u"\n")
def processChapter(self, chapter): self.num_chapters = getattr(self, 'num_chapters', 0) + 1 chapter.id = 'chapter_%02d' % self.num_chapters title = xmlescape(chapter.title) chapter.xml = misc.xhtml_page( title=title, body_content=[ E.h1( { 'style': 'margin-top:15%;font-size:200%;text-align:center;' }, title) ]) self.container.addArticle(chapter)
def escape(string, display): res = xmlescape(string, { '!': '!', '<': '$#60;', '>': '$#62;', '=': '$#61;', '~': '$#126;', '"': '"' }) if display == True: additional = {'_': '​_​'} for s,r in additional.items(): res = res.replace(s, r) return res
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: # we have to strip quote characters from string # formats (see comment above) fileobj.write( xmlescape(ligolwtypes.FormatFunc[self.Type]( self.pcdata).strip(u"\""))) fileobj.write(self.end_tag(u"") + u"\n")
def on_get_value(self, rowref, column): entry = rowref[1] if column is 0: return GtkIconWrapper.get_scaled_icon(entry.icon, ICON_SIZE) # if hasattr(entry, 'icon_pixmap'): # return entry.icon_pixmap # else: # TODO: Enqueue # entry.icon_pixmap = GtkIconWrapper.get_scaled_icon(entry.icon, ICON_SIZE) # return None elif column is 1: return entry.name elif column is 2: return xmlescape(entry.summarize())
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")
def write(self, fileobj = sys.stdout, indent = u""): """ Recursively write an element and it's children to a file. """ fileobj.write(self.start_tag(indent)) fileobj.write(u"\n") for c in self.childNodes: if c.tagName not in self.validchildren: raise ElementError("invalid child %s for %s" % (c.tagName, self.tagName)) c.write(fileobj, indent + Indent) if self.pcdata is not None: fileobj.write(xmlescape(self.pcdata)) fileobj.write(u"\n") fileobj.write(self.end_tag(indent)) fileobj.write(u"\n")