Python string.atoi() Examples

The following are 30 code examples for showing how to use string.atoi(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module string , or try the search function .

Example 1
Project: meddle   Author: glmcdona   File: version.py    License: MIT License 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 2
Project: ironpython2   Author: IronLanguages   File: version.py    License: Apache License 2.0 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 3
Project: BinderFilter   Author: dxwu   File: version.py    License: MIT License 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 4
Project: Computable   Author: ktraunmueller   File: version.py    License: MIT License 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 5
Project: oss-ftp   Author: aliyun   File: version.py    License: MIT License 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 6
Project: pycopia   Author: kdart   File: NPS.py    License: Apache License 2.0 6 votes vote down vote up
def _parsestats(self, rawstats):
        plug_re = re.compile("^[0-9]")
        lines = string.split(rawstats, "\n")
        for line in lines:
            line = string.strip(line)
            if plug_re.match(line):
                parts = string.split(line, "|")
                number = string.atoi(string.strip(parts[0]))
                name = string.strip(parts[1])
                status = string.strip(parts[2])
                bootdelay = string.atoi(string.strip(string.split(parts[3])[0]))
                password = string.strip(parts[4])
                if password == "(none)":
                    password = None
                defaultstate = string.strip(parts[5])
                self.plugs[number] = NPSPlug(number, name, status, bootdelay, password, defaultstate)
            elif line[:10] == "Disconnect":
                self.timeout = string.atoi(string.strip(string.split(line)[2]))*60 
Example 7
Project: ARK   Author: baidu   File: persistence.py    License: MIT License 6 votes vote down vote up
def __init__(self):
        """
        初始化方法
        """
        import string
        import threading
        if FilePersistence._init:
            return

        self._lock = threading.Lock()
        self._inspect_results = {}
        self._ob_paths = {}  # 需要观察路径下节点变化的路径列表
        self._touch_paths = {}  # 针对临时节点,需要不断touch的路径列表
        self._base = config.GuardianConfig.get(config.STATE_SERVICE_HOSTS_NAME)
        self._mode = string.atoi(config.GuardianConfig.get("PERSIST_FILE_MODE", FilePersistence._file_mode), 8)
        self._interval = string.atof(config.GuardianConfig.get("PERSIST_FILE_INTERVAL", "0.4"))
        self._timeout = string.atof(config.GuardianConfig.get("PERSIST_FILE_TIMEOUT", "3"))
        if not os.path.exists(self._base):
            os.makedirs(self._base, self._mode)

        self._session_thread = threading.Thread(target=self._thread_run)
        FilePersistence._init = True
        self._session_thread.daemon = True
        self._session_thread.start() 
Example 8
Project: You-are-Pythonista   Author: MiracleYoung   File: collect_system_info.py    License: GNU General Public License v3.0 6 votes vote down vote up
def collect_memory_info():
    '''
    系统内存信息收集
    '''
    memory_buffer = {}
    # 读取内存信息,并生成字典
    with open("/proc/meminfo") as mem_file:
        for line in mem_file:
            # line:
            # 'MemTotal:       16456100 kB'
            # 过滤出所要信息
            memory_buffer[line.split(':')[0]] = string.atoi(line.split(':')[1].split()[0])
    mem_total = memory_buffer["MemTotal"]
    mem_free = memory_buffer["MemFree"] + memory_buffer["Buffers"] + memory_buffer["Cached"]
    mem_cache = memory_buffer["Cached"]
    mem_info = {
        "mem_total": mem_total,
        "mem_free": mem_free,
        "mem_cache": mem_cache
    }
    return mem_info 
Example 9
Project: AppiumTestProject   Author: gitjayzhen   File: PerformanceCtrl.py    License: Apache License 2.0 6 votes vote down vote up
def  __init__(self,sno,times,pkg_name):
        # 打开待测应用,运行脚本,默认times为30次(可自己手动修改次数),获取该应用cpu、memory占用率的曲线图,图表保存至chart目录下
        self.utils = AdbCmder()
        self.sno = sno
        if times is None or time == "":
            self.times = 30        #top次数
        else:
            self.times = string.atoi(times)
            if self.times < 15 and self.times > 0:
                self.times = 20
        if pkg_name is None or pkg_name == "":
            self.pak_name = self.utils.get_current_package_name(sno)
        else:
            self.pkg_name = pkg_name          # 设备当前运行应用的包名

    # 获取cpu、mem占用 
Example 10
Project: datafari   Author: francelabs   File: version.py    License: Apache License 2.0 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 11
Project: Splunking-Crime   Author: nccgroup   File: version.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 12
Project: stdm   Author: gltn   File: para.py    License: GNU General Public License v2.0 6 votes vote down vote up
def getOp(self, tuple, engine):
        from reportlab.lib.sequencer import getSequencer
        import math
        globalsequencer = getSequencer()
        attr = self.attdict
        try:
            id = attr['id']
        except KeyError:
            id = None
        try:
            base = math.atoi(attr['base'])
        except:
            base=0
        globalsequencer.reset(id, base)
        self.op = ""
        return "" 
Example 13
Project: python-for-android   Author: kuri65536   File: birthdaySample.py    License: Apache License 2.0 6 votes vote down vote up
def _PromptForSpreadsheet(self):
    """ Prompts user to select spreadsheet.
     
        Gets and displays titles of all spreadsheets for user to 
        select. Generic function taken from spreadsheetsExample.py.

        Args:
          none

        Returns:
           spreadsheet ID that the user selected: string
    """

    feed = self.s_client.GetSpreadsheetsFeed()
    self._PrintFeed(feed)
    input = raw_input('\nSelection: ')
    
    # extract and return the spreadsheet ID
    return feed.entry[string.atoi(input)].id.text.rsplit('/', 1)[1] 
Example 14
Project: medicare-demo   Author: ofermend   File: version.py    License: Apache License 2.0 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 15
Project: darkc0de-old-stuff   Author: tuwid   File: syscalls.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, mmemory, typeaccess=0) :
		if not isinstance(mmemory, Memory):
			raise TypeError("ERREUR")

		self.mmemory = mmemory
		self.mmemory.open("r", typeaccess)

		try :
			fichier = open("/usr/include/asm/unistd.h", "r")
		except IOError :
			print "No such file /usr/include/asm/unistd.h"
			sys.exit(-1)
			
		liste = fichier.readlines()
		fichier.close()
		count = 0
		for i in liste :
			if(re.match("#define __NR_", i)) :
				l = string.split(i)
				if(l[2][0].isdigit()) :
					count = string.atoi(l[2], 10)
					self.lists_syscalls.append([count, l[1][5:]])
				else :
					count = count + 1
					self.lists_syscalls.append([count, l[1][5:]]) 
Example 16
Project: pentestly   Author: praetorian-code   File: netblock.py    License: GNU General Public License v3.0 6 votes vote down vote up
def strtoip(ipstr):
	"""convert an IP address in string form to numeric."""
	res = 0L
	count = 0
	n = string.split(ipstr, '.')
	for i in n:
		res = res << 8L
		ot = string.atoi(i)
		if ot < 0 or ot > 255:
			raise ValueError, "invalid IP octet"
		res = res + ot
		count = count + 1
	# could be incomplete (short); make it complete.
	while count < 4:
		res = res << 8L
		count = count + 1
	return res 
Example 17
Project: pentestly   Author: praetorian-code   File: netblock.py    License: GNU General Public License v3.0 6 votes vote down vote up
def cidrstrerr(str):
	"""Check an IP address or CIDR netblock for validity.

	Returns None if it is and otherwise an error string."""
	if not cvalid.match(str):
		return 'Not a syntatically valid IP address or netblock'
	rng = 32
	pos = string.find(str, '/')
	ips = str
	if not pos == -1:
		rng = string.atoi(ips[pos+1:])
		ips = str[:pos]
	if rng < 0 or rng > 32:
		return 'CIDR length out of range'
	n = string.split(ips, '.')
	for i in n:
		ip = string.atoi(i)
		if (ip < 0 or ip > 255):
			return 'an IP octet is out of range'
	# could check to see if it is 'proper', but.
	return None 
Example 18
Project: CTFCrackTools-V2   Author: Acmesec   File: version.py    License: GNU General Public License v3.0 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 19
Project: CTFCrackTools-V2   Author: Acmesec   File: version.py    License: GNU General Public License v3.0 6 votes vote down vote up
def parse (self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError, "invalid version number '%s'" % vstring

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(string.atoi, [major, minor, patch]))
        else:
            self.version = tuple(map(string.atoi, [major, minor]) + [0])

        if prerelease:
            self.prerelease = (prerelease[0], string.atoi(prerelease_num))
        else:
            self.prerelease = None 
Example 20
Project: recon-ng   Author: methos2016   File: netblock.py    License: GNU General Public License v3.0 6 votes vote down vote up
def strtoip(ipstr):
	"""convert an IP address in string form to numeric."""
	res = 0L
	count = 0
	n = string.split(ipstr, '.')
	for i in n:
		res = res << 8L
		ot = string.atoi(i)
		if ot < 0 or ot > 255:
			raise ValueError, "invalid IP octet"
		res = res + ot
		count = count + 1
	# could be incomplete (short); make it complete.
	while count < 4:
		res = res << 8L
		count = count + 1
	return res 
Example 21
Project: recon-ng   Author: methos2016   File: netblock.py    License: GNU General Public License v3.0 6 votes vote down vote up
def cidrstrerr(str):
	"""Check an IP address or CIDR netblock for validity.

	Returns None if it is and otherwise an error string."""
	if not cvalid.match(str):
		return 'Not a syntatically valid IP address or netblock'
	rng = 32
	pos = string.find(str, '/')
	ips = str
	if not pos == -1:
		rng = string.atoi(ips[pos+1:])
		ips = str[:pos]
	if rng < 0 or rng > 32:
		return 'CIDR length out of range'
	n = string.split(ips, '.')
	for i in n:
		ip = string.atoi(i)
		if (ip < 0 or ip > 255):
			return 'an IP octet is out of range'
	# could check to see if it is 'proper', but.
	return None 
Example 22
Project: EasY_HaCk   Author: sabri-zaki   File: netblock.py    License: Apache License 2.0 6 votes vote down vote up
def strtoip(ipstr):
	"""convert an IP address in string form to numeric."""
	res = 0L
	count = 0
	n = string.split(ipstr, '.')
	for i in n:
		res = res << 8L
		ot = string.atoi(i)
		if ot < 0 or ot > 255:
			raise ValueError, "invalid IP octet"
		res = res + ot
		count = count + 1
	# could be incomplete (short); make it complete.
	while count < 4:
		res = res << 8L
		count = count + 1
	return res 
Example 23
Project: EasY_HaCk   Author: sabri-zaki   File: netblock.py    License: Apache License 2.0 6 votes vote down vote up
def cidrstrerr(str):
	"""Check an IP address or CIDR netblock for validity.

	Returns None if it is and otherwise an error string."""
	if not cvalid.match(str):
		return 'Not a syntatically valid IP address or netblock'
	rng = 32
	pos = string.find(str, '/')
	ips = str
	if not pos == -1:
		rng = string.atoi(ips[pos+1:])
		ips = str[:pos]
	if rng < 0 or rng > 32:
		return 'CIDR length out of range'
	n = string.split(ips, '.')
	for i in n:
		ip = string.atoi(i)
		if (ip < 0 or ip > 255):
			return 'an IP octet is out of range'
	# could check to see if it is 'proper', but.
	return None 
Example 24
Project: razzy-spinner   Author: rafasashi   File: wordnet.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, pos, offset, line):
        "Initialize the synset from a line off a WN synset file."
	self.pos = pos
        "part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB."
	self.offset = offset
        """integer offset into the part-of-speech file.  Together
        with pos, this can be used as a unique id."""
	tokens = string.split(line[:string.index(line, '|')])
	self.ssType = tokens[2]
	self.gloss = string.strip(line[string.index(line, '|') + 1:])
        self.lexname = Lexname.lexnames[int(tokens[1])]
	(self._senseTuples, remainder) = _partition(tokens[4:], 2, string.atoi(tokens[3], 16))
	(self._pointerTuples, remainder) = _partition(remainder[1:], 4, int(remainder[0]))
	if pos == VERB:
	    (vfTuples, remainder) = _partition(remainder[1:], 3, int(remainder[0]))
	    def extractVerbFrames(index, vfTuples):
		return tuple(map(lambda t:string.atoi(t[1]), filter(lambda t,i=index:string.atoi(t[2],16) in (0, i), vfTuples)))
	    senseVerbFrames = []
	    for index in range(1, len(self._senseTuples) + 1):
		senseVerbFrames.append(extractVerbFrames(index, vfTuples))
	    self._senseVerbFrames = senseVerbFrames
	    self.verbFrames = tuple(extractVerbFrames(None, vfTuples))
            """A sequence of integers that index into
            VERB_FRAME_STRINGS. These list the verb frames that any
            Sense in this synset participates in.  (See also
            Sense.verbFrames.) Defined only for verbs.""" 
Example 25
Project: razzy-spinner   Author: rafasashi   File: wordnet.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, sourceOffset, pointerTuple):
	(type, offset, pos, indices) = pointerTuple
	self.type = Pointer._POINTER_TYPE_TABLE[type]
        """One of POINTER_TYPES."""
	self.sourceOffset = sourceOffset
	self.targetOffset = int(offset)
	self.pos = _normalizePOS(pos)
        """part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB"""
	indices = string.atoi(indices, 16)
	self.sourceIndex = indices >> 8
	self.targetIndex = indices & 255 
Example 26
Project: razzy-spinner   Author: rafasashi   File: __init__.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _wildcards(self, response, match):
        pos = string.find(response,'%')
        while pos >= 0:
            num = string.atoi(response[pos+1:pos+2])
            response = response[:pos] + \
                self._substitute(match.group(num)) + \
                response[pos+2:]
            pos = string.find(response,'%')
        return response 
Example 27
Project: razzy-spinner   Author: rafasashi   File: wordnet.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, pos, offset, line):
        "Initialize the synset from a line off a WN synset file."
	self.pos = pos
        "part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB."
	self.offset = offset
        """integer offset into the part-of-speech file.  Together
        with pos, this can be used as a unique id."""
	tokens = string.split(line[:string.index(line, '|')])
	self.ssType = tokens[2]
	self.gloss = string.strip(line[string.index(line, '|') + 1:])
        self.lexname = Lexname.lexnames[int(tokens[1])]
	(self._senseTuples, remainder) = _partition(tokens[4:], 2, string.atoi(tokens[3], 16))
	(self._pointerTuples, remainder) = _partition(remainder[1:], 4, int(remainder[0]))
	if pos == VERB:
	    (vfTuples, remainder) = _partition(remainder[1:], 3, int(remainder[0]))
	    def extractVerbFrames(index, vfTuples):
		return tuple(map(lambda t:string.atoi(t[1]), filter(lambda t,i=index:string.atoi(t[2],16) in (0, i), vfTuples)))
	    senseVerbFrames = []
	    for index in range(1, len(self._senseTuples) + 1):
		senseVerbFrames.append(extractVerbFrames(index, vfTuples))
	    self._senseVerbFrames = senseVerbFrames
	    self.verbFrames = tuple(extractVerbFrames(None, vfTuples))
            """A sequence of integers that index into
            VERB_FRAME_STRINGS. These list the verb frames that any
            Sense in this synset participates in.  (See also
            Sense.verbFrames.) Defined only for verbs.""" 
Example 28
Project: razzy-spinner   Author: rafasashi   File: wordnet.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, sourceOffset, pointerTuple):
	(type, offset, pos, indices) = pointerTuple
	self.type = Pointer._POINTER_TYPE_TABLE[type]
        """One of POINTER_TYPES."""
	self.sourceOffset = sourceOffset
	self.targetOffset = int(offset)
	self.pos = _normalizePOS(pos)
        """part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB"""
	indices = string.atoi(indices, 16)
	self.sourceIndex = indices >> 8
	self.targetIndex = indices & 255 
Example 29
Project: mishkal   Author: linuxscout   File: datetimeutil.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _number(val):
    try:
        return string.atoi(val)
    except:
        return None

#
# timedelta
# 
Example 30
Project: ironpython2   Author: IronLanguages   File: vssutil.py    License: Apache License 2.0 5 votes vote down vote up
def MakeNewBuildNo(project, buildDesc = None, auto=0, bRebrand = 0):
	if buildDesc is None: buildDesc = "Created by Python"
	ss = GetSS()
	i = ss.VSSItem(project)
	num = CountCheckouts(i)
	if num > 0:
		msg = "This project has %d items checked out\r\n\r\nDo you still want to continue?" % num
		import win32ui
		if win32ui.MessageBox(msg, project, win32con.MB_YESNO) != win32con.IDYES:
			return


	oldBuild = buildNo = GetLastBuildNo(project)
	if buildNo is None:
		buildNo = "1"
		oldBuild = "<None>"
	else:
		try:
			buildNo = string.atoi(buildNo)
			if not bRebrand: buildNo = buildNo + 1
			buildNo = str(buildNo)
		except ValueError:
			raise error("The previous label could not be incremented: %s" % (oldBuild))

	if not auto:
		from pywin.mfc import dialog
		buildNo = dialog.GetSimpleInput("Enter new build number", buildNo, "%s - Prev: %s" % (project, oldBuild))
		if buildNo is None: return
	i.Label(buildNo, "Build %s: %s" % (buildNo,buildDesc))
	if auto:
		print "Branded project %s with label %s" % (project, buildNo)
	return buildNo