Example #1
0
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
Example #2
0
 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)
Example #3
0
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
Example #4
0
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
Example #5
0
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()
Example #6
0
    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




Example #7
0
def print_regex_table(uri):
    match = uriref.match(uri)
    print match_groupdict_table(uri, match)
    print