<s> """<STR_LIT>""" <EOL> from datetime import datetime <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> SEP = "<STR_LIT:/>" <EOL> PARENT = "<STR_LIT:..>" <EOL> def get_int ( value , default , test_fn = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> converted = int ( value ) <EOL> except ValueError : <EOL> return default <EOL> test_fn = test_fn if test_fn else lambda x : True <EOL> return converted if test_fn ( converted ) else default <EOL> def check_version ( mod , required ) : <EOL> """<STR_LIT>""" <EOL> vers = tuple ( int ( v ) for v in mod . __version__ . split ( '<STR_LIT:.>' ) [ : <NUM_LIT:3> ] ) <EOL> if vers < required : <EOL> req = '<STR_LIT:.>' . join ( str ( v ) for v in required ) <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" % <EOL> ( mod . __name__ , mod . __version__ , req ) ) <EOL> def requires ( module , name = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> def wrapped ( method ) : <EOL> """<STR_LIT>""" <EOL> if module is None : <EOL> raise ImproperlyConfigured ( "<STR_LIT>" % name ) <EOL> return method <EOL> return wrapped <EOL> def dt_from_rfc8601 ( date_str ) : <EOL> """<STR_LIT>""" <EOL> date_str = date_str . rstrip ( '<STR_LIT>' ) . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> fmt = "<STR_LIT>" <EOL> return datetime . strptime ( date_str , fmt ) <EOL> def dt_from_rfc1123 ( date_str ) : <EOL> """<STR_LIT>""" <EOL> fmt = "<STR_LIT>" <EOL> return datetime . strptime ( date_str , fmt ) <EOL> def dt_from_header ( date_str ) : <EOL> """<STR_LIT>""" <EOL> convert_fns = ( <EOL> dt_from_rfc8601 , <EOL> dt_from_rfc1123 , <EOL> ) <EOL> for convert_fn in convert_fns : <EOL> try : <EOL> return convert_fn ( date_str ) <EOL> except ValueError : <EOL> pass <EOL> return None <EOL> def basename ( path ) : <EOL> """<STR_LIT>""" <EOL> base_path = path . strip ( SEP ) <EOL> sep_ind = base_path . rfind ( SEP ) <EOL> if sep_ind < <NUM_LIT:0> : <EOL> return path <EOL> return base_path [ sep_ind + <NUM_LIT:1> : ] <EOL> def path_parts ( path ) : <EOL> """<STR_LIT>""" <EOL> path = path if path is not None else '<STR_LIT>' <EOL> container_path = object_path = '<STR_LIT>' <EOL> parts = path_list ( path ) <EOL> if len ( parts ) > <NUM_LIT:0> : <EOL> container_path = parts [ <NUM_LIT:0> ] <EOL> if len ( parts ) > <NUM_LIT:1> : <EOL> object_path = path_join ( * parts [ <NUM_LIT:1> : ] ) <EOL> return container_path , object_path <EOL> def path_yield ( path ) : <EOL> """<STR_LIT>""" <EOL> for part in ( x for x in path . strip ( SEP ) . split ( SEP ) if x not in ( None , '<STR_LIT>' ) ) : <EOL> yield part <EOL> def path_list ( path ) : <EOL> """<STR_LIT>""" <EOL> return list ( path_yield ( path ) ) <EOL> def path_join ( * args ) : <EOL> """<STR_LIT>""" <EOL> return SEP . join ( ( x for x in args if x not in ( None , '<STR_LIT>' ) ) ) . strip ( SEP ) <EOL> def relpath ( path , start ) : <EOL> """<STR_LIT>""" <EOL> path_items = path_list ( path ) <EOL> start_items = path_list ( start ) <EOL> common = [ ] <EOL> for pth , stt in zip ( path_items , start_items ) : <EOL> if pth != stt : <EOL> break <EOL> common . append ( pth ) <EOL> common_ind = len ( common ) <EOL> parent_num = len ( start_items ) - common_ind <EOL> rel_items = [ PARENT ] * parent_num + path_items [ common_ind : ] <EOL> return path_join ( * rel_items ) </s>
