Python sys.maxint() Examples
The following are 30 code examples for showing how to use sys.maxint(). 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
sys
, or try the search function
.
Example 1
Project: mishkal Author: linuxscout File: httpserver.py License: GNU General Public License v3.0 | 7 votes |
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
Example 2
Project: cutout Author: jojoin File: posixemulation.py License: MIT License | 6 votes |
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
Example 3
Project: llvm-zorg Author: llvm File: AnalyzerCompareCommand.py License: Apache License 2.0 | 6 votes |
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)
Example 4
Project: BotDigger Author: hanzhang0116 File: BotDigger.py License: GNU General Public License v3.0 | 6 votes |
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
Example 5
Project: jbox Author: jpush File: posixemulation.py License: MIT License | 6 votes |
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
Example 6
Project: interview-with-python Author: thundergolfer File: closetsum.py License: MIT License | 6 votes |
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
Example 7
Project: ReadableWebProxy Author: fake-name File: server.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
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")
Example 8
Project: GTDWeb Author: lanbing510 File: http.py License: GNU General Public License v2.0 | 6 votes |
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
Example 9
Project: GTDWeb Author: lanbing510 File: http.py License: GNU General Public License v2.0 | 6 votes |
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
Example 10
Project: meddle Author: glmcdona File: generator.py License: MIT License | 6 votes |
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
Example 11
Project: exaddos Author: Exa-Networks File: ipfix.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example 12
Project: lambda-packs Author: ryfeus File: posixemulation.py License: MIT License | 6 votes |
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
Example 13
Project: ironpython2 Author: IronLanguages File: generator.py License: Apache License 2.0 | 6 votes |
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
Example 14
Project: CAMISIM Author: CAMI-challenge File: soapdenovo.py License: Apache License 2.0 | 5 votes |
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
Example 15
Project: myhdl Author: myhdl File: fifo.py License: GNU Lesser General Public License v2.1 | 5 votes |
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
Example 16
Project: myhdl Author: myhdl File: fifo.py License: GNU Lesser General Public License v2.1 | 5 votes |
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
Example 17
Project: gcp-variant-transforms Author: googlegenomics File: hashing_util.py License: Apache License 2.0 | 5 votes |
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
Example 18
Project: jawfish Author: war-and-code File: testmock.py License: MIT License | 5 votes |
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())
Example 19
Project: pyspark-cassandra Author: TargetHolding File: tests.py License: Apache License 2.0 | 5 votes |
def test_bigint(self): self.read_write_test('bigint', sys.maxint)
Example 20
Project: monero-python Author: monero-ecosystem File: test_numbers.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_numeric_types(self): "Only check if conversion of given type succeeds or fails." self.assertTrue(to_atomic(1)) self.assertTrue(to_atomic(1.0)) if hasattr(sys, 'maxint'): # Python 2.x self.assertTrue(to_atomic(sys.maxint + 1)) self.assertRaises(ValueError, to_atomic, '1')
Example 21
Project: misp42splunk Author: remg427 File: py2_test_grammar.py License: GNU Lesser General Public License v3.0 | 5 votes |
def testPlainIntegers(self): self.assertEquals(0xff, 255) self.assertEquals(0377, 255) self.assertEquals(2147483647, 017777777777) # "0x" is not a valid literal self.assertRaises(SyntaxError, eval, "0x") from sys import maxint if maxint == 2147483647: self.assertEquals(-2147483647-1, -020000000000) # XXX -2147483648 self.assert_(037777777777 > 0) self.assert_(0xffffffff > 0) for s in '2147483648', '040000000000', '0x100000000': try: x = eval(s) except OverflowError: self.fail("OverflowError on huge integer literal %r" % s) elif maxint == 9223372036854775807: self.assertEquals(-9223372036854775807-1, -01000000000000000000000) self.assert_(01777777777777777777777 > 0) self.assert_(0xffffffffffffffff > 0) for s in '9223372036854775808', '02000000000000000000000', \ '0x10000000000000000': try: x = eval(s) except OverflowError: self.fail("OverflowError on huge integer literal %r" % s) else: self.fail('Weird maxint value %r' % maxint)
Example 22
Project: misp42splunk Author: remg427 File: py2_test_grammar.py License: GNU Lesser General Public License v3.0 | 5 votes |
def testPlainIntegers(self): self.assertEquals(0xff, 255) self.assertEquals(0377, 255) self.assertEquals(2147483647, 017777777777) # "0x" is not a valid literal self.assertRaises(SyntaxError, eval, "0x") from sys import maxint if maxint == 2147483647: self.assertEquals(-2147483647-1, -020000000000) # XXX -2147483648 self.assert_(037777777777 > 0) self.assert_(0xffffffff > 0) for s in '2147483648', '040000000000', '0x100000000': try: x = eval(s) except OverflowError: self.fail("OverflowError on huge integer literal %r" % s) elif maxint == 9223372036854775807: self.assertEquals(-9223372036854775807-1, -01000000000000000000000) self.assert_(01777777777777777777777 > 0) self.assert_(0xffffffffffffffff > 0) for s in '9223372036854775808', '02000000000000000000000', \ '0x10000000000000000': try: x = eval(s) except OverflowError: self.fail("OverflowError on huge integer literal %r" % s) else: self.fail('Weird maxint value %r' % maxint)
Example 23
Project: misp42splunk Author: remg427 File: thread.py License: GNU Lesser General Public License v3.0 | 5 votes |
def _python_exit(): global _shutdown _shutdown = True items = list(_threads_queues.items()) if _threads_queues else () for t, q in items: q.put(None) for t, q in items: t.join(sys.maxint)
Example 24
Project: misp42splunk Author: remg427 File: thread.py License: GNU Lesser General Public License v3.0 | 5 votes |
def shutdown(self, wait=True): with self._shutdown_lock: self._shutdown = True self._work_queue.put(None) if wait: for t in self._threads: t.join(sys.maxint)
Example 25
Project: misp42splunk Author: remg427 File: process.py License: GNU Lesser General Public License v3.0 | 5 votes |
def _python_exit(): global _shutdown _shutdown = True items = list(_threads_queues.items()) if _threads_queues else () for t, q in items: q.put(None) for t, q in items: t.join(sys.maxint) # Controls how many more calls than processes will be queued in the call queue. # A smaller number will mean that processes spend more time idle waiting for # work while a larger number will make Future.cancel() succeed less frequently # (Futures in the call queue cannot be cancelled).
Example 26
Project: seizure-prediction Author: MichaelHills File: mat_to_hdf5.py License: MIT License | 5 votes |
def process_data_sub_job(settings, filename_in_fmt, filename_out_fmt, id, num_jobs): pid = os.getpid() reader = mat_reader(target, settings.data_dir) num_processed = 0 for i in xrange(id + 1, sys.maxint, num_jobs): out_index = i - 1 filename_in = filename_in_fmt % i filename_out = filename_out_fmt % out_index if filename_out_fmt is not None else None filename_out_temp = '%s.pid.%d.tmp' % (filename_out, pid) if filename_out is not None else None if filename_out is not None and os.path.exists(filename_out): num_processed += 1 continue if not reader.exists(filename_in): if i == id + 1: print 'Could not find file', reader.filename(filename_in) return 0 break print 'Runner %d processing %s' % (id, reader.filename(filename_in)) segment = reader.read(filename_in) data = process_data(segment) hdf5.write(filename_out_temp, data) os.rename(filename_out_temp, filename_out) num_processed += 1 return num_processed
Example 27
Project: linter-pylama Author: AtomLinter File: thread.py License: MIT License | 5 votes |
def _python_exit(): global _shutdown _shutdown = True items = list(_threads_queues.items()) if _threads_queues else () for t, q in items: q.put(None) for t, q in items: t.join(sys.maxint)
Example 28
Project: linter-pylama Author: AtomLinter File: thread.py License: MIT License | 5 votes |
def shutdown(self, wait=True): with self._shutdown_lock: self._shutdown = True self._work_queue.put(None) if wait: for t in self._threads: t.join(sys.maxint)
Example 29
Project: linter-pylama Author: AtomLinter File: process.py License: MIT License | 5 votes |
def _python_exit(): global _shutdown _shutdown = True items = list(_threads_queues.items()) if _threads_queues else () for t, q in items: q.put(None) for t, q in items: t.join(sys.maxint) # Controls how many more calls than processes will be queued in the call queue. # A smaller number will mean that processes spend more time idle waiting for # work while a larger number will make Future.cancel() succeed less frequently # (Futures in the call queue cannot be cancelled).
Example 30
Project: linter-pylama Author: AtomLinter File: process.py License: MIT License | 5 votes |
def shutdown(self, wait=True): with self._shutdown_lock: self._shutdown_thread = True if self._queue_management_thread: # Wake up queue management thread self._result_queue.put(None) if wait: self._queue_management_thread.join(sys.maxint) # To reduce the risk of openning too many files, remove references to # objects that use file descriptors. self._queue_management_thread = None self._call_queue = None self._result_queue = None self._processes = None