python类atoi()的实例源码

ll2mh1.py 文件源码 项目:maidenhead 作者: tylert 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def main():

    if len(sys.argv) == 2:  # slob city
        stringlength = string.atoi(sys.argv[1])
        if stringlength < 2 or stringlength % 2 != 0:
            raise RuntimeError('String length requested must be even '
                               'integer > 0.')
    else:
        stringlength = 6

    while 1:
        line = sys.stdin.readline()
        if not line:
            break
        latlon = re.findall(r'([-0-9.]+)\s+([-0-9.]+)', line)

        if latlon:
            for leftval, rightval in latlon:
                lat = string.atof(leftval)
                lon = string.atof(rightval)
        else:
            raise RuntimeError('Cannot even get the basic items.')

        astring = maidenhead.mh1(lat, lon, stringlength)
        print('{0}'.format(astring))
ll2mh2.py 文件源码 项目:maidenhead 作者: tylert 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def main():

    if len(sys.argv) == 2:  # slob city
        stringlength = string.atoi(sys.argv[1])
        if stringlength < 2 or stringlength % 2 != 0:
            raise RuntimeError('String length requested must be even '
                               'integer > 0.')
    else:
        stringlength = 6

    while 1:
        line = sys.stdin.readline()
        if not line:
            break
        latlon = re.findall(r'([-0-9.]+)\s+([-0-9.]+)', line)

        if latlon:
            for leftval, rightval in latlon:
                lat = string.atof(leftval)
                lon = string.atof(rightval)
        else:
            raise RuntimeError('Cannot even get the basic items.')

        astring = maidenhead.mh2(lat, lon, stringlength)
        print('{0}'.format(astring))
caldav.py 文件源码 项目:gnuhealth-live 作者: kret0s 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def do_POST(self):
    dc = self.IFACE_CLASS

    uri = urlparse.urljoin(self.get_baseuri(dc), self.path)
    uri = urllib.unquote(uri)

    dbname, dburi = TrytonDAVInterface.get_dburi(uri)
    if dburi.startswith('Calendars'):
        # read the body
        body = None
        if 'Content-Length' in self.headers:
            l = self.headers['Content-Length']
            body = self.rfile.read(atoi(l))
        ct = None
        if 'Content-Type' in self.headers:
            ct = self.headers['Content-Type']

        try:
            DATA = '%s\n' % dc._get_caldav_post(uri, body, ct)
        except DAV_Error, exception:
            ec, _ = exception
            return self.send_status(ec)
        self.send_body(DATA, 200, 'OK', 'OK')
        return
    return _prev_do_POST(self)
netblock.py 文件源码 项目:recon-ng 作者: Hehe-Zhc 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
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
netblock.py 文件源码 项目:recon-ng 作者: Hehe-Zhc 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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
version.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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
__init__.py 文件源码 项目:autosub-bootstrapbill 作者: BenjV 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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
matrix_speaker.py 文件源码 项目:neo_matrix_python 作者: lrouter 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def getVolume(self):
        list = [0x3]
        list.append(self.__cmd_reqDict['Volume'])
        cmd = self.__makeCommand(list)

        length = self.__ser.write(cmd)
        time.sleep(0.3)
        if length != len(cmd):
            self.__logger.error('write %d - %d /dev/ttyS2 failed.', len, len(cmd))
            return False
        ack = self.__ser.read(self.__ackLen)
        if ack.find('OK') == -1:
            return False
        valueStr = '0x' + ack[2:]
        value = string.atoi(valueStr, 16)

        return value

        #######################################

    ##    get current play device
    ##    0:USB 2:SPI
    #######################################
matrix_speaker.py 文件源码 项目:neo_matrix_python 作者: lrouter 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def getPlayDev(self):
        list = [0x3]
        list.append(self.__cmd_reqDict['PlayDev'])
        cmd = self.__makeCommand(list)

        length = self.__ser.write(cmd)
        time.sleep(0.3)
        if length != len(cmd):
            self.__logger.error('write %d - %d /dev/ttyS2 failed.', len, len(cmd))
            return False
        ack = self.__ser.read(self.__ackLen)
        if ack.find('OK') == -1:
            return False
        valueStr = '0x' + ack[2:]
        value = string.atoi(valueStr, 16)

        return value

        #######################################

    ##    get current music index in Flash
    ##    1-255
    #######################################
matrix_speaker.py 文件源码 项目:neo_matrix_python 作者: lrouter 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def getMusicInFlash(self):
        list = [0x3]
        list.append(self.__cmd_reqDict['MusicInFlash'])
        cmd = self.__makeCommand(list)

        length = self.__ser.write(cmd)
        time.sleep(0.3)
        if length != len(cmd):
            self.__logger.error('write %d - %d /dev/ttyS2 failed.', len, len(cmd))
            return False
        ack = self.__ser.read(self.__ackLen)
        if ack.find('OK') == -1:
            return False
        valueStr = '0x' + ack[2:]
        value = string.atoi(valueStr, 16)

        return value
version.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
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
version.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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
hostlist.py 文件源码 项目:dreamr-botnet 作者: YinAndYangSecurityAwareness 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def encodeHostBlock(self, hostlist):
        result = ""
        try:
            i = 0
            while (i < 32):
                if (i == 0 or i > len(hostlist)):
                    address = "127.0.0.1"
                else:
                    address = hostlist[i-1]
                a,b,c,d = map(string.atoi, string.split(address, '.'))
                result += struct.pack("BBBB", a, b, c, d)
                i += 1
        except Exception as e:
            pass
        return result

    # Take a 128 byte host block and turns it back into an array
version.py 文件源码 项目:empyrion-python-api 作者: huhlig 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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
netblock.py 文件源码 项目:recon-ng 作者: captainhooligan 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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
netblock.py 文件源码 项目:recon-ng 作者: captainhooligan 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
version.py 文件源码 项目:Docker-XX-Net 作者: kuanghy 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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
io.py 文件源码 项目:BigBrotherBot-For-UrT43 作者: ptitbigorneau 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def quickload(fname,linestocut=4):
    """
Quickly loads in a long text file, chopping off first n 'linestocut'.

Usage:   quickload(fname,linestocut=4)
Returns: array filled with data in fname
"""
    f = open(fname,'r')
    d = f.readlines()
    f.close()
    print fname,'read in.'
    d = d[linestocut:]
    d = map(string.split,d)
    print 'Done with string.split on lines.'
    for i in range(len(d)):
        d[i] = map(string.atoi,d[i])
    print 'Conversion to ints done.'
    return N.array(d)
PCGIServer.py 文件源码 项目:ZServer 作者: zopefoundation 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def read_info(self, info_file):
        "read configuration information from a PCGI info file"
        lines = open(info_file).readlines()
        directives = {}
        try:
            for line in lines:
                line = string.strip(line)
                if not len(line) or line[0] == '#':
                    continue
                k, v = string.split(line, '=', 1)
                directives[string.strip(k)] = string.strip(v)
        except Exception:
            raise ParseError('Error parsing PCGI info file')

        self.pid_file = directives.get('PCGI_PID_FILE', None)
        self.socket_file = directives.get('PCGI_SOCKET_FILE', None)
        if 'PCGI_PORT' in directives:
            self.port = string.atoi(directives['PCGI_PORT'])
        if 'PCGI_MODULE' in directives:
            self.module = directives['PCGI_MODULE']
        elif 'PCGI_MODULE_PATH' in directives:
            path = directives['PCGI_MODULE_PATH']
            path, module = os.path.split(path)
            module, ext = os.path.splitext(module)
            self.module = module
http_date.py 文件源码 项目:ZServer 作者: zopefoundation 项目源码 文件源码 阅读 53 收藏 0 点赞 0 评论 0
def unpack_rfc850(m):
    g = m.group
    a = string.atoi
    return (a(g(4)),        # year
            monmap[g(3)],   # month
            a(g(2)),        # day
            a(g(5)),        # hour
            a(g(6)),        # minute
            a(g(7)),        # second
            0,
            0,
            0
            )


# parsdate.parsedate    - ~700/sec.
# parse_http_date       - ~1333/sec.


问题


面经


文章

微信
公众号

扫码关注公众号