Normalize a tuple of BodyPart objects to a string.

    Normalization is done by sorting the body_parts by the Content- Disposition headers,
    which is typically on the form, ``form-data; name="name_of_part``.
352317
def normalize(body_part_tup,):
    
    return '\n\n'.join(
        [
            '{}\n\n{}'.format(
                str(p.headers[b'Content-Disposition'], p.encoding), p.text
            )
            for p in sorted(
                body_part_tup, key=lambda p: p.headers[b'Content-Disposition']
            )
        ]
    )
1304581
def _get_pretty_body(headers, body):
    
    try:
        if CONTENT_TYPE_HEADER_NAME in headers:
            if XMLRenderer.DEFAULT_CONTENT_TYPE == headers[CONTENT_TYPE_HEADER_NAME]:
                xml_parsed = parseString(body)
                pretty_xml_as_string = xml_parsed.toprettyxml()
                return pretty_xml_as_string
            elif JSONRenderer.DEFAULT_CONTENT_TYPE == headers[CONTENT_TYPE_HEADER_NAME]:
                decoded_body = body.decode('utf-8')
                parsed = json.loads(decoded_body)
                return json.dumps(parsed, sort_keys=True, indent=4)
    except:
        pass
    finally:
        return body
119519
function stringToStringTuples (str) {
  const tuples = []
  const parts = str.split('/').slice(1) // skip first empty elem
  if (parts.length === 1 && parts[0] === '') {
    return []
  }

  for (let p = 0; p < parts.length; p++) {
    const part = parts[p]
    const proto = protocols(part)

    if (proto.size === 0) {
      tuples.push([part])
      continue
    }

    p++ // advance addr part
    if (p >= parts.length) {
      throw ParseError('invalid address: ' + str)
    }

    // if it's a path proto, take the rest
    if (proto.path) {
      tuples.push([
        part,
        // TODO: should we need to check each path part to see if it's a proto?
        // This would allow for other protocols to be added after a unix path,
        // however it would have issues if the path had a protocol name in the path
        cleanPath(parts.slice(p).join('/'))
      ])
      break
    }

    tuples.push([part, parts[p]])
  }

  return tuples
}
673440
private String normalize(String name) {
        return Normalizer.normalize(name, Normalizer.Form.NFKD);
    }
679050
function stringTuplesToString (tuples) {
  const parts = []
  tuples.map(tup => {
    const proto = protoFromTuple(tup)
    parts.push(proto.name)
    if (tup.length > 1) {
      parts.push(tup[1])
    }
  })

  return cleanPath(parts.join('/'))
}
1113192
def normalize_name(name):
    
    if not name or not isinstance(name, basestring):
        raise ValueError('Can only normalize non-empty string names. Unexpected '+ repr(name))

    if len(name) > 1:
        name = name.lower()
    if name != '_' and '_' in name:
        name = name.replace('_', ' ')

    return canonical_names.get(name, name)
905220
function normalize(obj) {
    const isMultipart = isFormData(obj);
    const content = { filename: '', value: '', mime: '' };
    const result = ((isMultipart) ? new FormData() : {});
    let file = null;

    Object.keys(obj).forEach((item) => {
        if (isMultipart) {
            if (obj[item].value) content.value = obj[item].value;
            else content.value = obj[item];

            content.filename = obj[item].filename || null;
            content.mime = obj[item].mime || null;

            if (content.value instanceof stream.Stream) {
                result.append(item, content.value, {
                    contentType: content.mime,
                    filename: content.filename,
                });

                return;
            }

            if (Buffer.isBuffer(content.value)) {
                file = FileType(content.value);
                result.append(item, content.value, {
                    contentType: content.mime || file.mime || 'application/octet-stream',
                    filename: content.filename || `data-${Date.now()}.${file.ext || ''}`,
                });

                return;
            }

            if (typeof content.value === 'object') {
                result.append(item, JSON.stringify(content.value), {
                    contentType: 'application/json',
                });

                return;
            }

            result.append(item, content.value);
        } else {
            if (typeof obj[item] === 'object') {
                result[item] = JSON.stringify(obj[item]);
                return;
            }

            result[item] = obj[item];
        }
    });

    return result;
}
1251450
def normalize(self):
        """"""
        chrfunc = chr if py3k else HTMLEntity._unichr
        if self.named:
            return chrfunc(htmlentities.name2codepoint[self.value])
        if self.hexadecimal:
            return chrfunc(int(self.value, 16))
        return chrfunc(int(self.value))
487258
function parseBody()
    {
        $result = array(
            'data'=>array(),
            'files'=>array(),
            );

         // read incoming data
        $input = Instance::get('BODY');

        // grab multipart boundary from content type header
        preg_match('/boundary=(.*)$/', $_SERVER['CONTENT_TYPE'], $matches);

        // content type is probably regular form-encoded
        if (!count($matches)) {
            // we expect regular puts to containt a query string containing data
            parse_str($input, $result['data']);
        } else {
            $boundary = $matches[1];
            // split content by boundary and get rid of last -- element
            $a_blocks = preg_split("/-+$boundary/", $input);
            array_pop($a_blocks);

            // loop data blocks
            foreach ($a_blocks as $id => $block) {
                if (empty($block))
                    continue;
                // you'll have to var_dump $block to understand this and maybe replace \n or \r with a visibile char
                // parse uploaded files
                if (strpos($block, 'application/octet-stream') !== FALSE) {
                    // match "name", then everything after "stream" (optional) except for prepending newlines
                    // preg_match("/name=\"([^\"]*)\".*stream[\n|\r]+([^\n\r].*)?$/s", $block, $matches);
                    // $a_data['files'][$matches[1]] = isset($matches[2])?$matches[2]:null;
                }
                // parse all other fields
                else {
                    // match "name" and optional value in between newline sequences
                    if (strpos($block, 'filename="')===false) {
                        preg_match('/name=\"([^\"]*)\"[\n|\r]+([^\n\r].*)?\r$/s', $block, $matches);
                        $result['data'][$matches[1]] = isset($matches[2])?$matches[2]:null;
                    } else {
                        preg_match('/; name=\"([^\"]*)\"; filename=\"([^\"]*)\"\s*Content\-Type: ([\w\/]+)[\n|\r]+([^\n\r].*)?\r$/s', $block, $matches);
                        $result['files'][$matches[1]] = array(
                            'name' => $matches[2],
                            'type' => $matches[3],
                            'tmp_name' => tempnam( ini_get( 'upload_tmp_dir' ), 'php' ),
                            'error' => UPLOAD_ERR_OK,
                            'size' => 0);
                        $result['files'][$matches[1]]['size'] = file_put_contents($result['files'][$matches[1]]['tmp_name'], $matches[4]);
                        $result['files'][$matches[1]]['size']!==false || $result['files'][$matches[1]]['error'] = UPLOAD_ERR_CANT_WRITE;
                    }
                }
            }
        }

        return $result;
    }
1326757
public void normalizePercentEncoding() {
        try {
            uri = new URI(uri.getScheme(),
                          uri.getSchemeSpecificPart(),
                          uri.getFragment());
        } catch (URISyntaxException e) {
            // This should never be reached
            e.printStackTrace();
        }
    }
1188966
private void parseBody() {
        if (currentStatus == MultiPartStatus.PREEPILOGUE || currentStatus == MultiPartStatus.EPILOGUE) {
            if (isLastChunk) {
                currentStatus = MultiPartStatus.EPILOGUE;
            }
            return;
        }
        parseBodyMultipart();
    }
1112297
def normalizeToName(val):
    
    if val not in tagsAndNameSet:
        raise KeyError("{} is not a tag or name string".format(val))
    else:
        try:
            return tagToFullDict[val]
        except KeyError:
            return val
997365
function remakeBody (body, bodyType) {
  return blobUtil
    .base64StringToBlob(body)
    .then(function (blob) {
      switch (bodyType) {
        case BodyTypes.ARRAY_BUFFER:
          return blobUtil.blobToArrayBuffer(blob)
        case BodyTypes.BLOB:
          return blob
        case BodyTypes.FORM_DATA:
          throw new Error('Cannot make FormData from serialised Request')
        case BodyTypes.JSON:
          return blobToString(blob)
            .then(function (str) {
              return JSON.parse(str)
            })
        case BodyTypes.TEXT:
          return blobToString(blob)
        default:
          throw new Error('Unknown requested body type "' + bodyType + '"')
      }
    })
}
930712
def normalize_names(names):
    """"""
    if isinstance(names, basestring):
        names = names.split(',')
    names = listify(names)
    return [str(name).strip() for name in names]
1372690
private void parseBody() {
        if (currentStatus == MultiPartStatus.PREEPILOGUE || currentStatus == MultiPartStatus.EPILOGUE) {
            if (isLastChunk) {
                currentStatus = MultiPartStatus.EPILOGUE;
            }
            return;
        }
        parseBodyAttributes();
    }
1123584
function bodyToParams(body) {
  var params = {};

  body = body.trim();
  body.split('\n').forEach(function(line) {
    var match = line.trim().match(/^(\w+)=(.*)$/);
    if (match) {
      params[match[1]] = match[2];
    }
  });
  return params;
}
185078
def normalize_name(s):
    
    # Normalize the string into a byte string form
    s = unicodedata.normalize('NFKD', s).encode('ascii', 'ignore')
    # Remove the byte string and quotes from the string
    s = str(s)[2:-1]
    return s