<s> """<STR_LIT>""" <EOL> import itertools <EOL> import struct <EOL> from conary import versions <EOL> from conary . deps import deps <EOL> from conary . lib import sha1helper <EOL> from conary . lib . ext import pack <EOL> from conary . lib . ext import streams as cstreams <EOL> IntStream = cstreams . IntStream <EOL> ShortStream = cstreams . ShortStream <EOL> StringStream = cstreams . StringStream <EOL> StreamSet = cstreams . StreamSet <EOL> ByteStream = cstreams . ByteStream <EOL> LongLongStream = cstreams . LongLongStream <EOL> splitFrozenStreamSet = cstreams . splitFrozenStreamSet <EOL> whiteOutFrozenStreamSet = cstreams . whiteOutFrozenStreamSet <EOL> SMALL = cstreams . SMALL <EOL> LARGE = cstreams . LARGE <EOL> DYNAMIC = cstreams . DYNAMIC <EOL> SKIP_UNKNOWN = cstreams . SKIP_UNKNOWN <EOL> PRESERVE_UNKNOWN = cstreams . PRESERVE_UNKNOWN <EOL> class InfoStream ( object ) : <EOL> __slots__ = ( ) <EOL> def __deepcopy__ ( self , mem ) : <EOL> return self . __class__ ( self . freeze ( ) ) <EOL> def copy ( self ) : <EOL> return self . __class__ ( self . freeze ( ) ) <EOL> def freeze ( self , skipSet = None ) : <EOL> raise NotImplementedError <EOL> def diff ( self , them ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def twm ( self , diff , base ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def __eq__ ( self , them , skipSet = None ) : <EOL> raise NotImplementedError <EOL> def __ne__ ( self , them ) : <EOL> return not self . __eq__ ( them ) <EOL> class MtimeStream ( IntStream ) : <EOL> def __eq__ ( self , other , skipSet = None ) : <EOL> return True <EOL> def twm ( self , diff , base ) : <EOL> IntStream . twm ( self , diff , base ) <EOL> return False <EOL> class Md5Stream ( StringStream ) : <EOL> def freeze ( self , skipSet = None ) : <EOL> assert ( len ( self ( ) ) == <NUM_LIT:16> ) <EOL> return self ( ) <EOL> def thaw ( self , data ) : <EOL> if data : <EOL> assert ( len ( data ) == <NUM_LIT:16> ) <EOL> self . set ( data ) <EOL> def twm ( self , diff , base ) : <EOL> assert ( len ( diff ) == <NUM_LIT:16> ) <EOL> assert ( len ( base ( ) ) == <NUM_LIT:16> ) <EOL> assert ( len ( self ( ) ) == <NUM_LIT:16> ) <EOL> StringStream . twm ( self , diff , base ) <EOL> def set ( self , val ) : <EOL> assert ( len ( val ) == <NUM_LIT:16> ) <EOL> StringStream . set ( val ) <EOL> def setFromString ( self , val ) : <EOL> s = struct . pack ( "<STR_LIT>" , int ( val [ <NUM_LIT:0> : <NUM_LIT:8> ] , <NUM_LIT:16> ) , <EOL> int ( val [ <NUM_LIT:8> : <NUM_LIT:16> ] , <NUM_LIT:16> ) , int ( val [ <NUM_LIT:16> : <NUM_LIT> ] , <NUM_LIT:16> ) , <EOL> int ( val [ <NUM_LIT> : <NUM_LIT:32> ] , <NUM_LIT:16> ) ) <EOL> StringStream . set ( s ) <EOL> class Sha1Stream ( StringStream ) : <EOL> __slots__ = ( ) <EOL> allowedSize = ( <NUM_LIT:20> , ) <EOL> def freeze ( self , skipSet = None ) : <EOL> assert ( len ( self ( ) ) in self . allowedSize ) <EOL> return StringStream . freeze ( self , skipSet = skipSet ) <EOL> def twm ( self , diff , base ) : <EOL> StringStream . twm ( self , diff , base ) <EOL> def set ( self , val ) : <EOL> assert ( len ( val ) in self . allowedSize ) <EOL> StringStream . set ( self , val ) <EOL> def compute ( self , message ) : <EOL> self . set ( sha1helper . sha1String ( message ) ) <EOL> def verify ( self , message ) : <EOL> return self ( ) == sha1helper . sha1String ( message ) <EOL> def setFromString ( self , hexdigest ) : <EOL> StringStream . set ( self , sha1helper . sha1FromString ( hexdigest ) ) <EOL> class AbsoluteSha1Stream ( Sha1Stream ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( ) <EOL> allowedSize = ( <NUM_LIT:0> , <NUM_LIT:20> ) <EOL> def diff ( self , them ) : <EOL> return self . freeze ( ) <EOL> class NonStandardSha256Stream ( StringStream ) : <EOL> allowedSize = ( <NUM_LIT:32> , ) <EOL> def freeze ( self , skipSet = None ) : <EOL> assert ( len ( self ( ) ) in self . allowedSize ) <EOL> return StringStream . freeze ( self , skipSet = skipSet ) <EOL> def twm ( self , diff , base ) : <EOL> raise NotImplementedError <EOL> def set ( self , val ) : <EOL> assert ( len ( val ) in self . allowedSize ) <EOL> StringStream . set ( self , val ) <EOL> def compute ( self , message ) : <EOL> self . set ( sha1helper . nonstandardSha256String ( message ) ) <EOL> def verify ( self , message ) : <EOL> return self ( ) == sha1helper . nonstandardSha256String ( message ) <EOL> def setFromString ( self , hexdigest ) : <EOL> StringStream . set ( self , sha1helper . sha256FromString ( hexdigest ) ) <EOL> class FrozenVersionStream ( InfoStream ) : <EOL> __slots__ = "<STR_LIT:v>" <EOL> def __call__ ( self ) : <EOL> return self . v <EOL> def set ( self , val ) : <EOL> assert ( not val or min ( val . timeStamps ( ) ) > <NUM_LIT:0> ) <EOL> self . v = val <EOL> def freeze ( self , skipSet = { } ) : <EOL> if not self . v : <EOL> return "<STR_LIT>" <EOL> elif skipSet and '<STR_LIT>' in skipSet : <EOL> return self . v . asString ( ) <EOL> else : <EOL> return self . v . freeze ( ) <EOL> def diff ( self , them ) : <EOL> if self . v != them . v : <EOL> return self . freeze ( ) <EOL> return None <EOL> def thaw ( self , frz ) : <EOL> if frz : <EOL> self . v = versions . ThawVersion ( frz ) <EOL> else : <EOL> self . v = None <EOL> def twm ( self , diff , base ) : <EOL> if self . v == base . v : <EOL> self . thaw ( diff ) <EOL> return False <EOL> elif self . v != diff : <EOL> return True <EOL> return False <EOL> def __eq__ ( self , other , skipSet = None ) : <EOL> return other . __class__ == self . __class__ and self . v == other . v <EOL> def __init__ ( self , v = None ) : <EOL> self . thaw ( v ) <EOL> class StringVersionStream ( FrozenVersionStream ) : <EOL> __slots__ = [ ] <EOL> def set ( self , val ) : <EOL> self . v = val <EOL> def thaw ( self , frz ) : <EOL> if frz : <EOL> self . v = versions . VersionFromString ( frz ) <EOL> else : <EOL> self . v = None <EOL> def freeze ( self , skipSet = { } ) : <EOL> if not self . v : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return self . v . asString ( ) <EOL> class DepsAttr ( object ) : <EOL> def __get__ ( self , inst , cl ) : <EOL> return inst <EOL> class BaseDependenciesStream ( InfoStream ) : <EOL> """<STR_LIT>""" <EOL> deps = DepsAttr ( ) <EOL> def __call__ ( self ) : <EOL> return self <EOL> def set ( self , val ) : <EOL> assert ( val is not None ) <EOL> self . _members = val . _members <EOL> self . hash = None <EOL> def diff ( self , them ) : <EOL> if self != them : <EOL> return self . freeze ( ) <EOL> return None <EOL> def twm ( self , diff , base ) : <EOL> self . thaw ( diff ) <EOL> return False <EOL> class DependenciesStream ( deps . DependencySet , BaseDependenciesStream ) : <EOL> pass <EOL> class FlavorsStream ( deps . Flavor , BaseDependenciesStream ) : <EOL> pass <EOL> class OptionalFlavorStream ( InfoStream ) : <EOL> __slots__ = ( '<STR_LIT>' ) <EOL> def __eq__ ( self , other , skipSet = None ) : <EOL> return self . deps == other . deps <EOL> def __call__ ( self ) : <EOL> return self . deps <EOL> def freeze ( self , skipSet = None ) : <EOL> if self . deps is None : <EOL> return '<STR_LIT>' <EOL> return self . deps . freeze ( ) <EOL> def thaw ( self , s ) : <EOL> if s == '<STR_LIT>' : <EOL> self . deps = None <EOL> else : <EOL> self . deps = FlavorsStream ( s ) <EOL> def diff ( self , other , skipSet = None ) : <EOL> if self . deps is None and other . deps is None : <EOL> return '<STR_LIT>' <EOL> elif self . deps is None : <EOL> return '<STR_LIT>' ; <EOL> return self . deps . diff ( other ) <EOL> def set ( self , val ) : <EOL> if val is None : <EOL> self . deps = None <EOL> else : <EOL> self . deps = FlavorsStream ( val . freeze ( ) ) <EOL> def twm ( self , diff , base ) : <EOL> if diff is '<STR_LIT>' : <EOL> self . deps = None <EOL> else : <EOL> if self . deps is None : <EOL> self . deps = FlavorsStream ( ) <EOL> self . deps . twm ( diff , self . deps ) <EOL> def __init__ ( self , frz = None ) : <EOL> if frz == None : <EOL> self . deps = FlavorsStream ( '<STR_LIT>' ) <EOL> elif frz == '<STR_LIT>' : <EOL> self . deps = None <EOL> else : <EOL> self . deps = FlavorsStream ( frz ) <EOL> class StringsStream ( list , InfoStream ) : <EOL> """<STR_LIT>""" <EOL> def set ( self , val ) : <EOL> assert ( type ( val ) is str ) <EOL> if val not in self : <EOL> self . append ( val ) <EOL> self . sort ( ) <EOL> def __eq__ ( self , other , skipSet = None ) : <EOL> return list . __eq__ ( self , other ) <EOL> def freeze ( self , skipSet = None ) : <EOL> if not self : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' . join ( self ) <EOL> def diff ( self , them ) : <EOL> if self != them : <EOL> return self . freeze ( ) <EOL> return None <EOL> def thaw ( self , frz ) : <EOL> del self [ : ] <EOL> if len ( frz ) != <NUM_LIT:0> : <EOL> for s in frz . split ( '<STR_LIT>' ) : <EOL> self . set ( s ) <EOL> def twm ( self , diff , base ) : <EOL> self . thaw ( diff ) <EOL> return False <EOL> def __call__ ( self ) : <EOL> return self <EOL> def __init__ ( self , frz = '<STR_LIT>' ) : <EOL> self . thaw ( frz ) <EOL> class OrderedStringsStream ( StringsStream ) : <EOL> def set ( self , val ) : <EOL> assert ( type ( val ) is str ) <EOL> self . append ( val ) <EOL> class OrderedBinaryStringsStream ( StringsStream ) : <EOL> def freeze ( self , skipSet = None ) : <EOL> if not self : <EOL> return '<STR_LIT>' <EOL> l = [ ] <EOL> for s in self : <EOL> l . append ( pack . dynamicSize ( len ( s ) ) ) <EOL> l . append ( s ) <EOL> return '<STR_LIT>' . join ( l ) <EOL> def thaw ( self , frz ) : <EOL> del self [ : ] <EOL> if not frz : <EOL> return <EOL> i = <NUM_LIT:0> <EOL> while i < len ( frz ) : <EOL> i , ( s , ) = pack . unpack ( "<STR_LIT>" , i , frz ) <EOL> self . append ( s ) <EOL> class ReferencedTroveList ( list , InfoStream ) : <EOL> def freeze ( self , skipSet = None ) : <EOL> l = [ ] <EOL> for ( name , version , flavor ) in self : <EOL> version = version . freeze ( ) <EOL> if flavor is not None : <EOL> flavor = flavor . freeze ( ) <EOL> else : <EOL> flavor = "<STR_LIT>" <EOL> l . append ( name ) <EOL> l . append ( version ) <EOL> l . append ( flavor ) <EOL> return "<STR_LIT>" . join ( l ) <EOL> def thaw ( self , data ) : <EOL> del self [ : ] <EOL> if not data : return <EOL> l = data . split ( "<STR_LIT>" ) <EOL> i = <NUM_LIT:0> <EOL> while i < len ( l ) : <EOL> name = l [ i ] <EOL> version = versions . ThawVersion ( l [ i + <NUM_LIT:1> ] ) <EOL> flavor = l [ i + <NUM_LIT:2> ] <EOL> flavor = deps . ThawFlavor ( flavor ) <EOL> self . append ( ( name , version , flavor ) ) <EOL> i += <NUM_LIT:3> <EOL> def __init__ ( self , data = None ) : <EOL> list . __init__ ( self ) <EOL> if data is not None : <EOL> self . thaw ( data ) <EOL> class StreamCollection ( InfoStream ) : <EOL> """<STR_LIT>""" <EOL> ignoreSkipSet = False <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def getItems ( self ) : <EOL> if self . _data is not None : <EOL> self . _thaw ( ) <EOL> return self . _thawedItems <EOL> _items = property ( getItems ) <EOL> def __eq__ ( self , other , skipSet = { } ) : <EOL> assert ( self . __class__ == other . __class__ ) <EOL> if self . _data is not None and other . _data is not None : <EOL> return self . _data == other . _data <EOL> return self . _items == other . _items <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def freeze ( self , skipSet = { } ) : <EOL> if self . _data is not None : <EOL> if self . ignoreSkipSet or not skipSet : <EOL> return self . _data <EOL> else : <EOL> self . _thaw ( ) <EOL> l = [ ] <EOL> for typeId , itemDict in sorted ( self . _items . iteritems ( ) ) : <EOL> itemList = sorted ( itemDict ) <EOL> if itemList and not hasattr ( itemList [ <NUM_LIT:0> ] , '<STR_LIT>' ) : <EOL> raise AssertionError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % itemList [ <NUM_LIT:0> ] . __class__ . __name__ ) <EOL> for item in sorted ( itemDict ) : <EOL> s = item . freeze ( ) <EOL> if len ( s ) >= ( <NUM_LIT:1> << <NUM_LIT:16> ) : <EOL> raise OverflowError <EOL> l . append ( pack . pack ( "<STR_LIT>" , typeId , s ) ) <EOL> return "<STR_LIT>" . join ( l ) <EOL> def thaw ( self , data ) : <EOL> data = intern ( data ) <EOL> self . _data = data <EOL> def _thaw ( self ) : <EOL> i = <NUM_LIT:0> <EOL> self . _thawedItems = dict ( [ ( x , { } ) for x in self . streamDict ] ) <EOL> while ( i < len ( self . _data ) ) : <EOL> i , ( typeId , s ) = pack . unpack ( "<STR_LIT>" , i , self . _data ) <EOL> item = self . streamDict [ typeId ] ( s ) <EOL> self . _thawedItems [ typeId ] [ item ] = True <EOL> assert ( i == len ( self . _data ) ) <EOL> self . _data = None <EOL> def addStream ( self , typeId , item ) : <EOL> assert ( item . __class__ == self . streamDict [ typeId ] ) <EOL> self . _items [ typeId ] [ item ] = True <EOL> def delStream ( self , typeId , item ) : <EOL> del self . _items [ typeId ] [ item ] <EOL> def getStreams ( self , typeId ) : <EOL> return self . _items [ typeId ] <EOL> def iterAll ( self ) : <EOL> for typeId , itemDict in self . _items . iteritems ( ) : <EOL> for item in itemDict : <EOL> yield ( typeId , item ) <EOL> def diff ( self , other ) : <EOL> assert ( self . __class__ == other . __class__ ) <EOL> if self . _data is not None and self . _data == other . _data : <EOL> return None <EOL> us = set ( self . iterAll ( ) ) <EOL> them = set ( other . iterAll ( ) ) <EOL> added = us - them <EOL> removed = them - us <EOL> if not added and not removed : <EOL> return None <EOL> l = [ ] <EOL> if len ( removed ) >= ( <NUM_LIT:1> << <NUM_LIT:16> ) : <EOL> raise OverflowError <EOL> if len ( added ) >= ( <NUM_LIT:1> << <NUM_LIT:16> ) : <EOL> raise OverflowError <EOL> l . append ( struct . pack ( "<STR_LIT>" , len ( removed ) , len ( added ) ) ) <EOL> for typeId , item in itertools . chain ( removed , added ) : <EOL> s = item . freeze ( ) <EOL> if len ( s ) >= ( <NUM_LIT:1> << <NUM_LIT:16> ) : <EOL> raise OverflowError <EOL> l . append ( struct . pack ( "<STR_LIT>" , typeId , len ( s ) ) ) <EOL> l . append ( s ) <EOL> return "<STR_LIT>" . join ( l ) <EOL> def twm ( self , diff , base ) : <EOL> assert ( self == base ) <EOL> numRemoved , numAdded = struct . unpack ( "<STR_LIT>" , diff [ <NUM_LIT:0> : <NUM_LIT:4> ] ) <EOL> i = <NUM_LIT:4> <EOL> for x in xrange ( numRemoved + numAdded ) : <EOL> typeId , length = struct . unpack ( "<STR_LIT>" , diff [ i : i + <NUM_LIT:3> ] ) <EOL> i += <NUM_LIT:3> <EOL> item = self . streamDict [ typeId ] ( diff [ i : i + length ] ) <EOL> i += length <EOL> if x < numRemoved : <EOL> del self . _items [ typeId ] [ item ] <EOL> else : <EOL> self . _items [ typeId ] [ item ] = True <EOL> def __init__ ( self , data = None ) : <EOL> if data is not None : <EOL> self . thaw ( data ) <EOL> else : <EOL> self . thaw ( '<STR_LIT>' ) <EOL> class OrderedStreamCollection ( StreamCollection ) : <EOL> __slots__ = ( ) <EOL> def freeze ( self , skipSet = { } ) : <EOL> if self . _data is not None : <EOL> if not skipSet : <EOL> return self . _data <EOL> else : <EOL> self . _thaw ( ) <EOL> l = [ ] <EOL> for typeId , itemList in ( self . _items . iteritems ( ) ) : <EOL> for item in itemList : <EOL> s = item . freeze ( skipSet = skipSet ) <EOL> l . append ( struct . pack ( '<STR_LIT>' , typeId ) ) <EOL> l . append ( pack . dynamicSize ( len ( s ) ) ) <EOL> l . append ( s ) <EOL> return "<STR_LIT>" . join ( l ) <EOL> def _thaw ( self ) : <EOL> i = <NUM_LIT:0> <EOL> self . _thawedItems = dict ( [ ( x , [ ] ) for x in self . streamDict ] ) <EOL> while ( i < len ( self . _data ) ) : <EOL> i , ( typeId , s ) = pack . unpack ( '<STR_LIT>' , i , self . _data ) <EOL> item = self . streamDict [ typeId ] ( s ) <EOL> self . _thawedItems [ typeId ] . append ( item ) <EOL> assert ( i == len ( self . _data ) ) <EOL> self . _data = None <EOL> def addStream ( self , typeId , item ) : <EOL> assert ( item . __class__ == self . streamDict [ typeId ] ) <EOL> self . _items [ typeId ] . append ( item ) <EOL> def delStream ( self , typeId , item ) : <EOL> l = self . _items [ typeId ] <EOL> del l [ l . index ( item ) ] <EOL> def getStreams ( self , typeId ) : <EOL> return self . _items [ typeId ] <EOL> def iterAll ( self ) : <EOL> for typeId , l in self . _items . iteritems ( ) : <EOL> for item in l : <EOL> yield ( typeId , item ) <EOL> def count ( self , typeId ) : <EOL> return len ( self . _items [ typeId ] ) <EOL> def diff ( self , other ) : <EOL> assert ( self . __class__ == other . __class__ ) <EOL> us = set ( self . iterAll ( ) ) <EOL> them = set ( other . iterAll ( ) ) <EOL> added = us - them <EOL> removed = them - us <EOL> if not added and not removed : <EOL> return None <EOL> l = [ ] <EOL> if len ( removed ) >= ( <NUM_LIT:1> << <NUM_LIT:16> ) : <EOL> raise OverflowError <EOL> if len ( added ) >= ( <NUM_LIT:1> << <NUM_LIT:16> ) : <EOL> raise OverflowError <EOL> l . append ( struct . pack ( "<STR_LIT>" , len ( removed ) , len ( added ) ) ) <EOL> for typeId , item in removed : <EOL> s = item . freeze ( ) <EOL> l . append ( struct . pack ( '<STR_LIT>' , typeId ) ) <EOL> l . append ( pack . dynamicSize ( len ( s ) ) ) <EOL> l . append ( s ) <EOL> for typeId , item in self . iterAll ( ) : <EOL> if ( typeId , item ) in added : <EOL> s = item . freeze ( ) <EOL> l . append ( struct . pack ( '<STR_LIT>' , typeId ) ) <EOL> l . append ( pack . dynamicSize ( len ( s ) ) ) <EOL> l . append ( s ) <EOL> return "<STR_LIT>" . join ( l ) <EOL> def twm ( self , diff , base ) : <EOL> assert ( self == base ) <EOL> numRemoved , numAdded = struct . unpack ( "<STR_LIT>" , diff [ <NUM_LIT:0> : <NUM_LIT:4> ] ) <EOL> i = <NUM_LIT:4> <EOL> for x in xrange ( numRemoved + numAdded ) : <EOL> i , ( typeId , s ) = pack . unpack ( "<STR_LIT>" , i , diff ) <EOL> item = self . streamDict [ typeId ] ( s ) <EOL> if x < numRemoved : <EOL> l = self . _items [ typeId ] <EOL> del l [ l . index ( item ) ] <EOL> else : <EOL> self . _items [ typeId ] . append ( item ) <EOL> def __init__ ( self , data = None ) : <EOL> if data is not None : <EOL> self . thaw ( data ) <EOL> else : <EOL> self . _data = None <EOL> self . _thawedItems = dict ( [ ( x , [ ] ) for x in self . streamDict ] ) <EOL> class StringOrderedStreamCollection ( OrderedStreamCollection ) : <EOL> streamDict = { <NUM_LIT:1> : StringStream } <EOL> ignoreSkipSet = True <EOL> def append ( self , item ) : <EOL> s = StringStream ( ) <EOL> s . set ( item ) <EOL> self . addStream ( <NUM_LIT:1> , s ) <EOL> def __iter__ ( self ) : <EOL> return ( x [ <NUM_LIT:1> ] ( ) for x in self . iterAll ( ) ) <EOL> class AbsoluteStreamCollection ( StreamCollection ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( ) <EOL> def diff ( self , other ) : <EOL> assert ( self . __class__ == other . __class__ ) <EOL> return self . freeze ( ) <EOL> def twm ( self , diff , base ) : <EOL> assert ( self == base ) <EOL> self . thaw ( diff ) <EOL> class UnknownStream ( Exception ) : <EOL> pass </s>
