// ParseInputs uses DefaultInputEncParsers to parse io.Reader described by
// input encoding and format to an instance of ipld Node
553942
func ParseInputs(ienc, format string, r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
	return DefaultInputEncParsers.ParseInputs(ienc, format, r, mhType, mhLen)
}
81998
func parseSingleIPTemplate(ipTmpl string) (string, error) {
	out, err := template.Parse(ipTmpl)
	if err != nil {
		return "", fmt.Errorf("Unable to parse address template %q: %v", ipTmpl, err)
	}

	ips := strings.Split(out, " ")
	switch len(ips) {
	case 0:
		return "", errors.New("No addresses found, please configure one.")
	case 1:
		return ips[0], nil
	default:
		return "", fmt.Errorf("Multiple addresses found (%q), please configure one.", out)
	}
}
380507
func ParseIPWithPrefix(input string) (addr *net.IPNet, isIpv6 bool, err error) {
	defaultIpv4Mask := net.CIDRMask(32, 32)
	defaultIpv6Mask := net.CIDRMask(128, 128)

	hasPrefix := strings.Contains(input, "/")

	if hasPrefix {
		ip, network, err := net.ParseCIDR(input)
		if err != nil {
			return nil, false, err
		}
		network.IP = ip
		isIpv6, err = IsIPv6(ip.String())
		return network, isIpv6, err
	}

	// Ip prefix was not set
	ip := net.ParseIP(input)
	if ip == nil {
		return nil, false, fmt.Errorf("Unable to parse IP address: %v", input)
	}
	isIpv6, err = IsIPv6(ip.String())
	if err != nil {
		return
	}

	network := net.IPNet{}
	network.IP = ip
	if isIpv6 {
		network.Mask = defaultIpv6Mask
	} else {
		network.Mask = defaultIpv4Mask
	}
	return &network, isIpv6, nil
}
405065
func (k *Key) parseInts(strs []string, addInvalid, returnOnInvalid bool) ([]int, error) {
	vals := make([]int, 0, len(strs))
	for _, str := range strs {
		valInt64, err := strconv.ParseInt(str, 0, 64)
		val := int(valInt64)
		if err != nil && returnOnInvalid {
			return nil, err
		}
		if err == nil || addInvalid {
			vals = append(vals, val)
		}
	}
	return vals, nil
}
636176
func parseInputValueDef(parser *Parser) (interface{}, error) {
	var (
		description *ast.StringValue
		name        *ast.Name
		ttype       ast.Type
		directives  []*ast.Directive
		err         error
	)
	start := parser.Token.Start
	if description, err = parseDescription(parser); err != nil {
		return nil, err
	}
	if name, err = parseName(parser); err != nil {
		return nil, err
	}
	if _, err = expect(parser, lexer.COLON); err != nil {
		return nil, err
	}
	if ttype, err = parseType(parser); err != nil {
		return nil, err
	}
	var defaultValue ast.Value
	if skp, err := skip(parser, lexer.EQUALS); err != nil {
		return nil, err
	} else if skp {
		val, err := parseConstValue(parser)
		if err != nil {
			return nil, err
		}
		if val, ok := val.(ast.Value); ok {
			defaultValue = val
		}
	}
	if directives, err = parseDirectives(parser); err != nil {
		return nil, err
	}
	return ast.NewInputValueDefinition(&ast.InputValueDefinition{
		Name:         name,
		Description:  description,
		Type:         ttype,
		DefaultValue: defaultValue,
		Directives:   directives,
		Loc:          loc(parser, start),
	}), nil
}
491637
func parseInput() {
	logs.Log.Informational("\n添加任务参数——必填：%v\n添加任务参数——必填可选：%v\n", "-c_spider", []string{
		"-a_keyins",
		"-a_limit",
		"-a_outtype",
		"-a_thread",
		"-a_pause",
		"-a_proxyminute",
		"-a_dockercap",
		"-a_success",
		"-a_failure"})
	logs.Log.Informational("\n添加任务：\n")
retry:
	*spiderflag = ""
	input := [12]string{}
	fmt.Scanln(&input[0], &input[1], &input[2], &input[3], &input[4], &input[5], &input[6], &input[7], &input[8], &input[9])
	if strings.Index(input[0], "=") < 4 {
		logs.Log.Informational("\n添加任务的参数不正确，请重新输入：")
		goto retry
	}
	for _, v := range input {
		i := strings.Index(v, "=")
		if i < 4 {
			continue
		}
		key, value := v[:i], v[i+1:]
		switch key {
		case "-a_keyins":
			cache.Task.Keyins = value
		case "-a_limit":
			limit, err := strconv.ParseInt(value, 10, 64)
			if err != nil {
				break
			}
			cache.Task.Limit = limit
		case "-a_outtype":
			cache.Task.OutType = value
		case "-a_thread":
			thread, err := strconv.Atoi(value)
			if err != nil {
				break
			}
			cache.Task.ThreadNum = thread
		case "-a_pause":
			pause, err := strconv.ParseInt(value, 10, 64)
			if err != nil {
				break
			}
			cache.Task.Pausetime = pause
		case "-a_proxyminute":
			proxyminute, err := strconv.ParseInt(value, 10, 64)
			if err != nil {
				break
			}
			cache.Task.ProxyMinute = proxyminute
		case "-a_dockercap":
			dockercap, err := strconv.Atoi(value)
			if err != nil {
				break
			}
			if dockercap < 1 {
				dockercap = 1
			}
			cache.Task.DockerCap = dockercap
		case "-a_success":
			if value == "true" {
				cache.Task.SuccessInherit = true
			} else if value == "false" {
				cache.Task.SuccessInherit = false
			}
		case "-a_failure":
			if value == "true" {
				cache.Task.FailureInherit = true
			} else if value == "false" {
				cache.Task.FailureInherit = false
			}
		case "-c_spider":
			*spiderflag = value
		default:
			logs.Log.Informational("\n不可含有未知参数，必填参数：%v\n可选参数：%v\n", "-c_spider", []string{
				"-a_keyins",
				"-a_limit",
				"-a_outtype",
				"-a_thread",
				"-a_pause",
				"-a_proxyminute",
				"-a_dockercap",
				"-a_success",
				"-a_failure"})
			goto retry
		}
	}
}
370243
func parseFormatPanesSet(formatSet string) (*formatPanes, error) {
	format := formatPanes{}
	err := json.Unmarshal([]byte(formatSet), &format)
	return &format, err
}
662701
func parseEndpointSet(args ...string) (ep endpointSet, err error) {
	var argPatterns = make([]ellipses.ArgPattern, len(args))
	for i, arg := range args {
		patterns, perr := ellipses.FindEllipsesPatterns(arg)
		if perr != nil {
			return endpointSet{}, uiErrInvalidErasureEndpoints(nil).Msg(perr.Error())
		}
		argPatterns[i] = patterns
	}

	ep.setIndexes, err = getSetIndexes(args, getTotalSizes(argPatterns))
	if err != nil {
		return endpointSet{}, uiErrInvalidErasureEndpoints(nil).Msg(err.Error())
	}

	ep.argPatterns = argPatterns

	return ep, nil
}
695342
func parseInclude(t *Tree, start Pos) (Node, error) {
	expr, with, only, err := parseIncludeOrEmbed(t)
	if err != nil {
		return nil, err
	}
	return NewIncludeNode(expr, with, only, start), nil
}
1152846
func ParseID(s string) (ID, error) {
	var id ID
	err := id.UnmarshalText([]byte(s))
	if err != nil {
		return ID{}, err
	}
	return id, nil
}
923214
func ParseInput(input [6]string) *crontime {
	var result crontime
	// Check the syntax of the input
	for i := 0; i != len(input); i++ {
		if checkSyntax(input[i]) == false {
			log.Panicln("Invalid config at Line", i) // TODO be more helpful
		}
	}
	// Parse Input like 23-05
	for i := 0; i != len(input); i++ {
		if strings.Contains(input[i], "-") {
			result.parseRange(input[i], i)
		}
	}
	// Parse Input like 05,23,17
	for i := 0; i != len(input); i++ {
		if strings.Contains(input[i], ",") {
			result.parseIRange(input[i], i)
		}
	}
	// Parse input like */05
	for i := 0; i != len(input); i++ {
		if strings.Contains(input[i], "*/") {
			result.parsePeriodic(input[i], i)
		}
	}
	// Parse input like *
	for i := 0; i != len(input); i++ {
		if input[i] == "*" {
			result.parseIgnore(i)
		}
	}
	//Parse single Numbers (05 or 23)
	for i := 0; i != len(input); i++ {
		if !strings.ContainsAny(input[i], "-*/,") {
			tempary := make([]int, 1)
			temp, err := strconv.ParseInt(input[i], 10, 0)
			tempary[0] = int(temp)
			if err != nil {
				panic(err)
			}
			switch i {
			case 0:
				result.second = tempary
			case 1:
				result.minute = tempary
			case 2:
				result.hour = tempary
			case 3:
				result.dow = tempary
			case 4:
				result.dom = tempary
			case 5:
				result.month = tempary
			}
		}
	}
	// Do a sanity check, eg. there is no 32th Day in any Month
	result.checkValues()

	// Makes timestamp generation easier
	sort.Ints(result.second)
	sort.Ints(result.minute)
	sort.Ints(result.hour)
	sort.Ints(result.dow)
	sort.Ints(result.dom)
	sort.Ints(result.month)

	return &result
}
553237
func (v *View) parseInput(ch rune) []cell {
	cells := []cell{}

	isEscape, err := v.ei.parseOne(ch)
	if err != nil {
		for _, r := range v.ei.runes() {
			c := cell{
				fgColor: v.FgColor,
				bgColor: v.BgColor,
				chr:     r,
			}
			cells = append(cells, c)
		}
		v.ei.reset()
	} else {
		if isEscape {
			return nil
		}
		c := cell{
			fgColor: v.ei.curFgColor,
			bgColor: v.ei.curBgColor,
			chr:     ch,
		}
		cells = append(cells, c)
	}

	return cells
}
58458
func ParseIDMap(mapSpec []string, mapSetting string) (idmap []IDMap, err error) {
	stdErr := fmt.Errorf("error initializing ID mappings: %s setting is malformed", mapSetting)
	for _, idMapSpec := range mapSpec {
		idSpec := strings.Fields(strings.Map(nonDigitsToWhitespace, idMapSpec))
		if len(idSpec)%3 != 0 {
			return nil, stdErr
		}
		for i := range idSpec {
			if i%3 != 0 {
				continue
			}
			cid, hid, size, err := parseTriple(idSpec[i : i+3])
			if err != nil {
				return nil, stdErr
			}
			// Avoid possible integer overflow on 32bit builds
			if bits.UintSize == 32 && (cid > math.MaxInt32 || hid > math.MaxInt32 || size > math.MaxInt32) {
				return nil, stdErr
			}
			mapping := IDMap{
				ContainerID: int(cid),
				HostID:      int(hid),
				Size:        int(size),
			}
			idmap = append(idmap, mapping)
		}
	}
	return idmap, nil
}
231833
func ParseIPAddress(input string) string {
	host, _ := SplitHostPort(input)

	ip := net.ParseIP(host)

	if ip == nil {
		return host
	}

	if ip.IsLoopback() {
		return "127.0.0.1"
	}

	return ip.String()
}
1037171
func ParseIOStat(r io.Reader) (map[string]DeviceUtilizationReport, error) {
	scanner := bufio.NewScanner(r)
	var err error
	var fields []string
	reports := make(map[string]DeviceUtilizationReport, 0)
	passedSysInfo := false
	for scanner.Scan() {
		line := strings.TrimSpace(scanner.Text())
		// iostat might print out some system info and some spaces
		if !passedSysInfo {
			if strings.HasPrefix(strings.TrimSpace(line), "Device") {
				passedSysInfo = true
				fields = strings.Fields(line)
			}
			continue
		}
		metrics := strings.Fields(line)
		report := DeviceUtilizationReport{}

		// In some cases, we may have an extra newline at the end of a report,
		// in which case the metrics len will be 0 and we need to return
		if len(metrics) == 0 {
			return reports, nil
		}

		for index, field := range fields {
			switch field {
			case "Device:":
				report.Device = metrics[index]
			case "tps":
				report.TPS, err = strconv.ParseFloat(metrics[index], 64)
			case "Blk_read/s":
				report.BlkReadPS, err = strconv.ParseFloat(metrics[index], 64)
			case "Blk_wrtn/s":
				report.BlkWrtnPS, err = strconv.ParseFloat(metrics[index], 64)
			case "Blk_read":
				report.BlkRead, err = strconv.ParseFloat(metrics[index], 64)
			case "Blk_wrtn":
				report.BlkWrtn, err = strconv.ParseFloat(metrics[index], 64)
			case "kB_read/s":
				report.KBReadPS, err = strconv.ParseFloat(metrics[index], 64)
			case "kB_wrtn/s":
				report.KBWrtnPS, err = strconv.ParseFloat(metrics[index], 64)
			case "kB_read":
				report.KBRead, err = strconv.ParseFloat(metrics[index], 64)
			case "kB_wrtn":
				report.KBWrtn, err = strconv.ParseFloat(metrics[index], 64)
			case "MB_read/s":
				report.MBReadPS, err = strconv.ParseFloat(metrics[index], 64)
			case "MB_wrtn/s":
				report.MBWrtnPS, err = strconv.ParseFloat(metrics[index], 64)
			case "MB_read":
				report.MBRead, err = strconv.ParseFloat(metrics[index], 64)
			case "MB_wrtn":
				report.MBWrtn, err = strconv.ParseFloat(metrics[index], 64)
			case "rrqm/s":
				report.RRQMPS, err = strconv.ParseFloat(metrics[index], 64)
			case "wrqm/s":
				report.WRQMPS, err = strconv.ParseFloat(metrics[index], 64)
			case "r/s":
				report.RPS, err = strconv.ParseFloat(metrics[index], 64)
			case "w/s":
				report.WPS, err = strconv.ParseFloat(metrics[index], 64)
			case "rsec/s":
				report.RSecPS, err = strconv.ParseFloat(metrics[index], 64)
			case "wsec/s":
				report.WSecPS, err = strconv.ParseFloat(metrics[index], 64)
			case "rkB/s":
				report.RKBPS, err = strconv.ParseFloat(metrics[index], 64)
			case "wkB/s":
				report.WKBPS, err = strconv.ParseFloat(metrics[index], 64)
			case "rMB/s":
				report.RMBPS, err = strconv.ParseFloat(metrics[index], 64)
			case "wMB/s":
				report.WMBPS, err = strconv.ParseFloat(metrics[index], 64)
			case "avgrq-sz":
				report.AvgRqSz, err = strconv.ParseFloat(metrics[index], 64)
			case "avgqu-sz":
				report.AvgQuSz, err = strconv.ParseFloat(metrics[index], 64)
			case "%util":
				report.PctUtil, err = strconv.ParseFloat(metrics[index], 64)
			case "await":
				report.Await, err = strconv.ParseFloat(metrics[index], 64)
			}
			if err != nil {
				return nil, err
			}
		}
		reports[report.Device] = report
	}
	return reports, nil
}
399752
func parseIPVSStats(file io.Reader) (IPVSStats, error) {
	var (
		statContent []byte
		statLines   []string
		statFields  []string
		stats       IPVSStats
	)

	statContent, err := ioutil.ReadAll(file)
	if err != nil {
		return IPVSStats{}, err
	}

	statLines = strings.SplitN(string(statContent), "\n", 4)
	if len(statLines) != 4 {
		return IPVSStats{}, errors.New("ip_vs_stats corrupt: too short")
	}

	statFields = strings.Fields(statLines[2])
	if len(statFields) != 5 {
		return IPVSStats{}, errors.New("ip_vs_stats corrupt: unexpected number of fields")
	}

	stats.Connections, err = strconv.ParseUint(statFields[0], 16, 64)
	if err != nil {
		return IPVSStats{}, err
	}
	stats.IncomingPackets, err = strconv.ParseUint(statFields[1], 16, 64)
	if err != nil {
		return IPVSStats{}, err
	}
	stats.OutgoingPackets, err = strconv.ParseUint(statFields[2], 16, 64)
	if err != nil {
		return IPVSStats{}, err
	}
	stats.IncomingBytes, err = strconv.ParseUint(statFields[3], 16, 64)
	if err != nil {
		return IPVSStats{}, err
	}
	stats.OutgoingBytes, err = strconv.ParseUint(statFields[4], 16, 64)
	if err != nil {
		return IPVSStats{}, err
	}

	return stats, nil
}
702968
func parseImport(t *Tree, start Pos) (Node, error) {
	name, err := t.parseExpr()
	if err != nil {
		return nil, err
	}
	_, err = t.expectValue(tokenName, "as")
	if err != nil {
		return nil, err
	}
	tok, err := t.expect(tokenName)
	if err != nil {
		return nil, err
	}
	_, err = t.expect(tokenTagClose)
	if err != nil {
		return nil, err
	}
	return NewImportNode(name, tok.value, start), nil
}