def H_parseuri(opts): status = 0 outfile = get_output(opts.args) uris = opts.args.urirefs if not uris: status = 1 print "Usage:\n\t% uriref-cli parseuri uriref1 [uriref2 ...]" print print 'Examples' print '-' * 79 opts.flags.output_format = 'ptable' uris.insert(0, '//example.org/path?v=1') #uris.insert(0, '../path#id') XXX rel-part testing! uris.insert(0, '//[email protected]/path.ext;param#id') uris.insert(0, './../path.ext;param#id') uris.insert(0, 'cid:[email protected]') writer = writers[ opts.flags.output_format ] for uri in uris: match = uriref.match(uri) writer( uri, match, outfile, opts ) return status
def _test(*args): groups = uriref.match(url).groupdict() for dct in ( groups, expected ): for d in dct.keys(): if not dct[d]: del dct[d] assert groups == expected, \ "Testset[%s]: match failure:\n\t%s\n\nShould match result:\n\t%s\n" \ % (url, groups, expected)
def v_absolute_uriref(data, proc=None): import uriref if not data: raise ValueError, "expected Absolute URI" href = data if isinstance(data, tuple): span, href = data m = uriref.match(href) if not m: raise ValueError, "does not match Absolute URI: %s" % href return True
def du_uri_reference(node): rnode = find_first_element(node, nodes.reference) if not rnode: href = du_astext(node).strip() elif 'refuri' in rnode.attributes: href = rnode['refuri'] if href: # XXX how to go about uriref dep import uriref # XXX: relative or absolute m = uriref.match(href) if not m: raise ValueError, "Not a valid URI reference: %s" % href return href
def uriref_test(cycles): for x in xrange(0, cycles): for i in xrange(0, len(fictional_urls)): url, expected = fictional_urls[i] parsed = uriref.match(url).groupdict()
import sys uris = sys.argv[1:] if not uris: uris.insert(0, 'http://[email protected]:4321/path;with-param/to/service.ext?arg&q=v;and=v2#somefragment') uris.insert(0, '*****@*****.**') uris.insert(0, 'cid:[email protected]') uris.insert(0, './../path;param') uris.insert(0, '../path;param') uris.insert(0, '//example.org/path?v=1') uris.insert(0, 'urn://id@net/abspath') uris.insert(0, 'urn:/abspath') #uris.insert(0, ':4') #uris.insert(0, '.root') #uris.insert(0, '@root') uris.insert(0, '//foo/#root') uris.insert(0, '/#root') #uris.insert(0, '#root') uris.insert(0, '/?root') uris.insert(0, '/root') uris.insert(0, 'urn:root') for uri in uris: match = uriref.match(uri) print util.match_groupdict_table(uri, match) print
def print_regex_table(uri): match = uriref.match(uri) print match_groupdict_table(uri, match) print