#NEWLINE# def _merge_prefix( deque , size ) : #NEWLINE# #INDENT# "Replace the first entries in a deque of strings with a single\n    string of up to size bytes.\n\n    >>> d = collections.deque(['abc', 'de', 'fghi', 'j'])\n    >>> _merge_prefix(d, 5); print(d)\n    deque(['abcde', 'fghi', 'j'])\n\n    Strings will be split as necessary to reach the desired size.\n    >>> _merge_prefix(d, 7); print(d)\n    deque(['abcdefg', 'hi', 'j'])\n\n    >>> _merge_prefix(d, 3); print(d)\n    deque(['abc', 'defg', 'hi', 'j'])\n\n    >>> _merge_prefix(d, 100); print(d)\n    deque(['abcdefghij'])\n    " #NEWLINE# if ( ( len ( deque ) == 1 ) and ( len ( deque [ 0 ] ) <= size ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# prefix = [ ] #NEWLINE# remaining = size #NEWLINE# while ( deque and ( remaining > 0 ) ) : #NEWLINE# #INDENT# chunk = deque . popleft ( ) #NEWLINE# if ( len ( chunk ) > remaining ) : #NEWLINE# #INDENT# deque . appendleft ( chunk [ remaining : ] ) #NEWLINE# chunk = chunk [ : remaining ] #NEWLINE# #UNINDENT# prefix . append ( chunk ) #NEWLINE# remaining -= len ( chunk ) #NEWLINE# #UNINDENT# if prefix : #NEWLINE# #INDENT# deque . appendleft ( type ( prefix [ 0 ] ) ( ) . join ( prefix ) ) #NEWLINE# #UNINDENT# if ( not deque ) : #NEWLINE# #INDENT# deque . appendleft ( b'' )