code: def encode_metadata(self):
          
          encoded_list = []
          for key, value in iteritems(self.metadata):
              key_str = str(key)  # dict keys may be of any object type.
  
              # confirm that the key does not contain unwanted characters.
              if re.search(r'^$|[\s,]+', key_str):
                  msg = 'Upload-metadata key "{}" cannot be empty nor contain spaces or commas.'
                  raise ValueError(msg.format(key_str))
  
              value_bytes = b(value)  # python 3 only encodes bytes
              encoded_list.append('{} {}'.format(key_str, b64encode(value_bytes).decode('ascii')))
          return encoded_list
docs: Return list of encoded metadata as defined by the Tus protocol.