Ignore:
Timestamp:
Jun 26, 2010, 3:16:01 PM (9 years ago)
Author:
cameron
Message:

Add Qname validation routine for namespaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/parabix2.py

    r416 r417  
    583583                              ('name_check', bitutil.bitstream2string(name_check, lgth))])
    584584
     585def validate_namespace_names(lex, name_stream):
     586        """ Ensure that any colon (namespace separator) in a name divides the
     587        name into nonempty namespace prefix and local-part components, neither
     588        of which contain colons.
     589        >>> demo_validate_namespace_names("<a:b  xmlns: = '3' :x = '1' y: = '2'/>")
     590        input data  : <a:b  xmlns: = '3' :x = '1' y: = '2'/>
     591        names       : _111__111111_______11_______11________
     592        NCname_error: ____________1______1__________1_______
     593        >>> demo_validate_namespace_names("<a  xmlns:g = '3' a:x = '1' y::b = '2'/>")
     594        input data  : <a  xmlns:g = '3' a:x = '1' y::b = '2'/>
     595        names       : _1__1111111_______111_______1111________
     596        NCname_error: ______________________________1_________
     597        """
     598        name_cursor = name_stream & ~bitutil.Advance(name_stream)
     599        void_prefix_err = name_cursor & lex.Colon
     600        namespace_sep = bitutil.ScanThru(name_cursor, lex.NameScan &~ lex.Colon) & lex.Colon
     601        local_part_start = bitutil.Advance(namespace_sep)
     602        local_part_err = local_part_start &~ lex.NameScan
     603        colon2_err = bitutil.ScanThru(local_part_start, lex.NameScan &~ lex.Colon) & lex.Colon
     604        return void_prefix_err | local_part_err | colon2_err
     605       
     606def demo_validate_namespace_names(u8data):
     607        lgth = len(u8data)
     608        (bit, EOF_mask) = bitutil.transpose_streams(u8data)
     609        (u8, control, lex) = byteclass.classify_bytes(bit)
     610        lex = add_multiliterals(lex)
     611        markup1 = parse_CtCDPI(lex, EOF_mask)
     612        callouts = parse_tags(lex, markup1.CtCDPI_mask, EOF_mask)
     613        name_stream = callouts.ElemNames | callouts.AttNames
     614        name_check = validate_namespace_names(lex, name_stream)
     615        bitutil.print_aligned_u8_byte_streams([('input data', u8data),
     616                              ('names', bitutil.bitstream2string(name_stream, lgth)),
     617                              ('NCname_error', bitutil.bitstream2string(name_check, lgth))])
     618
     619
    585620def parabix_parse(u8data):
    586621        # Transpose to parallel bit streams and prepare an EOF mask.
Note: See TracChangeset for help on using the changeset viewer.