Parse primary key value from parameters.
Throw an error if it cannot be retrieved.

@param  {Request} req
@return {Integer|String}
428912
function(req) {

    var pk = module.exports.parsePk(req);

    // Validate the required `id` parameter
    if (!pk) {

      var err = new Error(
        'No `id` parameter provided.' +
        '(Note: even if the model\'s primary key is not named `id`- ' +
        '`id` should be used as the name of the parameter- it will be ' +
        'mapped to the proper primary key name)'
      );
      err.status = 400;
      throw err;
    }

    return pk;
  }
987045
def parse_request(api_secret, reqbody, dec_func=False):
    
    try:
        if type(reqbody) == type(dict):
            return self.parse_form_request(reqbody)
            
        if callable(dec_func):
            req_msg = json.loads(dec_func(reqbody))
        else:
            req_msg = json.loads(reqbody)
    except Exception as err:
        raise ParseError(u"parse params error")

    if not check_sign(api_secret, req_msg):
        raise SignError(u"message sign error")

    return Storage(req_msg)
707331
function parsePathParams (req, res, next) {
    if (util.isSwaggerRequest(req)) {
      req.pathParams = {};

      if (req.swagger.pathName.indexOf("{") >= 0) {
        // Convert the Swagger path to a RegExp
        let paramNames = [];
        let pathPattern = req.swagger.pathName.replace(util.swaggerParamRegExp, (match, paramName) => {
          paramNames.push(paramName);
          return "([^\/]+)";
        });

        // Exec the RegExp to get the path param values from the URL
        let values = new RegExp(pathPattern + "\/?$", "i").exec(req.path);

        // Parse each path param
        for (let i = 1; i < values.length; i++) {
          let paramName = paramNames[i - 1];
          let paramValue = decodeURIComponent(values[i]);
          let param = _.find(req.swagger.params, { in: "path", name: paramName });

          util.debug('    Parsing the "%s" path parameter', paramName);
          req.pathParams[paramName] = paramParser.parseParameter(param, paramValue, param);
        }
      }
    }

    next();
  }
874100
function parseQueryString(query) {
  if (!query) {
    return {};
  }
  return (/^[?#]/.test(query) ? query.slice(1) : query)
      .split('&')
      .reduce((params, param) => {
        const item = param.split('=');
        const key = decodeURIComponent(item[0] || '');
        const value = decodeURIComponent(item[1] || '');
        if (key) {
          params[key] = value;
        }
        return params;
      }, {});
}
992100
def get_from_params(request, key):
    
    data = getattr(request, 'json', None) or request.values
    value = data.get(key)
    return to_native(value)
618409
function parsePath(req) {
  // get path if preprocessed or otherwise separate path from query string
  const path = req.path || (req.url && req.url.split('?')[0]) || '';
  // ignore start and end slashes, and split the path
  return path.replace(/^\/|\/$/g, '').split('/');
}
292580
function GET(uri, params) {
	const reqUrl = `${uri}${url.format({ query: params })}`;

	log(`request URL: ${reqUrl}`);

	return fetch(reqUrl)
		.then(function handleGetRequest(res) {
			const status = res.status;
			const statusText = res.statusText;

			log(`status code: ${status}`);
			log(`status text: ${statusText}`);

			if (status !== 200) {
				const err = new Error(`Request failed: ${statusText}`);

				err.status = status;

				throw err;
			}

			return res.json();
		})
		.then(data => {
			const posts = data.posts;

			log(`${posts.length} posts were fetched`);

			return posts;
		})
		.catch(err => {
			log('catched err: ', err);

			throw err;
		});
}
701047
function processRequestOptions(req, attrNode, context) {
    if ('id' in req) {
        if (context.attrPath.length > 0) {
            throw new RequestError('ID option only allowed at root (in "' + context.attrPath.join('.') + '")');
        }

        // TODO: Cast req.id to defined type and handle composite primaryKey

        attrNode.many = false;

        context.resourceTree.filter = [
            [
                {
                    attribute: context.resourceTree.primaryKey,
                    operator: 'equal',
                    value: req.id
                }
            ]
        ];
    }

    if ('filter' in req) {
        let requestFilter = req.filter.map(andFilter =>
            andFilter.map(filter => {
                let filteredAttrNode = attrNode;
                const subResourceAttrNodes = [];

                let subContext = Object.assign({}, context);
                filter.attribute.forEach(subAttr => {
                    filteredAttrNode = getAttributeWithAuthCheck([subAttr], filteredAttrNode, subContext);
                    if (filteredAttrNode.dataSources) subResourceAttrNodes.push(filteredAttrNode);
                    subContext.attrPath = subContext.attrPath.concat([subAttr]);
                });

                if (!filteredAttrNode.filter) {
                    throw new RequestError(
                        [
                            'Can not filter by attribute "' + filter.attribute.join('.') + '" ',
                            context.attrPath.length > 0 ? '(in "' + context.attrPath.join('.') + '") ' : ''
                        ].join('')
                    );
                }
                if (filteredAttrNode.filter.indexOf(filter.operator) === -1) {
                    throw new RequestError(
                        [
                            'Can not filter by attribute "' + filter.attribute.join('.') + '" ',
                            context.attrPath.length > 0 ? '(in "' + context.attrPath.join('.') + '") ' : '',
                            'with "' + filter.operator + '" ',
                            '(allowed operators: ' + filteredAttrNode.filter.join(', ') + ')'
                        ].join('')
                    );
                }

                const resolvedFilter = {
                    attribute: filteredAttrNode.map.default,
                    operator: filter.operator,
                    value: filter.value
                };
                let parentFilter = resolvedFilter;

                // resolve filter by sub-resources:
                if (subResourceAttrNodes.length > 0) {
                    let subFilter;
                    if (attrNode.subFilters) {
                        attrNode.subFilters.forEach(_subFilter => {
                            if (filter.attribute.join('.') === _subFilter.attribute.join('.')) {
                                subFilter = _subFilter;
                            }
                        });
                    }

                    if (!subFilter) {
                        throw new RequestError(
                            `Can not filter by sub-resource attribute "${filter.attribute.join('.')}"` +
                                (context.attrPath.length > 0 ? ` (in "${context.attrPath.join('.')}")` : '')
                        );
                    }

                    if (subFilter.filter.indexOf(filter.operator) === -1) {
                        throw new RequestError(
                            `Can not filter by sub-resource attribute "${filter.attribute.join('.')}"` +
                                (context.attrPath.length > 0 ? ` (in "${context.attrPath.join('.')}")` : '') +
                                ` with "${filter.operator}" (allowed operators: ${subFilter.filter.join(', ')})`
                        );
                    }

                    if (subFilter.rewriteTo) {
                        const filterAttrNode = getAttribute(subFilter.rewriteTo, attrNode, context);
                        parentFilter.attribute = filterAttrNode.map.default;
                    } else {
                        let filterContext = context;
                        subResourceAttrNodes.forEach(subResourceAttrNode => {
                            let subFilterTree = {
                                dataSources: subResourceAttrNode.dataSources,
                                attributes: [],
                                filter: null,
                                parentKey: subResourceAttrNode.resolvedParentKey,
                                childKey: subResourceAttrNode.resolvedChildKey
                            };

                            // select childKey from DataSource:
                            subResourceAttrNode.childKey.forEach(childKeyAttrPath => {
                                const childKeyAttrNode = getAttribute(childKeyAttrPath, subResourceAttrNode, context);
                                subFilterTree.attributes.push({
                                    dataSourceMap: childKeyAttrNode.map.default,
                                    attrNode: childKeyAttrNode,
                                    fromDataSource: '#current-primary'
                                });
                            });

                            // modify parent-filter to sub-filter:
                            parentFilter.attribute = subResourceAttrNode.resolvedParentKey;
                            parentFilter.operator = 'equal';
                            delete parentFilter.value;
                            const previousParentFilter = parentFilter;

                            // ... then filter sub-resource by given attribute:
                            parentFilter = {
                                attribute: filteredAttrNode.map.default,
                                operator: filter.operator,
                                value: filter.value
                            };
                            subFilterTree.filter = [[parentFilter]];

                            // handle m:n relations with join-table:
                            if (subResourceAttrNode.joinVia) {
                                const joinViaDataSource = subResourceAttrNode.dataSources[subResourceAttrNode.joinVia];

                                const resolvedJoinParentKey = {};
                                resolvedJoinParentKey[subResourceAttrNode.joinVia] =
                                    joinViaDataSource.resolvedJoinParentKey;
                                const resolvedJoinChildKey = {};
                                resolvedJoinChildKey[subResourceAttrNode.joinVia] =
                                    joinViaDataSource.resolvedJoinChildKey;

                                const joinSubFilterTree = {
                                    dataSources: subResourceAttrNode.dataSources,
                                    primaryName: subResourceAttrNode.joinVia,
                                    attributes: [],
                                    filter: [
                                        [
                                            {
                                                attribute: resolvedJoinChildKey,
                                                operator: 'equal',
                                                valueFromSubFilter: 0
                                            }
                                        ]
                                    ],
                                    parentKey: subFilterTree.parentKey,
                                    childKey: resolvedJoinParentKey
                                };

                                subFilterTree.parentKey = resolvedJoinChildKey;

                                // select joinParentKey from DataSource:
                                joinViaDataSource.joinParentKey.forEach(joinParentKeyAttrPath => {
                                    const joinParentKeyAttrNode = getAttribute(
                                        joinParentKeyAttrPath,
                                        subResourceAttrNode,
                                        context
                                    );
                                    joinSubFilterTree.attributes.push({
                                        dataSourceMap: joinParentKeyAttrNode.map.default,
                                        attrNode: joinParentKeyAttrNode,
                                        fromDataSource: subResourceAttrNode.joinVia
                                    });
                                });

                                // link join-sub-filter in between:
                                joinSubFilterTree.subFilters = [subFilterTree];
                                subFilterTree = joinSubFilterTree;
                            }

                            // link sub-filter to parent:
                            if (!filterContext.resourceTree.subFilters) {
                                filterContext.resourceTree.subFilters = [];
                            }

                            previousParentFilter.valueFromSubFilter = filterContext.resourceTree.subFilters.length;
                            filterContext.resourceTree.subFilters.push(subFilterTree);

                            // switch filter-context:
                            filterContext = Object.assign({}, filterContext);
                            filterContext.resourceTree = subFilterTree;
                        });
                    }
                }

                // TODO: Check type of values

                return resolvedFilter;
            })
        );

        if (context.resourceTree.filter) {
            // generate cross product of OR filters:
            const combinedFilter = [];
            requestFilter.forEach(andFilter => {
                context.resourceTree.filter.forEach(andFilter2 => {
                    combinedFilter.push(cloneDeep(andFilter).concat(cloneDeep(andFilter2)));
                });
            });
            requestFilter = combinedFilter;
        }

        context.resourceTree.filter = requestFilter;
    }

    if ('search' in req) {
        context.resourceTree.search = req.search;
    }

    const order = req.order || attrNode.defaultOrder;
    if (order) {
        context.resourceTree.order = order.map(orderPart => {
            let orderedAttrNode = attrNode;
            let subContext = Object.assign({}, context);
            orderPart.attribute.forEach(subAttr => {
                orderedAttrNode = getAttributeWithAuthCheck([subAttr], orderedAttrNode, subContext);
                if (orderedAttrNode.dataSources) {
                    throw new RequestError(
                        `Can not order by sub-resource attribute "${orderPart.attribute.join('.')}"` +
                            (context.attrPath.length > 0 ? ` (in "${context.attrPath.join('.')}")` : '')
                    );
                }
                subContext.attrPath = subContext.attrPath.concat([subAttr]);
            });

            if (!orderedAttrNode.order) {
                throw new RequestError(
                    [
                        'Attribute "' + orderPart.attribute.join('.') + '" ',
                        context.attrPath.length > 0 ? ' (in "' + context.attrPath.join('.') + '") ' : '',
                        'can not be ordered'
                    ].join('')
                );
            }
            if (orderedAttrNode.order.indexOf(orderPart.direction) === -1) {
                throw new RequestError(
                    [
                        'Attribute "' + orderPart.attribute.join('.') + '" ',
                        context.attrPath.length > 0 ? ' (in "' + context.attrPath.join('.') + '")' : '',
                        'can not be ordered "' +
                            orderPart.direction +
                            '" (allowed: ' +
                            orderedAttrNode.order.join(', ') +
                            ')'
                    ].join('')
                );
            }

            orderPart = Object.assign({}, orderPart);
            orderPart.attribute = orderedAttrNode.map.default;

            return orderPart;
        });
    }

    let limit = null;
    if ('limit' in req) {
        if (!attrNode.many) {
            throw new RequestError(
                'Invalid limit on a single resource' +
                    (context.attrPath.length > 0 ? ` (in "${context.attrPath.join('.')}")` : '')
            );
        }
        limit = req.limit;
    } else if (attrNode.many) {
        limit = attrNode.defaultLimit || attrNode.maxLimit || (context.isMainResource ? 10 : null);
    }
    if (attrNode.maxLimit) {
        if (limit === null || limit > attrNode.maxLimit) {
            throw new RequestError(
                `Invalid limit ${limit !== null ? limit : 'unlimited'}, maxLimit is ${attrNode.maxLimit}` +
                    (context.attrPath.length > 0 ? ` (in "${context.attrPath.join('.')}")` : '')
            );
        }
    }
    if (limit !== null) {
        context.resourceTree.limit = limit;
        if (!context.isMainResource && context.isMany) {
            context.resourceTree.limitPerGroup = true;
        }
    }

    if ('page' in req) {
        if (!('limit' in req)) {
            throw new RequestError(
                'Always specify a fixed limit when requesting page' +
                    (context.attrPath.length > 0 ? ` (in "${context.attrPath.join('.')}")` : '')
            );
        }

        context.resourceTree.page = req.page;
    }
}
735227
function hmget(key /* field-1, field-N, req */) {
  var args = slice.call(arguments, 1)
    , req = typeof args[args.length - 1] === 'object'
        ? args.pop() : null
    , val = this.getKey(key, req)
    , value
    , list = []
    , i;
  for(i = 0;i < args.length;i++) {
    if(!val) {
      list.push(null);
      continue;
    }
    value = val.getKey(args[i])
    list.push(value !== undefined ? value : null);
  }
  return list;
}
591931
function decodeDataUrlFromQueryParam(value) {
  if (typeof value !== 'string') {
    return undefined
  }
  const maybeDataUrl = prependPrefix(value, 'data:')
    .replace(/ /g, '+')
    .replace(/\s/g, '')
  return isDataUrl(maybeDataUrl) ? maybeDataUrl : undefined
}
695482
function parseHeader(req) {

    if (req.headers && req.headers.authorization) {

        var credentialsIndex = 1;
        var parts = req.headers.authorization.split(' ');
        var partsExpectedLength = 2;
        var schemeIndex = 0;

        if (parts.length === partsExpectedLength) {

            var credentials = parts[credentialsIndex];
            var scheme = parts[schemeIndex];

            if (/^Bearer$/i.test(scheme)) {
                return credentials;
            }

        }

    }

    return null;

}
246035
def parse_querystring(self, req: Request, name: str, field: Field) -> typing.Any:
        """"""
        return core.get_value(req.query, name, field)
934908
function collectQueryParams(req, paramNames) {
    var result = {
        query: {},
        fields: {},
        options: {},
        params: {}
    };
    paramNames.forEach(function (paramName) {
        var paramValue = req.anyParam(paramName);
        if (paramValue) {
            paramValue = paramValue.trim();
            if (paramValue && paramValue !== '*') {
                if (paramValue.charAt(paramValue.length - 1) === '*') {
                    // regexp to match prefix
                    paramValue = new RegExp('^' + paramValue.substring(0, paramValue.length - 1));
                }
                result.query[paramName] = paramValue;
            }
            result.params[paramName] = paramValue;
        }
    });
    var fields = req.anyParam('fields');
    if (fields) {
        result.fields = {};
        fields.split(',').forEach(function (field) {
            field = field.trim();
            if (field) {
                var select = 1;
                switch (field.charAt(0)) {
                    case '-':
                        field = field.substring(1);
                        select = 0;
                        break;
                    case '+':
                        field = field.substring(1);
                        break;
                }
                result.fields[field] = select;
            }
        });
    }
    var sort = req.anyParam('sort');
    if (sort) {
        result.options.sort = {};
        sort.split(',').forEach(function (field) {
            field = field.trim();
            if (field) {
                var order = 1;
                switch (field.charAt(0)) {
                    case '-':
                        field = field.substring(1);
                        order = -1;
                        break;
                    case '+':
                        field = field.substring(1);
                        break;
                }
                result.options.sort[field] = order;
            }
        });
        result.params.sort = sort;
    }
    var skip = req.anyParam('skip') || req.anyParam('offset');
    if (skip) {
        result.options.skip = parseInt(skip, 10);
        result.params.skip = skip;
    }
    var limit = req.anyParam('limit');
    if (limit) {
        result.options.limit = parseInt(limit, 10);
        result.params.limit = limit;
    }
    return result;
}
202898
function parseQueryMap(query) {
  var map = {};
  parseQueryString(query, function(key, value) {
    map[key] = value;
  });
  return map;
}
1327242
function get(key, req) {
  var val = this.getKey(key, req);
  if(val === undefined) {
    return null;
  }
  return this.raw ? val : '' + val;
}
1280750
public static String getRequestParameterValue(final HttpServletRequest request, final String key) {
		String[] values = getRequestParameterValues(request, key);
		return values == null || values.length == 0 ? null : values[0];
	}
6321
function(req, res) {
    var params = URL.parse(req.url, true).query
      , code = params.code
      , state = params.state
    ;

    if(!code) {
      res.writeHead(400, {'Content-Type': 'text/plain'});
      return res.end('The "code" parameter is missing.');
    }
    if(!state) {
      res.writeHead(400, {'Content-Type': 'text/plain'});
      return res.end('The "state" parameter is missing.');
    }
    try {
      state = this.serializer.parse(state);
    } catch(err) {
      res.writeHead(400, {'Content-Type': 'text/plain'});
      return res.end('The "state" parameter is invalid.');
    }
    var data = {
      oauth2_server_id: state[0]
      , next_url: state[1]
      , state: state[2]
    }
    var methods = this.methods[data.oauth2_server_id];
    methods.valid_grant(data, code, function(err, token) {
      if (err) return server_error(res, err);
      if(!token) {
        res.writeHead(400, {'Content-Type': 'text/plain'});
        res.end('Invalid grant.');
        return;
      }
      data.token = token;
      methods.treat_access_token(data, req, res, function() {
        redirect(res, data.next_url);
      }, function(err){server_error(res, err)});
    });
  }