本文整理匯總了Python中sys.maxint方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.maxint方法的具體用法?Python sys.maxint怎麽用?Python sys.maxint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sys
的用法示例。
在下文中一共展示了sys.maxint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _auto_ssl_context
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def _auto_ssl_context():
import OpenSSL, time, random
pkey = OpenSSL.crypto.PKey()
pkey.generate_key(OpenSSL.crypto.TYPE_RSA, 768)
cert = OpenSSL.crypto.X509()
cert.set_serial_number(random.randint(0, sys.maxint))
cert.gmtime_adj_notBefore(0)
cert.gmtime_adj_notAfter(60 * 60 * 24 * 365)
cert.get_subject().CN = '*'
cert.get_subject().O = 'Dummy Certificate'
cert.get_issuer().CN = 'Untrusted Authority'
cert.get_issuer().O = 'Self-Signed'
cert.set_pubkey(pkey)
cert.sign(pkey, 'md5')
ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.use_privatekey(pkey)
ctx.use_certificate(cert)
return ctx
示例2: rename
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def rename(src, dst):
# Try atomic or pseudo-atomic rename
if _rename(src, dst):
return
# Fall back to "move away and replace"
try:
os.rename(src, dst)
except OSError as e:
if e.errno != errno.EEXIST:
raise
old = "%s-%08x" % (dst, random.randint(0, sys.maxint))
os.rename(dst, old)
os.rename(src, dst)
try:
os.unlink(old)
except Exception:
pass
示例3: __init__
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def __init__(self):
buildstep.LogLineObserver.__init__(self)
# Counts of various reports.
self.num_reports = None
self.num_added = 0
self.num_removed = 0
self.num_changed = 0
# Reports to notify the user about; a list of tuples of (title,
# name, html-report).
self.reports = []
# Lines we couldn't parse.
self.invalid_lines = []
# Make sure we get all the data.
self.setMaxLineLength(sys.maxint)
示例4: distanceDomain
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def distanceDomain(domain, DomainDict, ccTldDict, tldDict):
similarDomain = ""
minDistance = sys.maxint
level = domain.split(".")
if len(level) <=1:
return ("not a domain", sys.maxint)
(domain2LD, domain3LD, domain2LDs, domain3LDs) = extractLevelDomain(domain, ccTldDict, tldDict)
for popularDomain in DomainDict:
distance = Levenshtein.distance(domain2LD.decode('utf-8'), popularDomain.decode('utf-8'))
if distance < minDistance:
minDistance = distance
similarDomain = popularDomain
#debug
#sys.stdout.write("subdomain: %s, similarDomain: %s, minDistance: %d\n" % (subdomain, similarDomain, minDistance))
if len(similarDomain) > 0:
return (similarDomain, minDistance/float(len(similarDomain)))
else:
return (domain2LD, 0)
# check whether a domain contains invalid TLD
示例5: threeSumClosest
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def threeSumClosest(A, B):
i , n = 0 , len(A)
A = sorted(A)
diff = sys.maxint
close_sum = 0
while i <= n-3:
j , k = i+1 , n-1
sum = A[i] + A[j] + A[k]
if sum == B:
return sum
if diff > abs(sum - B):
diff += abs(sum-B)
close_sum = sum
if sum < B:
j += 1
else:
k -= 1
i += 1
return close_sum
示例6: __init__
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def __init__(self, interface_dict, rpc_prefix):
mp_conf = {"use_bin_type":True}
super().__init__(
pack_params = {
"use_bin_type":True
},
# unpack_param = {
# 'raw' : True,
# 'max_buffer_size' : sys.maxint,
# 'max_str_len' : sys.maxint,
# 'max_bin_len' : sys.maxint,
# 'max_array_len' : sys.maxint,
# 'max_map_len' : sys.maxint,
# 'max_ext_len' : sys.maxint,
# },
)
self.log = logging.getLogger("Main.{}-Interface".format(rpc_prefix))
self.mdict = interface_dict
self.log.info("Connection")
示例7: base36_to_int
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def base36_to_int(s):
"""
Converts a base 36 string to an ``int``. Raises ``ValueError` if the
input won't fit into an int.
"""
# To prevent overconsumption of server resources, reject any
# base36 string that is long than 13 base36 digits (13 digits
# is sufficient to base36-encode any 64-bit integer)
if len(s) > 13:
raise ValueError("Base36 input too large")
value = int(s, 36)
# ... then do a final check that the value will fit into an int to avoid
# returning a long (#15067). The long type was removed in Python 3.
if six.PY2 and value > sys.maxint:
raise ValueError("Base36 input too large")
return value
示例8: int_to_base36
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def int_to_base36(i):
"""
Converts an integer to a base36 string
"""
char_set = '0123456789abcdefghijklmnopqrstuvwxyz'
if i < 0:
raise ValueError("Negative base36 conversion input.")
if six.PY2:
if not isinstance(i, six.integer_types):
raise TypeError("Non-integer base36 conversion input.")
if i > sys.maxint:
raise ValueError("Base36 conversion input too large.")
if i < 36:
return char_set[i]
b36 = ''
while i != 0:
i, n = divmod(i, 36)
b36 = char_set[n] + b36
return b36
示例9: _make_boundary
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def _make_boundary(text=None):
# Craft a random boundary. If text is given, ensure that the chosen
# boundary doesn't appear in the text.
token = random.randrange(sys.maxint)
boundary = ('=' * 15) + (_fmt % token) + '=='
if text is None:
return boundary
b = boundary
counter = 0
while True:
cre = re.compile('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
if not cre.search(text):
break
b = boundary + '.' + str(counter)
counter += 1
return b
示例10: read_data
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def read_data (self,setid,epoch,data):
# unknown template, ignore it !
if setid not in self.template:
return
extracted = {'epoch':epoch,'flows':1}
format = self.template[setid]
for what in format:
offset,size = format[what]
extracted[NAME[what]], = struct.unpack(CONVERT[(what,size)],data[offset:offset+size])
# # reports the data decoding rate per thread
# self.decoded +=1
# if not self.decoded % 1000:
# print "id %d decoded %ld flows" % (self.id,self.decoded)
# sys.stdout.flush()
# if self.decoded == sys.maxint:
# self.decoded = self.decoded % 1000
self.callback(extracted)
示例11: getLenStat
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def getLenStat(fileName, minLength=1000):
"""
Get basic statistics concerning the lengths of the sequence.
@param fileName: fasta file
@type fileName: str
"""
buf = ""
c = 0
bp = 0
minLen = sys.maxint
maxLen = 0
totalBp = 0
totalCount = 0
for k, l in fas.getSequenceToBpDict(fileName).iteritems():
totalCount += 1
totalBp += l
if l >= minLength:
c += 1
bp += l
if l < minLen:
minLen = l
elif l > maxLen:
maxLen = l
buf += 'Bigger than %sbp (sequences: %s, Mbp: %s)\n' % (minLength, c, round(float(bp) / 1000000.0, 3))
buf += 'Bigger than %sbp (min: %s, max %s, avg %s bp)\n' % (minLength, minLen, maxLen, round((float(bp) / c)))
buf += 'Total (sequences: %s, Mbp: %s)\n' % (totalCount, round(float(totalBp) / 1000000.0, 3))
return buf
示例12: fifo
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def fifo(dout, din, re, we, empty, full, clk, maxFilling=sys.maxint):
""" Synchronous fifo model based on a list.
Ports:
dout -- data out
din -- data in
re -- read enable
we -- write enable
empty -- empty indication flag
full -- full indication flag
clk -- clock input
Optional parameter:
maxFilling -- maximum fifo filling, "infinite" by default
"""
memory = []
@always(clk.posedge)
def access():
if we:
memory.insert(0, din.val)
if re:
dout.next = memory.pop()
filling = len(memory)
empty.next = (filling == 0)
full.next = (filling == maxFilling)
return access
示例13: fifo2
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def fifo2(dout, din, re, we, empty, full, clk, maxFilling=sys.maxint):
""" Synchronous fifo model based on a list.
Ports:
dout -- data out
din -- data in
re -- read enable
we -- write enable
empty -- empty indication flag
full -- full indication flag
clk -- clock input
Optional parameter:
maxFilling -- maximum fifo filling, "infinite" by default
"""
memory = []
@always(clk.posedge)
def access():
if we:
memory.insert(0, din.val)
if re:
try:
dout.next = memory.pop()
except IndexError:
raise Exception("Underflow -- Read from empty fifo")
filling = len(memory)
empty.next = (filling == 0)
full.next = (filling == maxFilling)
if filling > maxFilling:
raise Exception("Overflow -- Max filling %s exceeded" % maxFilling)
return access
示例14: _generate_unsigned_hash_code
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def _generate_unsigned_hash_code(strings, max_hash_value=sys.maxint):
# type: (List[str], int) -> int
"""Generates a forever-fixed hash code for `strings`.
The hash code generated is in the range [0, max_hash_value). Note that the
hash code generated by farmhash.fingerprint64 is unsigned.
"""
return farmhash.fingerprint64(json.dumps(strings)) % max_hash_value
示例15: test_copy
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import maxint [as 別名]
def test_copy(self):
current = sys.getrecursionlimit()
self.addCleanup(sys.setrecursionlimit, current)
# can't use sys.maxint as this doesn't exist in Python 3
sys.setrecursionlimit(int(10e8))
# this segfaults without the fix in place
copy.copy(Mock())