parameters: (self, boundary)
docstring: Set the boundary parameter in Content-Type to 'boundary'.
  
          This is subtly different than deleting the Content-Type header and
          adding a new one with a new boundary parameter via add_header().  The
          main difference is that using the set_boundary() method preserves the
          order of the Content-Type header in the original message.
  
          HeaderParseError is raised if the message has no Content-Type header.
docstring_summary: Set the boundary parameter in Content-Type to 'boundary'.
docstring_tokens: Set the boundary parameter in Content - Type to boundary .
function: def set_boundary(self, boundary):
          """Set the boundary parameter in Content-Type to 'boundary'.
  
          This is subtly different than deleting the Content-Type header and
          adding a new one with a new boundary parameter via add_header().  The
          main difference is that using the set_boundary() method preserves the
          order of the Content-Type header in the original message.
  
          HeaderParseError is raised if the message has no Content-Type header.
          """
          missing = object()
          params = self._get_params_preserve(missing, 'content-type')
          if params is missing:
              # There was no Content-Type header, and we don't know what type
              # to set it to, so raise an exception.
              raise errors.HeaderParseError('No Content-Type header found')
          newparams = []
          foundp = False
          for pk, pv in params:
              if pk.lower() == 'boundary':
                  newparams.append(('boundary', '"%s"' % boundary))
                  foundp = True
              else:
                  newparams.append((pk, pv))
          if not foundp:
              # The original Content-Type header had no boundary attribute.
              # Tack one on the end.  BAW: should we raise an exception
              # instead???
              newparams.append(('boundary', '"%s"' % boundary))
          # Replace the existing Content-Type header with the new value
          newheaders = []
          for h, v in self._headers:
              if h.lower() == 'content-type':
                  parts = []
                  for k, v in newparams:
                      if v == '':
                          parts.append(k)
                      else:
                          parts.append('%s=%s' % (k, v))
                  newheaders.append((h, SEMISPACE.join(parts)))
  
              else:
                  newheaders.append((h, v))
          self._headers = newheaders
function_tokens: def set_boundary ( self , boundary ) : missing = object ( ) params = self . _get_params_preserve ( missing , 'content-type' ) if params is missing : # There was no Content-Type header, and we don't know what type # to set it to, so raise an exception. raise errors . HeaderParseError ( 'No Content-Type header found' ) newparams = [ ] foundp = False for pk , pv in params : if pk . lower ( ) == 'boundary' : newparams . append ( ( 'boundary' , '"%s"' % boundary ) ) foundp = True else : newparams . append ( ( pk , pv ) ) if not foundp : # The original Content-Type header had no boundary attribute. # Tack one on the end.  BAW: should we raise an exception # instead??? newparams . append ( ( 'boundary' , '"%s"' % boundary ) ) # Replace the existing Content-Type header with the new value newheaders = [ ] for h , v in self . _headers : if h . lower ( ) == 'content-type' : parts = [ ] for k , v in newparams : if v == '' : parts . append ( k ) else : parts . append ( '%s=%s' % ( k , v ) ) newheaders . append ( ( h , SEMISPACE . join ( parts ) ) ) else : newheaders . append ( ( h , v ) ) self . _headers = newheaders