<s> import sys <EOL> import uuid <EOL> import ctypes <EOL> def diff ( new , old ) : <EOL> """<STR_LIT>""" <EOL> if old is not None : <EOL> is_update = True <EOL> removed = set ( new . removed ( old ) ) <EOL> updated = set ( new . updated ( old ) ) <EOL> else : <EOL> is_update = False <EOL> updated = new <EOL> removed = set ( ) <EOL> return updated , removed , is_update <EOL> def generate_persistent_id ( ) : <EOL> """<STR_LIT>""" <EOL> return ctypes . c_long ( uuid . uuid1 ( ) . int >> <NUM_LIT:64> ) . value <EOL> def parse_byte_range ( byte_range , min_byte = <NUM_LIT:0> , max_byte = sys . maxint ) : <EOL> """<STR_LIT>""" <EOL> if not byte_range : <EOL> return min_byte , max_byte <EOL> begin = byte_range [ <NUM_LIT:0> ] or min_byte <EOL> end = byte_range [ <NUM_LIT:1> ] or max_byte <EOL> if end < begin : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if begin < min_byte : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if end > max_byte : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return begin , end <EOL> def to_tree ( instance , * children ) : <EOL> """<STR_LIT>""" <EOL> yield unicode ( instance ) <EOL> for i , child in enumerate ( children ) : <EOL> lines = <NUM_LIT:0> <EOL> yield "<STR_LIT:|>" <EOL> yield "<STR_LIT>" + unicode ( child ) <EOL> if i != len ( children ) - <NUM_LIT:1> : <EOL> a = "<STR_LIT:|>" <EOL> else : <EOL> a = "<STR_LIT:U+0020>" <EOL> for j , item in enumerate ( child . itervalues ( ) ) : <EOL> if j != len ( child ) - <NUM_LIT:1> : <EOL> b = "<STR_LIT:|>" <EOL> else : <EOL> b = "<STR_LIT:U+0020>" <EOL> if j == <NUM_LIT:0> : <EOL> yield a + "<STR_LIT>" <EOL> for k , line in enumerate ( item . to_tree ( ) ) : <EOL> lines += <NUM_LIT:1> <EOL> if k == <NUM_LIT:0> : <EOL> yield a + "<STR_LIT>" + line <EOL> else : <EOL> yield a + "<STR_LIT:U+0020>" + b + "<STR_LIT:U+0020>" + line <EOL> if len ( children ) > <NUM_LIT:1> and i == len ( children ) - <NUM_LIT:1> and lines > <NUM_LIT:1> : <EOL> yield a <EOL> def invoke_hooks ( hooks , name , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> callbacks = hooks . get ( name , [ ] ) <EOL> for callback in callbacks : <EOL> callback ( * args , ** kwargs ) </s>
