當前位置: 首頁>>代碼示例>>Python>>正文


Python types.LongType方法代碼示例

本文整理匯總了Python中types.LongType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.LongType方法的具體用法?Python types.LongType怎麽用?Python types.LongType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在types的用法示例。


在下文中一共展示了types.LongType方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __getitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def __getitem__(self, key):
        """Called to implement evaluation of self[key].

        >>> ip=IP('127.0.0.0/30')
        >>> for x in ip:
        ...  print hex(x.int())
        ...
        0x7F000000L
        0x7F000001L
        0x7F000002L
        0x7F000003L
        >>> hex(ip[2].int())
        '0x7F000002L'
        >>> hex(ip[-1].int())
        '0x7F000003L'
        """

        if not isinstance(key, types.IntType) and not isinstance(key, types.LongType):
            raise TypeError
        if abs(key) >= self.len():
            raise IndexError
        if key < 0:
            key = self.len() - abs(key)

        return self.ip + long(key) 
開發者ID:Yukinoshita47,項目名稱:Yuki-Chan-The-Auto-Pentest,代碼行數:27,代碼來源:IPy.py

示例2: addTrace

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def addTrace(self, proc):
        """
        Add a new tracer to this group the "proc" argument
        may be either an long() for a pid (which we will attach
        to) or an already attached (and broken) tracer object.
        """

        if (type(proc) == types.IntType or
            type(proc) == types.LongType):
            trace = getTrace()
            self.initTrace(trace)
            self.traces[proc] = trace
            try:
                trace.attach(proc)
            except:
                self.delTrace(proc)
                raise

        else: # Hopefully a tracer object... if not.. you're dumb.
            trace = proc
            self.initTrace(trace)
            self.traces[trace.getPid()] = trace

        return trace 
開發者ID:joxeankoret,項目名稱:nightmare,代碼行數:26,代碼來源:__init__.py

示例3: to64

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def to64(number):
    """Converts a number in the range of 0 to 63 into base 64 digit
    character in the range of '0'-'9', 'A'-'Z', 'a'-'z','-','_'.
    """

    if not (type(number) is types.LongType or type(number) is types.IntType):
        raise TypeError("You must pass a long or an int")

    if 0 <= number <= 9:            #00-09 translates to '0' - '9'
        return byte(number + 48)

    if 10 <= number <= 35:
        return byte(number + 55)     #10-35 translates to 'A' - 'Z'

    if 36 <= number <= 61:
        return byte(number + 61)     #36-61 translates to 'a' - 'z'

    if number == 62:                # 62   translates to '-' (minus)
        return byte(45)

    if number == 63:                # 63   translates to '_' (underscore)
        return byte(95)

    raise ValueError('Invalid Base64 value: %i' % number) 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:26,代碼來源:_version200.py

示例4: from64

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def from64(number):
    """Converts an ordinal character value in the range of
    0-9,A-Z,a-z,-,_ to a number in the range of 0-63.
    """

    if not (type(number) is types.LongType or type(number) is types.IntType):
        raise TypeError("You must pass a long or an int")

    if 48 <= number <= 57:         #ord('0') - ord('9') translates to 0-9
        return(number - 48)

    if 65 <= number <= 90:         #ord('A') - ord('Z') translates to 10-35
        return(number - 55)

    if 97 <= number <= 122:        #ord('a') - ord('z') translates to 36-61
        return(number - 61)

    if number == 45:               #ord('-') translates to 62
        return(62)

    if number == 95:               #ord('_') translates to 63
        return(63)

    raise ValueError('Invalid Base64 value: %i' % number) 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:26,代碼來源:_version200.py

示例5: encrypt_int

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def encrypt_int(message, ekey, n):
    """Encrypts a message using encryption key 'ekey', working modulo n"""

    if type(message) is types.IntType:
        message = long(message)

    if not type(message) is types.LongType:
        raise TypeError("You must pass a long or int")

    if message < 0 or message > n:
        raise OverflowError("The message is too long")

    #Note: Bit exponents start at zero (bit counts start at 1) this is correct
    safebit = bit_size(n) - 2                   #compute safe bit (MSB - 1)
    message += (1 << safebit)                   #add safebit to ensure folding

    return pow(message, ekey, n) 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:19,代碼來源:_version200.py

示例6: int2bytes

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def int2bytes(number):
    """Converts a number to a string of bytes
    
    >>> bytes2int(int2bytes(123456789))
    123456789
    """

    if not (type(number) is types.LongType or type(number) is types.IntType):
        raise TypeError("You must pass a long or an int")

    string = ""

    while number > 0:
        string = "%s%s" % (byte(number & 0xFF), string)
        number /= 256
    
    return string 
開發者ID:deadblue,項目名稱:baidupan_shell,代碼行數:19,代碼來源:_version133.py

示例7: new_looper

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def new_looper(a, arg=None):
    """Helper function for nest()
    determines what sort of looper to make given a's type"""
    if isinstance(a,types.TupleType):
        if len(a) == 2:
            return RangeLooper(a[0],a[1])
        elif len(a) == 3:
            return RangeLooper(a[0],a[1],a[2])
    elif isinstance(a, types.BooleanType):
        return BooleanLooper(a)
    elif isinstance(a,types.IntType) or isinstance(a, types.LongType):
        return RangeLooper(a)
    elif isinstance(a, types.StringType) or isinstance(a, types.ListType):
        return ListLooper(a)
    elif isinstance(a, Looper):
        return a
    elif isinstance(a, types.LambdaType):
        return CalcField(a, arg) 
開發者ID:ActiveState,項目名稱:code,代碼行數:20,代碼來源:recipe-473818.py

示例8: __getitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def __getitem__(self, key):
        """Called to implement evaluation of self[key].
        
        >>> ip=IP('127.0.0.0/30')
        >>> for x in ip:
        ...  print hex(x.int())
        ...
        0x7F000000L
        0x7F000001L
        0x7F000002L
        0x7F000003L
        >>> hex(ip[2].int())
        '0x7F000002L'
        >>> hex(ip[-1].int())
        '0x7F000003L'
        """

        if type(key) != types.IntType and type(key) != types.LongType:
            raise TypeError
        if abs(key) >= self.len():
            raise IndexError
        if key < 0:
            key = self.len() - abs(key)

        return self.ip + long(key) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:27,代碼來源:IPy.py

示例9: realEncode

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def realEncode(self, data):
        """Convert number to string.
        If no formatString was specified in class constructor data type is
        dynamically determined and converted using a default formatString of
        "%d", "%f", or "%d" for Int, Float, and Long respectively.
        """

        if self._formatString is None:
            retType = type(data)
            if retType is IntType:
                return "%d" % data
            elif retType is FloatType:
                return "%f" % data
            elif retType is LongType:
                return "%d" % data
            else:
                return data

        return self._formatString % data 
開發者ID:MozillaSecurity,項目名稱:peach,代碼行數:21,代碼來源:NumberToString.py

示例10: init_info

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def init_info(self):
        scalar_converter.init_info(self)
        # !! long to int conversion isn't safe!
        self.type_name = 'long'
        self.check_func = 'PyLong_Check'
        self.c_type = 'longlong'
        self.return_type = 'longlong'
        self.to_c_return = "(longlong) PyLong_AsLongLong(py_obj)"
        self.matching_types = [types.LongType] 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:11,代碼來源:c_spec.py

示例11: long2str

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def long2str(l):
    """Convert an integer to a string."""
    if type(l) not in (types.IntType, types.LongType):
        raise ValueError, 'the input must be an integer'

    if l < 0:
        raise ValueError, 'the input must be greater than 0'
    s = ''
    while l:
        s = s + chr(l & 255L)
        l >>= 8

    return s 
開發者ID:DroidTest,項目名稱:TimeMachine,代碼行數:15,代碼來源:androconf.py

示例12: int2bytes

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def int2bytes(number):
    """Converts a number to a string of bytes
    """

    if not (type(number) is types.LongType or type(number) is types.IntType):
        raise TypeError("You must pass a long or an int")

    string = ""

    while number > 0:
        string = "%s%s" % (byte(number & 0xFF), string)
        number /= 256
    
    return string 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:16,代碼來源:_version133.py

示例13: encrypt_int

# 需要導入模塊: import types [as 別名]
# 或者: from types import LongType [as 別名]
def encrypt_int(message, ekey, n):
    """Encrypts a message using encryption key 'ekey', working modulo
    n"""

    if type(message) is types.IntType:
        return encrypt_int(long(message), ekey, n)

    if not type(message) is types.LongType:
        raise TypeError("You must pass a long or an int")

    if message > 0 and \
            math.floor(math.log(message, 2)) > math.floor(math.log(n, 2)):
        raise OverflowError("The message is too long")

    return fast_exponentiation(message, ekey, n) 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:17,代碼來源:_version133.py


注:本文中的types.LongType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。