def calendar_query(url, props, filter=None, depth=None): """Send a calendar-query request. :param url: URL to request against :param props: Properties to request (as XML elements or strings :param filter: Optional filter to apply :param depth: Optional Depth :return: Multistat response """ reqxml = ET.Element('{urn:ietf:params:xml:ns:caldav}calendar-query') propxml = ET.SubElement(reqxml, '{DAV:}prop') for prop in props: if isinstance(prop, str): ET.SubElement(propxml, prop) else: propxml.append(prop) if filter is not None: filterxml = ET.SubElement(reqxml, '{urn:ietf:params:xml:ns:caldav}filter') filterxml.append(filter) with report(url, reqxml, depth) as f: assert f.status == 207, f.status respxml = xmlparse(f.read()) return multistat_extract_responses(respxml)
def getprop(url, props, depth=None): """Retrieve properties on a URL or set of URLs. :param url: URL to query :param props: List of properties to retrieve :param depth: Optional depth :return: See `multistat_extract_responses` """ reqxml = ET.Element('{DAV:}propfind') propxml = ET.SubElement(reqxml, '{DAV:}prop') for prop in props: if isinstance(prop, str): ET.SubElement(propxml, prop) else: propxml.append(prop) if depth is None: depth = '0' req = urllib.request.Request(url=url, headers={'Content-Type': 'application/xml'}, data=ET.tostring(reqxml), method='PROPFIND') req.add_header('Depth', depth) with urllib.request.urlopen(req) as f: assert f.status == 207, f.status respxml = xmlparse(f.read()) return multistat_extract_responses(respxml)
def get_by_id(self, id): """Query author by scholarpedia ID: return a single author or None.""" resp = self.config.relative_get('authors/id/' + quote(id)) raw = resp.text if resp and resp.text else None if not raw: return None return self._author_parse(xmlparse(raw))
def get_by_name(self, name): """Query author by name: returns a list of authors.""" resp = self.config.relative_get('authors/name/' + quote(name)) raw = resp.text if resp and resp.text else None if not raw: return [] authors = xmlparse(raw) return [self._author_parse(author) for author in authors]
parser.add_argument('-m', '--mangle', dest='mangle', action='store_true', default=False, help='Mangle possibly-problematic characters in filenames ' '(e.g. if target is a FAT-based filesystem)') parser.add_argument('-f', '--force', dest='force', action='store_true', default=False, help='Continue working if target not empty') args = parser.parse_args() target = args.target if not args.profile in profiles: # XXX - replace with exception? sys.stderr.write("ERROR: unknown profile {profile}\n".format(profile=args.profile)) exit(1) profile = profiles[args.profile] pl_etree = xmlparse("{HOME}/.local/share/rhythmbox/playlists.xml".format_map(os.environ)) root = pl_etree.getroot() playlists = root.findall(".//playlist[@type='static']") def convert(item, converter, profile): print(b"Converting: " + b' => '.join([item['origin'], item['target']])) if converter == 'sox': cmd = ['sox', item['origin']] if 'sox' in profile: cmd.extend(profile['sox']) cmd.append(item['target']) subprocess.call(cmd) elif converter == 'avconv': cmd = ['avconv', '-i', item['origin']] if 'avconv' in profile: