<s> import sys <EOL> reload ( sys ) <EOL> sys . setdefaultencoding ( "<STR_LIT:utf-8>" ) <EOL> import cStringIO , zipfile , os <EOL> import hashlib <EOL> import urllib <EOL> from xml . etree import ElementTree as ET <EOL> from xml . etree import ElementTree as VET <EOL> class NS : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , uri ) : <EOL> self . uri = uri <EOL> def __getattr__ ( self , tag ) : <EOL> return self . uri + tag <EOL> def __call__ ( self , path ) : <EOL> return "<STR_LIT:/>" . join ( getattr ( self , tag ) for tag in path . split ( "<STR_LIT:/>" ) ) <EOL> XHTML = NS ( "<STR_LIT>" ) <EOL> TNA = NS ( "<STR_LIT>" ) <EOL> def get_text_tna ( element , tag , default = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> part = element . find ( TNA ( tag ) ) <EOL> return part . text . strip ( ) if part != None and part . text != None else default <EOL> def prettify ( elem ) : <EOL> """<STR_LIT>""" <EOL> from xml . dom import minidom <EOL> rough_string = ET . tostring ( elem , '<STR_LIT>' ) <EOL> reparsed = minidom . parseString ( rough_string ) <EOL> return reparsed . toprettyxml ( indent = "<STR_LIT:U+0020>" ) <EOL> class FormatInfo : <EOL> def __init__ ( self , pronom_files , format_list = [ ] ) : <EOL> self . info = { } <EOL> self . formats = [ ] <EOL> self . pronom_files = pronom_files <EOL> for f in format_list : <EOL> self . add_format ( f ) <EOL> def save ( self , dst ) : <EOL> """<STR_LIT>""" <EOL> tree = ET . ElementTree ( ET . Element ( '<STR_LIT>' , { '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" } ) ) <EOL> root = tree . getroot ( ) <EOL> for f in self . formats : <EOL> root . append ( f ) <EOL> self . indent ( root ) <EOL> with open ( dst , '<STR_LIT:wb>' ) as out : <EOL> print >> out , ET . tostring ( root ) <EOL> def indent ( self , elem , level = <NUM_LIT:0> ) : <EOL> i = "<STR_LIT:\n>" + level * "<STR_LIT:U+0020>" <EOL> if len ( elem ) : <EOL> if not elem . text or not elem . text . strip ( ) : <EOL> elem . text = i + "<STR_LIT:U+0020>" <EOL> if not elem . tail or not elem . tail . strip ( ) : <EOL> elem . tail = i <EOL> for elem in elem : <EOL> self . indent ( elem , level + <NUM_LIT:1> ) <EOL> if not elem . tail or not elem . tail . strip ( ) : <EOL> elem . tail = i <EOL> else : <EOL> if level and ( not elem . tail or not elem . tail . strip ( ) ) : <EOL> elem . tail = i <EOL> def load_pronom_xml ( self , puid_filter = None ) : <EOL> """<STR_LIT>""" <EOL> formats = [ ] <EOL> try : <EOL> zip = zipfile . ZipFile ( self . pronom_files , '<STR_LIT:r>' ) <EOL> for item in zip . infolist ( ) : <EOL> try : <EOL> stream = zip . open ( item ) <EOL> format = self . parse_pronom_xml ( stream , puid_filter ) <EOL> if format != None : <EOL> formats . append ( format ) <EOL> finally : <EOL> stream . close ( ) <EOL> finally : <EOL> try : <EOL> zip . close ( ) <EOL> except Exception , e : <EOL> sys . stderr . write ( "<STR_LIT>" . format ( self . pronom_files , e ) ) <EOL> sys . exit ( ) <EOL> id_map = { } <EOL> for element in formats : <EOL> puid = element . find ( '<STR_LIT>' ) . text <EOL> pronom_id = element . find ( '<STR_LIT>' ) . text <EOL> id_map [ pronom_id ] = puid <EOL> for element in formats : <EOL> for rel in element . findall ( '<STR_LIT>' ) : <EOL> rel . text = id_map [ rel . text ] <EOL> self . _sort_formats ( formats ) <EOL> self . formats = formats <EOL> def parse_pronom_xml ( self , source , puid_filter = None ) : <EOL> """<STR_LIT>""" <EOL> pronom_xml = ET . parse ( source ) <EOL> pronom_root = pronom_xml . getroot ( ) <EOL> pronom_format = pronom_root . find ( TNA ( '<STR_LIT>' ) ) <EOL> fido_format = ET . Element ( '<STR_LIT>' ) <EOL> for id in pronom_format . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> type = get_text_tna ( id , '<STR_LIT>' ) <EOL> if type == '<STR_LIT>' : <EOL> puid = get_text_tna ( id , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_format , '<STR_LIT>' ) . text = puid <EOL> if puid_filter != None and puid != puid_filter : <EOL> return None <EOL> for id in pronom_format . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> type = get_text_tna ( id , '<STR_LIT>' ) <EOL> if type == '<STR_LIT>' : <EOL> ET . SubElement ( fido_format , '<STR_LIT>' ) . text = get_text_tna ( id , '<STR_LIT>' ) <EOL> elif type == '<STR_LIT>' : <EOL> puid = get_text_tna ( id , '<STR_LIT>' ) <EOL> if puid == '<STR_LIT>' : <EOL> ET . SubElement ( fido_format , '<STR_LIT>' ) . text = '<STR_LIT>' <EOL> elif puid == '<STR_LIT>' : <EOL> ET . SubElement ( fido_format , '<STR_LIT>' ) . text = '<STR_LIT>' <EOL> ET . SubElement ( fido_format , '<STR_LIT:name>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_format , '<STR_LIT:version>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_format , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_format , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> for x in pronom_format . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> ET . SubElement ( fido_format , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> for id in pronom_format . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> type = get_text_tna ( id , '<STR_LIT>' ) <EOL> if type == '<STR_LIT>' : <EOL> ET . SubElement ( fido_format , '<STR_LIT>' ) . text = get_text_tna ( id , '<STR_LIT>' ) <EOL> for x in pronom_format . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> rel = get_text_tna ( x , '<STR_LIT>' ) <EOL> if rel == '<STR_LIT>' : <EOL> ET . SubElement ( fido_format , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> for pronom_sig in pronom_format . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> fido_sig = ET . SubElement ( fido_format , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_sig , '<STR_LIT:name>' ) . text = get_text_tna ( pronom_sig , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_sig , '<STR_LIT>' ) . text = get_text_tna ( pronom_sig , '<STR_LIT>' ) . encode ( '<STR_LIT>' ) <EOL> for pronom_pat in pronom_sig . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> fido_pat = ET . SubElement ( fido_sig , '<STR_LIT>' ) <EOL> pos = fido_position ( get_text_tna ( pronom_pat , '<STR_LIT>' ) ) <EOL> bytes = get_text_tna ( pronom_pat , '<STR_LIT>' ) <EOL> offset = get_text_tna ( pronom_pat , '<STR_LIT>' ) <EOL> max_offset = get_text_tna ( pronom_pat , '<STR_LIT>' ) <EOL> if max_offset == None : <EOL> pass <EOL> regex = convert_to_regex ( bytes , '<STR_LIT>' , pos , offset , max_offset ) <EOL> if regex == "<STR_LIT>" : <EOL> print >> sys . stderr , "<STR_LIT>" , puid , "<STR_LIT>" <EOL> remove = fido_format . findall ( '<STR_LIT>' ) <EOL> for r in remove : <EOL> fido_format . remove ( r ) <EOL> continue <EOL> ET . SubElement ( fido_pat , '<STR_LIT>' ) . text = pos <EOL> ET . SubElement ( fido_pat , '<STR_LIT>' ) . text = bytes <EOL> ET . SubElement ( fido_pat , '<STR_LIT>' ) . text = regex <EOL> fido_details = ET . SubElement ( fido_format , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_details , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) . encode ( '<STR_LIT:utf8>' ) <EOL> ET . SubElement ( fido_details , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_details , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_details , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> for x in pronom_format . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> rel = get_text_tna ( x , '<STR_LIT>' ) <EOL> if rel == '<STR_LIT>' : <EOL> ET . SubElement ( fido_details , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> for x in pronom_format . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> rel = get_text_tna ( x , '<STR_LIT>' ) <EOL> if rel == '<STR_LIT>' : <EOL> ET . SubElement ( fido_details , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> ET . SubElement ( fido_details , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> for x in pronom_format . findall ( TNA ( "<STR_LIT>" ) ) : <EOL> r = ET . SubElement ( fido_details , '<STR_LIT>' ) <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> for id in x . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> type = get_text_tna ( id , '<STR_LIT>' ) <EOL> if type == '<STR_LIT>' : <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = "<STR_LIT>" + get_text_tna ( id , '<STR_LIT>' ) <EOL> else : <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = get_text_tna ( id , '<STR_LIT>' ) + "<STR_LIT::>" + get_text_tna ( id , '<STR_LIT>' ) <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) + "<STR_LIT:U+0020>" + get_text_tna ( x , '<STR_LIT>' ) <EOL> ET . SubElement ( r , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> for x in pronom_format . findall ( TNA ( "<STR_LIT>" ) ) : <EOL> rf = ET . SubElement ( fido_details , '<STR_LIT>' ) <EOL> ET . SubElement ( rf , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> ET . SubElement ( rf , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> checksum = "<STR_LIT>" <EOL> for id in x . findall ( TNA ( '<STR_LIT>' ) ) : <EOL> type = get_text_tna ( id , '<STR_LIT>' ) <EOL> if type == '<STR_LIT>' : <EOL> url = "<STR_LIT>" + get_text_tna ( id , '<STR_LIT>' ) <EOL> ET . SubElement ( rf , '<STR_LIT>' ) . text = url <EOL> m = hashlib . md5 ( ) <EOL> sock = urllib . urlopen ( url ) <EOL> m . update ( sock . read ( ) ) <EOL> sock . close ( ) <EOL> checksum = m . hexdigest ( ) <EOL> else : <EOL> ET . SubElement ( rf , '<STR_LIT>' ) . text = get_text_tna ( id , '<STR_LIT>' ) + "<STR_LIT::>" + get_text_tna ( id , '<STR_LIT>' ) <EOL> ET . SubElement ( rf , '<STR_LIT>' ) . text = "<STR_LIT>" <EOL> ET . SubElement ( rf , '<STR_LIT>' ) . text = get_text_tna ( x , '<STR_LIT>' ) <EOL> checksumElement = ET . SubElement ( rf , '<STR_LIT>' ) <EOL> checksumElement . text = checksum <EOL> checksumElement . attrib [ '<STR_LIT:type>' ] = "<STR_LIT>" <EOL> md = ET . SubElement ( fido_details , '<STR_LIT>' ) <EOL> ET . SubElement ( md , '<STR_LIT:status>' ) . text = '<STR_LIT>' <EOL> ET . SubElement ( md , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> ET . SubElement ( md , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> ET . SubElement ( md , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) <EOL> ET . SubElement ( md , '<STR_LIT>' ) . text = get_text_tna ( pronom_format , '<STR_LIT>' ) . encode ( '<STR_LIT:utf8>' ) <EOL> return fido_format <EOL> def _sort_formats ( self , formatlist ) : <EOL> """<STR_LIT>""" <EOL> def compare_formats ( f1 , f2 ) : <EOL> f1ID = f1 . find ( '<STR_LIT>' ) . text <EOL> f2ID = f2 . find ( '<STR_LIT>' ) . text <EOL> for worse in f1 . findall ( '<STR_LIT>' ) : <EOL> if worse . text == f2ID : <EOL> return - <NUM_LIT:1> <EOL> for worse in f2 . findall ( '<STR_LIT>' ) : <EOL> if worse . text == f1ID : <EOL> return <NUM_LIT:1> <EOL> if f1ID < f2ID : <EOL> return - <NUM_LIT:1> <EOL> elif f1ID == f2ID : <EOL> return <NUM_LIT:0> <EOL> else : <EOL> return <NUM_LIT:1> <EOL> return sorted ( formatlist , cmp = compare_formats ) <EOL> def fido_position ( pronom_position ) : <EOL> """<STR_LIT>""" <EOL> if pronom_position == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> elif pronom_position == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> elif pronom_position == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> elif pronom_position == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" + pronom_position ) <EOL> return '<STR_LIT>' <EOL> def _convert_err_msg ( msg , c , i , chars ) : <EOL> return "<STR_LIT>" . format ( msg , c , i , chars , i * '<STR_LIT:U+0020>' , buf . getvalue ( ) ) <EOL> def doByte ( chars , i , littleendian ) : <EOL> """<STR_LIT>""" <EOL> c1 = '<STR_LIT>' . find ( chars [ i ] . upper ( ) ) <EOL> c2 = '<STR_LIT>' . find ( chars [ i + <NUM_LIT:1> ] . upper ( ) ) <EOL> if ( c1 < <NUM_LIT:0> or c2 < <NUM_LIT:0> ) : <EOL> raise Exception ( _convert_err_msg ( '<STR_LIT>' , chars [ i : i + <NUM_LIT:2> ] , i , chars ) ) <EOL> if littleendian : <EOL> val = chr ( <NUM_LIT:16> * c1 + c2 ) <EOL> else : <EOL> val = chr ( c1 + <NUM_LIT:16> * c2 ) <EOL> return ( escape ( val ) , <NUM_LIT:2> ) <EOL> _ordinary = frozenset ( '<STR_LIT>' ) <EOL> _special = '<STR_LIT>' <EOL> _hex = '<STR_LIT>' <EOL> def _escape_char ( c ) : <EOL> if c in '<STR_LIT:\n>' : <EOL> return '<STR_LIT>' <EOL> elif c == '<STR_LIT:\r>' : <EOL> return '<STR_LIT>' <EOL> elif c in _special : <EOL> return '<STR_LIT:\\>' + c <EOL> else : <EOL> ( high , low ) = divmod ( ord ( c ) , <NUM_LIT:16> ) <EOL> return '<STR_LIT>' + _hex [ high ] + _hex [ low ] <EOL> def escape ( string ) : <EOL> "<STR_LIT>" <EOL> return '<STR_LIT>' . join ( c if c in _ordinary else _escape_char ( c ) for c in string ) <EOL> def calculate_repetition ( char , pos , offset , maxoffset ) : <EOL> """<STR_LIT>""" <EOL> calcbuf = cStringIO . StringIO ( ) <EOL> calcremain = False <EOL> offsetremain = <NUM_LIT:0> <EOL> maxoffsetremain = <NUM_LIT:0> <EOL> if offset != None and offset != '<STR_LIT>' : <EOL> if int ( offset ) > <NUM_LIT> : <EOL> offsetremain = str ( int ( offset ) - <NUM_LIT> ) <EOL> offset = '<STR_LIT>' <EOL> calcremain = True <EOL> if maxoffset != None and maxoffset != '<STR_LIT>' : <EOL> if int ( maxoffset ) > <NUM_LIT> : <EOL> maxoffsetremain = str ( int ( maxoffset ) - <NUM_LIT> ) <EOL> maxoffset = '<STR_LIT>' <EOL> calcremain = True <EOL> if pos == "<STR_LIT>" or pos == "<STR_LIT>" : <EOL> if offset != '<STR_LIT:0>' : <EOL> calcbuf . write ( char + '<STR_LIT:{>' + str ( offset ) ) <EOL> if maxoffset != None : <EOL> calcbuf . write ( '<STR_LIT:U+002C>' + maxoffset ) <EOL> calcbuf . write ( '<STR_LIT:}>' ) <EOL> elif maxoffset != None : <EOL> calcbuf . write ( char + '<STR_LIT>' + maxoffset + '<STR_LIT:}>' ) <EOL> if pos == "<STR_LIT>" : <EOL> if offset != '<STR_LIT:0>' : <EOL> calcbuf . write ( char + '<STR_LIT:{>' + str ( offset ) ) <EOL> if maxoffset != None : <EOL> calcbuf . write ( '<STR_LIT:U+002C>' + maxoffset ) <EOL> calcbuf . write ( '<STR_LIT:}>' ) <EOL> if maxoffset == None : <EOL> calcbuf . write ( '<STR_LIT>' ) <EOL> elif maxoffset != None : <EOL> calcbuf . write ( char + '<STR_LIT>' + maxoffset + '<STR_LIT:}>' ) <EOL> if calcremain : <EOL> calcbuf . write ( calculate_repetition ( char , pos , offsetremain , maxoffsetremain ) ) <EOL> val = calcbuf . getvalue ( ) <EOL> calcbuf . close ( ) <EOL> return val <EOL> def convert_to_regex ( chars , endianness = '<STR_LIT>' , pos = '<STR_LIT>' , offset = '<STR_LIT:0>' , maxoffset = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in endianness : <EOL> littleendian = False <EOL> else : <EOL> littleendian = True <EOL> if len ( offset ) == <NUM_LIT:0> : <EOL> offset = '<STR_LIT:0>' <EOL> if len ( maxoffset ) == <NUM_LIT:0> : <EOL> maxoffset = None <EOL> global buf <EOL> buf = cStringIO . StringIO ( ) <EOL> buf . write ( "<STR_LIT>" ) <EOL> i = <NUM_LIT:0> <EOL> state = '<STR_LIT:start>' <EOL> if '<STR_LIT>' in pos : <EOL> buf . write ( '<STR_LIT>' ) <EOL> buf . write ( calculate_repetition ( '<STR_LIT:.>' , pos , offset , maxoffset ) ) <EOL> if '<STR_LIT>' in pos : <EOL> buf . write ( '<STR_LIT>' ) <EOL> buf . write ( calculate_repetition ( '<STR_LIT:.>' , pos , offset , maxoffset ) ) <EOL> while True : <EOL> if i == len ( chars ) : <EOL> break <EOL> if state == '<STR_LIT:start>' : <EOL> if chars [ i ] . isalnum ( ) : <EOL> state = '<STR_LIT>' <EOL> elif chars [ i ] == '<STR_LIT:[>' and chars [ i + <NUM_LIT:1> ] == '<STR_LIT:!>' : <EOL> state = '<STR_LIT>' <EOL> elif chars [ i ] == '<STR_LIT:[>' : <EOL> state = '<STR_LIT>' <EOL> elif chars [ i ] == '<STR_LIT:{>' : <EOL> state = '<STR_LIT>' <EOL> elif chars [ i ] == '<STR_LIT:(>' : <EOL> state = '<STR_LIT>' <EOL> elif chars [ i ] in '<STR_LIT>' : <EOL> state = '<STR_LIT>' <EOL> else : <EOL> raise Exception ( _convert_err_msg ( '<STR_LIT>' , chars [ i ] , i , chars ) ) <EOL> elif state == '<STR_LIT>' : <EOL> ( byt , inc ) = doByte ( chars , i , littleendian ) <EOL> buf . write ( byt ) <EOL> i += inc <EOL> state = '<STR_LIT:start>' <EOL> elif state == '<STR_LIT>' : <EOL> buf . write ( '<STR_LIT>' ) <EOL> i += <NUM_LIT:2> <EOL> while True : <EOL> if chars [ i ] . isalnum ( ) : <EOL> ( byt , inc ) = doByte ( chars , i , littleendian ) <EOL> buf . write ( byt ) <EOL> i += inc <EOL> elif chars [ i ] == '<STR_LIT:]>' : <EOL> break <EOL> else : <EOL> raise Exception ( _convert_err_msg ( '<STR_LIT>' , chars [ i ] , i , chars ) ) <EOL> buf . write ( '<STR_LIT:)>' ) <EOL> i += <NUM_LIT:1> <EOL> state = '<STR_LIT:start>' <EOL> elif state == '<STR_LIT>' : <EOL> try : <EOL> buf . write ( '<STR_LIT:[>' ) <EOL> i += <NUM_LIT:1> <EOL> ( byt , inc ) = doByte ( chars , i , littleendian ) <EOL> buf . write ( byt ) <EOL> i += inc <EOL> if chars [ i ] != '<STR_LIT::>' : <EOL> return "<STR_LIT>" <EOL> buf . write ( '<STR_LIT:->' ) <EOL> i += <NUM_LIT:1> <EOL> ( byt , inc ) = doByte ( chars , i , littleendian ) <EOL> buf . write ( byt ) <EOL> i += inc <EOL> if chars [ i ] != '<STR_LIT:]>' : <EOL> return "<STR_LIT>" <EOL> buf . write ( '<STR_LIT:]>' ) <EOL> i += <NUM_LIT:1> <EOL> except Exception : <EOL> print _convert_err_msg ( '<STR_LIT>' , chars [ i ] , i , chars ) <EOL> raise <EOL> if i < len ( chars ) and chars [ i ] == '<STR_LIT:{>' : <EOL> state = '<STR_LIT>' <EOL> else : <EOL> state = '<STR_LIT:start>' <EOL> elif state == '<STR_LIT>' : <EOL> buf . write ( '<STR_LIT>' ) <EOL> i += <NUM_LIT:1> <EOL> while True : <EOL> if chars [ i ] . isalnum ( ) : <EOL> ( byt , inc ) = doByte ( chars , i , littleendian ) <EOL> buf . write ( byt ) <EOL> i += inc <EOL> elif chars [ i ] == '<STR_LIT:|>' : <EOL> buf . write ( '<STR_LIT:|>' ) <EOL> i += <NUM_LIT:1> <EOL> elif chars [ i ] == '<STR_LIT:)>' : <EOL> break <EOL> elif chars [ i ] == '<STR_LIT:[>' : <EOL> buf . write ( '<STR_LIT:[>' ) <EOL> i += <NUM_LIT:1> <EOL> ( byt , inc ) = doByte ( chars , i , littleendian ) <EOL> buf . write ( byt ) <EOL> i += inc <EOL> if chars [ i ] != '<STR_LIT::>' : <EOL> return "<STR_LIT>" <EOL> buf . write ( '<STR_LIT:->' ) <EOL> i += <NUM_LIT:1> <EOL> ( byt , inc ) = doByte ( chars , i , littleendian ) <EOL> buf . write ( byt ) <EOL> i += inc <EOL> if chars [ i ] != '<STR_LIT:]>' : <EOL> return "<STR_LIT>" <EOL> buf . write ( '<STR_LIT:]>' ) <EOL> i += <NUM_LIT:1> <EOL> else : <EOL> raise Exception ( _convert_err_msg ( ( '<STR_LIT>' ) . format ( state ) , chars [ i ] , i , chars ) ) <EOL> buf . write ( '<STR_LIT:)>' ) <EOL> i += <NUM_LIT:1> <EOL> state = '<STR_LIT:start>' <EOL> elif state in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> buf . write ( '<STR_LIT:.>' ) <EOL> buf . write ( '<STR_LIT:{>' ) <EOL> i += <NUM_LIT:1> <EOL> while True : <EOL> if chars [ i ] . isalnum ( ) : <EOL> buf . write ( chars [ i ] ) <EOL> i += <NUM_LIT:1> <EOL> elif chars [ i ] == '<STR_LIT:->' : <EOL> buf . write ( '<STR_LIT:U+002C>' ) <EOL> i += <NUM_LIT:1> <EOL> elif chars [ i ] == '<STR_LIT:*>' : <EOL> i += <NUM_LIT:1> <EOL> elif chars [ i ] == '<STR_LIT:}>' : <EOL> break <EOL> else : <EOL> raise Exception ( _convert_err_msg ( '<STR_LIT>' , chars [ i ] , i , chars ) ) <EOL> buf . write ( '<STR_LIT:}>' ) <EOL> i += <NUM_LIT:1> <EOL> state = '<STR_LIT:start>' <EOL> elif state == '<STR_LIT>' : <EOL> if chars [ i ] == '<STR_LIT:*>' : <EOL> buf . write ( '<STR_LIT>' ) <EOL> i += <NUM_LIT:1> <EOL> elif chars [ i ] == '<STR_LIT:+>' : <EOL> buf . write ( '<STR_LIT>' ) <EOL> i += <NUM_LIT:1> <EOL> elif chars [ i ] == '<STR_LIT:?>' : <EOL> if chars [ i + <NUM_LIT:1> ] != '<STR_LIT:?>' : <EOL> raise Exception ( _convert_err_msg ( '<STR_LIT>' , chars [ i + <NUM_LIT:1> ] , i + <NUM_LIT:1> , chars ) ) <EOL> buf . write ( '<STR_LIT>' ) <EOL> i += <NUM_LIT:2> <EOL> state = '<STR_LIT:start>' <EOL> else : <EOL> raise Exception ( '<STR_LIT>' . format ( state ) ) <EOL> if '<STR_LIT>' in pos : <EOL> buf . write ( calculate_repetition ( '<STR_LIT:.>' , pos , offset , maxoffset ) ) <EOL> buf . write ( '<STR_LIT>' ) <EOL> val = buf . getvalue ( ) <EOL> buf . close ( ) <EOL> return val <EOL> def main ( arg = None ) : <EOL> import sys <EOL> from argparselocal import ArgumentParser <EOL> if arg != None : <EOL> arglist = arg <EOL> else : <EOL> arglist = sys . argv [ <NUM_LIT:1> : ] <EOL> mydir = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> versionsFile = os . path . join ( mydir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> versions = VET . parse ( versionsFile ) <EOL> except Exception , e : <EOL> sys . stderr . write ( "<STR_LIT>" . format ( e ) ) <EOL> sys . exit ( ) <EOL> xml_pronomSignature = os . path . join ( mydir , '<STR_LIT>' , versions . find ( '<STR_LIT>' ) . text ) <EOL> xml_pronomZipFile = os . path . join ( mydir , '<STR_LIT>' , "<STR_LIT>" . format ( versions . find ( '<STR_LIT>' ) . text ) ) <EOL> parser = ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = xml_pronomZipFile , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = xml_pronomSignature , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( arglist ) <EOL> info = FormatInfo ( args . input ) <EOL> info . load_pronom_xml ( args . puid ) <EOL> info . save ( args . output ) <EOL> print >> sys . stderr , '<STR_LIT>' . format ( len ( info . formats ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
