<s> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> from swiftly . cli . command import CLICommand , ReturnCode <EOL> def cli_post ( context , path , body = None ) : <EOL> """<STR_LIT>""" <EOL> path = path . lstrip ( '<STR_LIT:/>' ) if path else '<STR_LIT>' <EOL> status , reason , headers , contents = <NUM_LIT:0> , '<STR_LIT>' , { } , '<STR_LIT>' <EOL> with context . client_manager . with_client ( ) as client : <EOL> if not path : <EOL> status , reason , headers , contents = client . post_account ( <EOL> headers = context . headers , query = context . query , cdn = context . cdn , <EOL> body = body ) <EOL> if status // <NUM_LIT:100> != <NUM_LIT:2> : <EOL> raise ReturnCode ( '<STR_LIT>' % ( status , reason ) ) <EOL> elif '<STR_LIT:/>' not in path . rstrip ( '<STR_LIT:/>' ) : <EOL> path = path . rstrip ( '<STR_LIT:/>' ) <EOL> status , reason , headers , contents = client . post_container ( <EOL> path , headers = context . headers , query = context . query , <EOL> cdn = context . cdn , body = body ) <EOL> if status // <NUM_LIT:100> != <NUM_LIT:2> : <EOL> raise ReturnCode ( <EOL> '<STR_LIT>' % ( path , status , reason ) ) <EOL> else : <EOL> status , reason , headers , contents = client . post_object ( <EOL> * path . split ( '<STR_LIT:/>' , <NUM_LIT:1> ) , headers = context . headers , <EOL> query = context . query , cdn = context . cdn , body = body ) <EOL> if status // <NUM_LIT:100> != <NUM_LIT:2> : <EOL> raise ReturnCode ( <EOL> '<STR_LIT>' % ( path , status , reason ) ) <EOL> class CLIPost ( CLICommand ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cli ) : <EOL> super ( CLIPost , self ) . __init__ ( <EOL> cli , '<STR_LIT>' , max_args = <NUM_LIT:1> , usage = """<STR_LIT>""" . strip ( ) ) <EOL> self . option_parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . option_parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . option_parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def __call__ ( self , args ) : <EOL> options , args , context = self . parse_args_and_create_context ( args ) <EOL> context . headers = self . options_list_to_lowered_dict ( options . header ) <EOL> context . query = self . options_list_to_lowered_dict ( options . query ) <EOL> path = args . pop ( <NUM_LIT:0> ) . lstrip ( '<STR_LIT:/>' ) if args else None <EOL> body = None <EOL> if options . input_ : <EOL> if options . input_ == '<STR_LIT:->' : <EOL> body = self . cli . context . io_manager . get_stdin ( ) <EOL> else : <EOL> body = open ( options . input_ , '<STR_LIT:rb>' ) <EOL> return cli_post ( context , path , body = body ) </s>
