parameters: (self, data, files, json=None)
docstring: Prepares the given HTTP body data.
docstring_summary: Prepares the given HTTP body data.
docstring_tokens: Prepares the given HTTP body data .
function: def prepare_body(self, data, files, json=None):
          """Prepares the given HTTP body data."""
  
          # Check if file, fo, generator, iterator.
          # If not, run through normal process.
  
          # Nottin' on you.
          body = None
          content_type = None
          length = None
  
          if json is not None:
              content_type = 'application/json'
              body = json_dumps(json)
  
          is_stream = all([
              hasattr(data, '__iter__'),
              not isinstance(data, (basestring, list, tuple, dict))
          ])
  
          try:
              length = super_len(data)
          except (TypeError, AttributeError, UnsupportedOperation):
              length = None
  
          if is_stream:
              body = data
  
              if files:
                  raise NotImplementedError('Streamed bodies and files are mutually exclusive.')
  
              if length is not None:
                  self.headers['Content-Length'] = builtin_str(length)
              else:
                  self.headers['Transfer-Encoding'] = 'chunked'
          else:
              # Multi-part file uploads.
              if files:
                  (body, content_type) = self._encode_files(files, data)
              else:
                  if data and json is None:
                      body = self._encode_params(data)
                      if isinstance(data, basestring) or hasattr(data, 'read'):
                          content_type = None
                      else:
                          content_type = 'application/x-www-form-urlencoded'
  
              self.prepare_content_length(body)
  
              # Add content-type if it wasn't explicitly provided.
              if content_type and ('content-type' not in self.headers):
                  self.headers['Content-Type'] = content_type
  
          self.body = body
function_tokens: def prepare_body ( self , data , files , json = None ) : # Check if file, fo, generator, iterator. # If not, run through normal process. # Nottin' on you. body = None content_type = None length = None if json is not None : content_type = 'application/json' body = json_dumps ( json ) is_stream = all ( [ hasattr ( data , '__iter__' ) , not isinstance ( data , ( basestring , list , tuple , dict ) ) ] ) try : length = super_len ( data ) except ( TypeError , AttributeError , UnsupportedOperation ) : length = None if is_stream : body = data if files : raise NotImplementedError ( 'Streamed bodies and files are mutually exclusive.' ) if length is not None : self . headers [ 'Content-Length' ] = builtin_str ( length ) else : self . headers [ 'Transfer-Encoding' ] = 'chunked' else : # Multi-part file uploads. if files : ( body , content_type ) = self . _encode_files ( files , data ) else : if data and json is None : body = self . _encode_params ( data ) if isinstance ( data , basestring ) or hasattr ( data , 'read' ) : content_type = None else : content_type = 'application/x-www-form-urlencoded' self . prepare_content_length ( body ) # Add content-type if it wasn't explicitly provided. if content_type and ( 'content-type' not in self . headers ) : self . headers [ 'Content-Type' ] = content_type self . body = body