Changeset 3276

Show
Ignore:
Timestamp:
12/14/09 15:07:56 (10 years ago)
Author:
jsamuel
Message:

Committing httpretrieve files provided by Yafete as he sorts out svn access.

Location:
seattle/trunk/seattlelib
Files:
5 added
6 modified

Legend:

Unmodified
Added
Removed
  • seattle/trunk/seattlelib/http_hierarchy_error.repy

    r3056 r3276  
    1616 
    1717''' 
    18 http hierarchy error exception classes formation 
     18http hierarchy error exception classes 
    1919 
    2020-> HttpError 
  • seattle/trunk/seattlelib/httpretrieve.repy

    r3253 r3276  
    2222include sockettimeout.repy 
    2323include http_hierarchy_error.repy 
    24  
    25  
    26  
    27  
    28  
    29 def httpretrieve_open(url, http_post=None, header_timeout=30, content_timeout=30, httpheader_limit=8192): 
     24include urllib.repy 
     25 
     26 
     27 
     28 
     29 
     30def httpretrieve_open(url, http_query=None, http_post=None, http_header=None, header_timeout=30, content_timeout=30, httpheader_limit=8192, httpcontent_limit=4194304): 
    3031  """ 
    3132  <Purpose> 
     
    3738           String of a http web server-URL 
    3839    http_post: 
    39            string of data to post to server 
     40           dictionary of data to post to server(unencoded string, the library encodes the post it self) 
     41    http_query: 
     42           dictionary of query to send to server(unencoded string, the library encodes the query it self) 
     43    http_header: 
     44           dictionary of http header to add the the http header request 
    4045    header_timeout: 
    4146           socket timeout for receiving header from server(default value set to 30 seconds) 
     
    4449    httpheader_limit: 
    4550           length limit for when a server sends http header(default value set to 8kb(8192 charactors))  
    46      
     51    httpcontent_limit: 
     52            limits the the amount of content a server can send to the retrieval  
    4753  
    4854  <Exceptions> 
     
    9399    Returns file like obj which can read the http content from http web server.  
    94100  """ 
    95  
     101   
    96102  # check if url is valid and get host, path, port and query from the given url 
    97   (host, port, path, query) = _httpretrieve_parse_given_url(url) 
     103  (host, port, path, url_query) = _httpretrieve_parse_given_url(url) 
    98104 
    99105  # get connection to the http web server 
     
    103109  except Exception, e: 
    104110    raise HttpConnectionError('Error: opening a connection failed with given http server, Given: ' + str(url) + ' ' + str(e)) 
    105  
     111     
    106112  # build a http format request using the given port, host, path and query 
    107   httpheader = _httpretrieve_buildhttprequest(port, host, path, query, http_post) 
    108  
     113  httpheader = _httpretrieve_buildhttprequest(http_header, port, host, path, url_query, http_query, http_post) 
     114   
    109115  # send http format request to http web server   
    110   _httpretrieve_sendhttprequest(sock, httpheader, http_post)  
    111  
     116  _httpretrieve_sendhttprequest(sock, httpheader)  
     117   
    112118  # receive the http header lines in a form of list from the http web server 
    113119  httpheaderlines = _httpretrieve_receive_httpheader(sock, header_timeout, httpheader_limit) 
     
    120126    contentlength = _httpretrieve_get_contentlength(httpheaderlines) 
    121127    # return a filelikeobj to read the http content from the http server  
    122     return _httpretrieve_filelikeobject(sock, contentlength, content_timeout)  
     128    return _httpretrieve_filelikeobject(sock, contentlength, httpcontent_limit, content_timeout)  
    123129   
    124130  elif http_status_number == '301' or http_status_number == '302': # redirect 
     
    143149 
    144150 
    145  
    146 def httpretrieve_save_file(url, filename, http_post=None, header_timeout=30, content_timeout=30, httpheader_limit=8192): 
     151def httpretrieve_save_file(url, filename, http_query=None, http_post=None, http_header=None, header_timeout=30, content_timeout=30, httpheader_limit=8192, httpcontent_limit=4194304): 
    147152  """ 
    148153  <Purpose> 
     
    152157    url: 
    153158           String of a http web server URL 
    154  
    155159    filename: 
    156160           The file name for the http content to be saved in 
     161    http_post: 
     162           dictionary of data to post to server(unencoded string, the library encodes the post it self) 
     163    http_query: 
     164           dictionary of query to send to server(unencoded string, the library encodes the query it self) 
     165    http_header: 
     166           dictionary of http header to add the the http header request 
     167    header_timeout: 
     168           socket timeout for receiving header from server(default value set to 30 seconds) 
     169    content_timeout: 
     170           socket timeout for receiving content from server(default value set to 30 seconds) 
     171    httpheader_limit: 
     172           length limit for when a server sends http header(default value set to 8kb(8192 charactors))  
     173    httpcontent_limit: 
     174            limits the the amount of content a server can send to the retrieval  
    157175            
    158176  <Exceptions> 
     
    175193    raise HttpRetrieveClientError('Error on creating a file to saving http content' + str(e)) 
    176194 
    177   http_obj = httpretrieve_open(url, http_post, header_timeout, content_timeout, httpheader_limit) 
     195  http_obj = httpretrieve_open(url, http_query, http_post, http_header, header_timeout, content_timeout, httpheader_limit, httpcontent_limit) 
    178196 
    179197  # keep on reading 1024 and writing it into a file, until it receives an empty string 
     
    190208 
    191209   
    192 def httpretrieve_get_string(url, http_post=None, header_timeout=30, content_timeout=30, httpheader_limit=8192): 
     210def httpretrieve_get_string(url, http_query=None, http_post=None, http_header=None, header_timeout=30, content_timeout=30, httpheader_limit=8192, httpcontent_limit=4194304): 
    193211  """ 
    194212  <Purpose> 
     
    196214 
    197215  <Arguments> 
    198      url: 
    199            string of a http web server URL 
     216    url: 
     217           String of a http web server-URL 
     218    http_post: 
     219           dictionary of data to post to server(unencoded string, the library encodes the post it self) 
     220    http_query: 
     221           dictionary of query to send to server(unencoded string, the library encodes the query it self) 
     222    http_header: 
     223           dictionary of http header to add the the http header request 
     224    header_timeout: 
     225           socket timeout for receiving header from server(default value set to 30 seconds) 
     226    content_timeout: 
     227           socket timeout for receiving content from server(default value set to 30 seconds) 
     228    httpheader_limit: 
     229           length limit for when a server sends http header(default value set to 8kb(8192 charactors))  
     230    httpcontent_limit: 
     231            limits the the amount of content a server can send to the retrieval  
    200232  
    201233  <Exceptions> 
     
    209241  """        
    210242   
    211   http_obj = httpretrieve_open(url, http_post, header_timeout, content_timeout, httpheader_limit) 
     243  http_obj = httpretrieve_open(url, http_query, http_post, http_header, header_timeout, content_timeout, httpheader_limit, httpcontent_limit) 
    212244  # retrieve the http content from server using httpretrieve file like object 
    213245  httpcontent = http_obj.read() 
     
    220252class _httpretrieve_filelikeobject: 
    221253  # file like object used to receive the http content with a length limit    
    222   def __init__(self, sock, contentlength, content_timeout): 
     254  def __init__(self, sock, contentlength, httpcontent_limit, content_timeout): 
    223255    self.sock = sock 
    224256    if contentlength == None: 
     
    227259      self.contentlengthisknown = True 
    228260      self.contentlength = contentlength 
     261    self.httpcontent_limit = httpcontent_limit   
    229262    self.content_timeout = content_timeout   
    230263    self.fileobjclosed = False 
     
    285318    else:  
    286319    # check if limit is a valid number 
    287       try: # none int check 
    288         int(limit) 
    289       except ValueError, e: 
     320      if not type(limit) == int: 
    290321        raise HttpUserInputError('User input Error: given a none int to receive' + str(e))   
    291       else: 
     322      elif limit < 0: 
    292323        # raise an exception if limit is a negative number 
    293         if limit < 0:  
    294           raise HttpUserInputError('User input Error: given a negative number to receive, given: ' + str(limit)) 
     324        raise HttpUserInputError('User input Error: given a negative number to receive, given: ' + str(limit)) 
    295325      readhaslimit = True 
    296326      left_to_read = limit   
     
    322352      else: 
    323353        # By default, httpretrieve permits content length to be less than 4,096 kilobytes(4194304 charactors) 
    324         if len(content) >= 4194304: 
    325           raise HttpContentLengthError('content length exceeded 4096 kb') 
     354        if len(content) >= self.httpcontent_limit: 
     355          raise HttpContentLengthError('content length exceeded ' + self.httpcontent_limit) 
    326356 
    327357        # add what is received 
     
    415445 
    416446 
    417 def _httpretrieve_buildhttprequest(port, host, path, query, http_post): 
     447def _httpretrieve_buildhttprequest(http_header, port, host, path, url_query, dict_query, http_post): 
    418448  # send http request to the http web server using socket connection   
    419449   
    420450  if http_post != None: 
    421     # check if the given post is valid 
    422     if not type(http_post) == str: 
    423       raise HttpUserInputError('The given http_post is not a string, given: ' + str(type(http_post))) 
    424     # there is a posted data use http POST method 
    425     http_command = 'POST' 
     451    # there is a posted data, thus use http POST command 
     452    
     453    # check if the given post data is valid 
     454    if not type(http_post) == dict: 
     455      raise HttpUserInputError('The given http_post is not a dictionary, given: ' + str(type(http_post))) 
     456 
     457    # change the given http post dictionary into a encoded post data with a key and val   
     458    try:  
     459      http_post = urllib_quote_parameters(http_post) 
     460    except Exception, e: 
     461      raise HttpUserInputError('Error encoding the given http post dictionary ' +  str(http_post) + str(e)) 
     462 
     463 
     464    # build the main http request header which includes the GET/POST and the Host name field 
     465    httpheader = _httpretrieve_httprequestmain_header('POST', url_query, dict_query, path, host, port) 
     466 
     467    # if given add a client http header to the request 
     468    httpheader += _httpretrieve_parse_clienthttpheader(http_header) 
     469 
     470    # indicate the http post content length 
     471    httpheader += 'Content-Length: ' + str(len(http_post)) + '\r\n'   
     472    # add a new line to indicate that the http header is done and the http post is followed. 
     473    httpheader += '\r\n' 
     474    # include the posted data after the http header empty line 
     475    httpheader += http_post 
     476         
    426477 
    427478  else: 
    428     # there was no posted data use http GET method    
    429     http_command = 'GET' 
    430  
    431   # if there is no query, dont need to include it in the request 
    432   addquery = '' 
    433   if query != '': 
     479    # there is no posted data, use http GET method    
     480    httpheader = _httpretrieve_httprequestmain_header('GET', url_query, dict_query, path, host, port) 
     481    # if http header is given, add client headers to the request  
     482    httpheader += _httpretrieve_parse_clienthttpheader(http_header) 
     483    # add a new line to indicate that the header request is complete 
     484    httpheader += '\r\n' 
     485 
     486  # return header with a new line which is signal for http header is done  
     487  return httpheader  
     488 
     489 
     490 
     491 
     492def _httpretrieve_httprequestmain_header(http_command, url_query, dict_query, path, host, port): 
     493  # builds the first two main http request headers which include the GET/POST and the HOST name 
     494   
     495  # before building the httprequest make sure there isnt two fields of query given by the client 
     496  if url_query != '' and dict_query != None: 
     497    # cant have two different fields with query 
     498    raise HttpUserInputError('Cant input a http query with the url and an extra parameter dictionary with a http query') 
     499 
     500  elif dict_query != None: 
     501    # user has given a http query  
     502    try:  
     503      encoded_query = '?' + urllib_quote_parameters(dict_query) 
     504    except Exception, e: 
     505      raise HttpUserInputError('Error encoding the given http query dictionary ' +  str(dict_query) + str(e)) 
     506 
     507  elif url_query != '': 
    434508    # if there is a query include the query on the main header('?' is used as a seperater between path) 
    435     addquery = '?' + query 
    436  
    437   # if there is no path add a / on the request and if there is a path use the given path 
     509    encoded_query = '?' + url_query 
     510  else: 
     511    # there is no query 
     512    encoded_query = '' 
     513     
     514 
     515  # if there is no path add a '/' on the request and if there is a path use the given path 
    438516  addpath = '/' 
    439517  if path != '': 
    440518    addpath = path 
    441      
    442   httpheader = http_command + ' ' + addpath + addquery + ' HTTP/1.0\r\n' 
     519 
     520  # FIRST header which includes the POST/GET request   
     521  main_httpheader = http_command + ' ' + addpath + encoded_query + ' HTTP/1.0\r\n' 
     522 
    443523 
    444524  # if port is 80, dont need to include the port upon request 
     
    448528    # (':' is used as a separater between host and port) 
    449529    addport = ':' + str(port) 
    450      
    451   httpheader += 'Host: ' + host + addport + '\r\n' 
    452  
    453   # server name  
    454   httpheader += 'Server: Seattle Testbed\r\n' 
    455   # closes the servers socket connection after sending all response                     
    456   httpheader += 'Connection: close\r\n' 
    457  
    458   # if there is a posted data include the content length in httpheader 
    459   if http_command == 'POST': 
    460     httpheader += 'Content-Length: ' + str(len(http_post)) + '\r\n'   
    461  
    462   # return header with a new line which is signal for http header is done  
    463   return httpheader + '\r\n'   
    464  
    465    
    466  
    467  
    468 def _httpretrieve_sendhttprequest(sock, httpheader, http_post): 
     530 
     531  # SECOND line of the header request which include the host name with port if the port is not 80    
     532  main_httpheader += 'Host: ' + host + addport + '\r\n' 
     533 
     534  # return the firs two lines of the http request  
     535  return main_httpheader 
     536 
     537 
     538 
     539 
     540def _httpretrieve_parse_clienthttpheader(http_header): 
     541  # builds a http header from the given http header dictionary 
     542  if http_header == None: 
     543    # if the http header isnt given return a empty string 
     544    return '' 
     545  elif not type(http_header) == dict: 
     546    # raise an exception if the http header isnt dictionary 
     547    raise HttpUserInputError('The given http_post is not a dictionary, given: ' + str(type(http_header))) 
     548  else:  
     549    # take the given key and val from the http_header dictionary and add them to the http header with 
     550    # correct http format 
     551    clienthttpheader = '' 
     552    for key, val in http_header.items(): 
     553      # make simple checks on the key and val  
     554      if not type(key) == str: 
     555        raise HttpUserInputError('The given http header key isnt str given ' + str(type(key))) 
     556      if not type(val) == str: 
     557        raise HttpUserInputError('The given http header value isnt str given ' + str( type(val))) 
     558      if key == '' or val == '': 
     559        # raise an exception if the key or value is a empty field 
     560        raise HttpUserInputError('The given empty http header feild of key or value') 
     561      if key.capitalize() != key: 
     562        raise HttpUserInputError('The given http header key is not capitalized, given: ' + key) 
     563 
     564      # add the key and value to the http header field 
     565      clienthttpheader += key + ' : ' + val + '\r\n'   
     566 
     567    # return the string of the http header   
     568    return clienthttpheader 
     569 
     570 
     571 
     572 
     573def _httpretrieve_sendhttprequest(sock, httpheader): 
    469574  # send the request, and if there is any error raise an excetion 
    470575  try: 
    471576    sock.send(httpheader) 
    472     # if there is a posted data send the posted data right after the http header 
    473     if httpheader.startswith('POST'): 
    474       sock.send(http_post) 
    475       # used to end the post 
    476       sock.send('\r\n\r\n') 
    477577  except Exception, e: 
    478     sock.close() 
     578    if 'Socket closed' not in str(e):  
     579      sock.close() 
    479580    raise HttpConnectionError('Connection error: on sending http request to server ' + str(e)) 
    480581 
     
    633734  # eg.'Location: http://www.google.com' 
    634735  for headerline in httpheaderlines: 
    635     if headerline.startswith('Location'): 
     736    if headerline.startswith('Location:'): 
    636737      # if found redirect need to strip out 'Location: ' to return the url    
    637738      redirect = headerline[len('Location: '):] 
     
    654755  # eg.'Content-Length: 34' 
    655756  for headerline in httpheaderlines: 
    656     if headerline.startswith('Content-Length'): 
     757    if headerline.startswith('Content-Length:'): 
    657758      # if found content length need to strip out 'Content-Length: ' to return the length    
     759       
    658760      try:  
    659761        contentlength = int(headerline[len('Content-Length: '):]) 
     
    661763        raise HttpHeaderFormatError('Http header Content-Length format error: http server provided content length that isnt a int ' + str(e))                 
    662764 
     765       
     766      # check if the content length is valid and retrun it  
     767      if contentlength <= 0:                 
     768        raise HttpHeaderFormatError('Http header Content-Length format error: provided content length with invalid number ' + str(contentlength)) 
    663769      else: 
    664        # check if the content length is valid and retrun it  
    665         if len(str(contentlength)) == 0:  
    666           raise HttpHeaderFormatError('Http header Content-Length format error: provided content length with nothing') 
    667         elif contentlength < 0:                 
    668           return HttpHeaderFormatError('Http header Content-Length format error: provided content length with negative number ' + str(contentlength)) 
    669         else: 
    670           return contentlength 
     770        return contentlength 
    671771                         
    672772  # there wasn't a content-length line or the content length was given but didnt give a int  
    673773  return None 
     774 
     775 
  • seattle/trunk/seattlelib/registerhttpcallback.repy

    r3253 r3276  
    105105      # returns None if there isnt a posted data 
    106106      _registerhttpcallback_receive_httpposted_data(sock, httprequest_dictionary, httppost_limit) 
    107        
    108107       
    109108      # place the call back callbackfunc with dictionary that includes http_command, 
     
    209208def _registerhttpcallback_receive_client_request(sock, httprequest_limit): 
    210209  # receive request from the client using the socket connection 
    211   try: 
     210  if not type(httprequest_limit) == int: 
    212211    # check if the given httprequest limit is valid 
    213     int(httprequest_limit) 
    214   except Exception, e: 
    215212    raise HttpServerError('The given http request limit isnt int ' + str(e)) 
    216213   
    217   try:  
    218     # empty line is used as a signal for when the http request is done, and we set a 
    219     # default request length limit to be 131072 character(128kb) 
    220     client_request = _registerhttpcallback_receive_untilemptyline(sock, httprequest_limit) 
     214   
     215  # empty line is used as a signal for when the http request is done, and we set a 
     216  # default request length limit to be 131072 character(128kb) 
     217  client_request = _registerhttpcallback_receive_untilemptyline(sock, httprequest_limit) 
    221218         
    222   except Exception, e: 
    223     # raise depending up on what errors there was while receiving until empty line  
    224     if 'Timeout Error' in str(e): 
    225       raise HttpError408('The server timed out while waiting to receive the request') 
    226     elif 'Length Exceeded' in str(e): 
    227       raise HttpError413('The http request length is too long') 
    228     elif 'Receiveing' in str(e): 
    229       raise HttpError500('Error while receiving http request') 
    230     else: 
    231       raise HttpError500('Error on receiving the request ' + str(e)) 
    232   
     219   
    233220  # http request format requires the request to be line by line 
    234221  # build a list of the received request split line by line to check the formating of the request 
     
    251238 
    252239 
     240 
    253241def _registerhttpcallback_make_httprequsest_dictionary(client_request_lines): 
    254242  # builds up a dictionary from the received request or raises an exception if the 
     
    323311 
    324312  # check the http comand is valid or if its even suported(suported comands include GET and POST) 
    325   if http_command_url_version[0] == 'GET' or http_command_url_version[0] == 'POST': 
     313  if http_command_url_version[0] == 'GET' or http_command_url_version[0].lower() == 'post': 
    326314     http_command = http_command_url_version[0] 
    327315  else: 
     
    376364  # indicating the end of the posted data(this is if the http comand is only a POST) 
    377365 
    378   try: 
     366  if not type(httppoost_limit) == int: 
    379367    # check if the given http post limit is valid 
    380     int(httppoost_limit) 
    381   except Exception, e: 
    382     raise HttpServerError('The given http post limit isnt int ' + str(e)) 
    383    
     368    raise HttpServerError('The given http post limit is not a int, given: ' + str(type(httppoost_limit))) 
     369 
    384370  # if the http comand method isnt post theres is no posted data 
    385371  posted_data = None 
    386    
    387   if httprequest_dictionary['http_command'] == 'POST': 
     372 
     373  # Bug pointed out by Albert Rafetseder: not all browsers send post with caps  
     374  if httprequest_dictionary['http_command'].lower() == 'post': 
     375    # get the posted data length or raise an exception if not given  
    388376    try: 
    389       # empty line is used as a signal for when the http post is done, and we set a 
    390       # default post data length limit to be 2048 character(2mb) 
    391       posted_data = _registerhttpcallback_receive_untilemptyline(sock, httppoost_limit) 
    392  
    393     except Exception, e: 
    394       # raise depending up on what errors there was while receiving until empty line  
    395       if 'Timeout Error' in str(e): 
    396         raise HttpError408('The server timed out while waiting to receive the post data') 
    397       elif 'Length Exceeded' in str(e): 
    398         raise HttpError413('The http posted data length is too long') 
    399       elif 'Receiveing' in str(e): 
    400         raise HttpError500('Error while receiving request posted data') 
    401       else: 
    402         raise HttpError500('Error on receiving the posted data ' + str(e)) 
     377      posted_data_length = int(httprequest_dictionary['Content-Length']) 
     378    except Exception, e:    
     379      raise HttpError411('content length is required on a http POST comand') 
     380    else: 
     381      # Bug pointed out by Albert Rafetseder: post doesnt send a empty line after the posted data 
     382      # recieve the posted data using the posted data length 
     383      posted_data = _registerhttpcallback_receive_httppost(sock, posted_data_length, httppoost_limit) 
    403384 
    404385    # check if there is a posted data and return it 
    405386    if len(posted_data) == 0: 
    406387      raise HttpError417('The request included a http POST comand with no data posted') 
    407  
    408     # get the posted data length or raise an exception if not given   
    409     try: 
    410       posted_data_length = httprequest_dictionary['Content-Length'] 
    411     except Exception, e:    
    412       raise HttpError411('content length is required on a http POST comand') 
    413  
    414     # raise an exception if the the posted data legnth doesnt equal to what is received 
    415     if len(posted_data) != int(posted_data_length): 
    416       raise HttpError417('The content length didnt match the posted data length: the content length was ' + posted_data_length + ' while the posted data is ' + str(len(posted_data)))   
    417388     
    418389  # adds the posted data or None to the httprequest dictionary  
    419390  httprequest_dictionary['posted_data'] = posted_data 
     391 
     392 
     393 
     394 
     395 
     396def _registerhttpcallback_receive_httppost(sock, http_post_length, length_limit): 
     397  # receives posted data from the given connection untill the given content length field matchs the received amount  
     398  total_recvd_post = '' 
     399   
     400  while True: 
     401    if len(total_recvd_post) == http_post_length: 
     402      # if the content length matchs the received posted data return it  
     403      return total_recvd_post 
     404 
     405    # raise an exception if the received posted data length is greater than the given http header content length    
     406    if len(total_recvd_post) > http_post_length: 
     407      raise HttpError417('The http posted data didnt match the http content length header, given content length: ' + str(http_post_length) + ' while posted data length is ' + str(len(total_recvd_post))) 
     408 
     409    # raise an exception if the total received length has exceeded the given length limit 
     410    if len(total_recvd_post) > length_limit:                   
     411      raise HttpError413('The http posted data length exceeded length limit of ' + str(length_limit)) 
     412 
     413                        
     414    try: 
     415      # receive one character at a time inorder to check for the empty line 
     416      content = sock.recv(512) 
     417 
     418    # catch any error that happens while receiving content              
     419    except SocketTimeoutError, e: 
     420      raise HttpError408('The server timed out while waiting to receive the post data ' + str(e)) 
     421    except Exception, e:  
     422      raise HttpError500('Error while receiving request posted data ' + str(e)) 
     423 
     424    else: 
     425      # if there was not receiving error, keep on adding the receieved content  
     426      total_recvd_post += content 
     427 
    420428 
    421429 
     
    435443    # raise an exception if the total received length has exceeded the given length limit 
    436444    if len(total_recvd_content) > length_limit:                   
    437       raise Exception('Length Exceeded') 
     445      raise HttpError413('The http request length exceeded the given length limit ' + str(length_limit)) 
    438446                         
    439447    try: 
     
    443451    # catch any error that happens while receiving content              
    444452    except SocketTimeoutError, e: 
    445       raise Exception('Timeout Error' + str(e)) 
     453      raise HttpError408('The server timed out while waiting to receive the request ' + str(e)) 
    446454    except Exception, e:  
    447       raise Exception('Receiving ' + str(e)) 
     455      raise HttpError500('Error while receiving http request ' + str(e)) 
    448456 
    449457    else: 
     
    451459      total_recvd_content += content 
    452460 
    453   return total_recvd_content 
    454461 
    455462 
     
    508515  if statuscode_numb == 301 or statuscode_numb == 302: 
    509516    if client_error_msg == '': 
    510       raise HttpUserInputError('Internal server error on generating error msg: callback func client should put the location on raising redirect') 
     517      raise HttpUserInputError('Internal server error: callback func client should put the location on raising redirect') 
    511518    elif not client_error_msg.startswith('http://'): 
    512       raise HttpUserInputError('Internal server error on generating error msg: calback func client redirect is invalid, Given:' + client_error_msg) 
     519      raise HttpUserInputError('Internal server error: calback func client redirect is invalid, Given: ' + client_error_msg) 
    513520    else: 
    514521      httpheader += 'Location: ' + str(client_error_msg) + '\n' 
  • seattle/trunk/seattlelib/tests/httpretrieve_test/ut_httpretrieve_content_timeout.py

    r3253 r3276  
    5050  try: 
    5151    # start up http retrieve to retieve the content from http server 
    52     recv_msg = httpretrieve_get_string('http://127.0.0.1:12345/', ' ', 5, 5) 
     52    recv_msg = httpretrieve_get_string('http://127.0.0.1:12345/', http_query=None, http_post=None, http_header=None, header_timeout=30, content_timeout=4) 
    5353 
    5454  #catch the right Exception if there is a different exception print failed_error_msg 
  • seattle/trunk/seattlelib/tests/httpretrieve_test/ut_httpretrieve_header_timeout.py

    r3253 r3276  
    3030  # a timeout exception, print failed_error_msg 
    3131  failed_error_msg = 'Failed: HttpContentReceivingError should have raised a timeout exception' 
    32   try:   
    33     recv_msg = httpretrieve_get_string('http://127.0.0.1:12345', ' ', 5, 5)   
     32  try: 
     33    recv_msg = httpretrieve_get_string('http://127.0.0.1:12345', http_query=None, http_post=None, http_header=None, header_timeout=5)   
    3434 
    3535  # catch the right Exception(HttpHeaderReceivingError) if there is a different exception print failed_error_msg 
  • seattle/trunk/seattlelib/tests/httpretrieve_test/ut_httpretrieve_post.py

    r3253 r3276  
    88include httpretrieve.repy 
    99include registerhttpcallback.repy 
     10include urllib.repy 
    1011 
    1112 
     
    2223 
    2324  # data to post to server using the httpretrieve  
    24   http_post = '' 
    25   for i in range(100): 
    26     http_post += str(i)   
     25  http_post={"first": "1st", "second": "2nd"} 
    2726     
    2827  # build temp server that acts normally and sends what ever the client posted data is 
     
    3534  try: 
    3635    # use httpretrieve to retrieve the content form the server.(which is the posted data)   
    37     recv_msg = httpretrieve_get_string('http://127.0.0.1:12345', http_post)    
     36    recv_msg = httpretrieve_get_string('http://127.0.0.1:12345', None, http_post)    
    3837 
    3938  except Exception, e: 
    4039    print 'Http retrieve failed on receiving content, Raised: ' + str(e) 
    4140  else: 
    42     if recv_msg != http_post: 
     41    # check if the recieved post is similar to the http post sent                                
     42    if recv_msg != urllib_quote_parameters(http_post): 
    4343      print 'failed: the received posted data didnt match the actual posted data' 
    44       print 'httpretrieve posted ' + http_post 
     44      print 'httpretrieve posted ' + urllib_quote_parameters(http_post) 
    4545      print 'server receieved ' + recv_msg  
    4646