Python sys.tracebacklimit() Examples
The following are 30
code examples of sys.tracebacklimit().
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 also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example #1
Source File: debug.py From asynq with Apache License 2.0 | 7 votes |
def extract_tb(tb, limit=None): """This implementation is stolen from traceback module but respects __traceback_hide__.""" if limit is None: if hasattr(sys, "tracebacklimit"): limit = sys.tracebacklimit tb_list = [] n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame if not _should_skip_frame(f): lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None tb_list.append((filename, lineno, name, line)) tb = tb.tb_next n = n + 1 return tb_list
Example #2
Source File: main.py From dbf2csv with MIT License | 6 votes |
def main(): sys.tracebacklimit = 0 args = get_args() if args.quoting_mode == 'minimal': args.quoting = csv.QUOTE_MINIMAL elif args.quoting_mode == 'all': args.quoting = csv.QUOTE_ALL elif args.quoting_mode == 'non-numeric': args.quoting = csv.QUOTE_NONNUMERIC elif args.quoting_mode == 'none': args.quoting = csv.QUOTE_NONE if os.path.isdir(args.input): process_directory(args.input, args.output, args) elif os.path.isfile(args.input): process_file(args.input, args.output, args)
Example #3
Source File: __init__.py From cats-blender-plugin with MIT License | 6 votes |
def check_unsupported_blender_versions(): # Don't allow Blender versions older than 2.79 if bpy.app.version < (2, 79): unregister() sys.tracebacklimit = 0 raise ImportError('\n\nBlender versions older than 2.79 are not supported by Cats. ' '\nPlease use Blender 2.79 or later.' '\n') # Versions 2.80.0 to 2.80.74 are beta versions, stable is 2.80.75 if (2, 80, 0) <= bpy.app.version < (2, 80, 75): unregister() sys.tracebacklimit = 0 raise ImportError('\n\nYou are still on the beta version of Blender 2.80!' '\nPlease update to the release version of Blender 2.80.' '\n')
Example #4
Source File: collector.py From mishkal with GNU General Public License v3.0 | 5 votes |
def getLimit(self): limit = self.limit if limit is None: limit = getattr(sys, 'tracebacklimit', None) return limit
Example #5
Source File: traceback.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ if file is None: file = sys.stderr if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name _print(file, ' File "%s", line %d, in %s' % (filename, lineno, name)) linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: _print(file, ' ' + line.strip()) tb = tb.tb_next n = n+1
Example #6
Source File: __init__.py From script.module.openscrapers with GNU General Public License v3.0 | 5 votes |
def simpleException(self, exception, msg): self._solveDepthCnt = 0 sys.tracebacklimit = 0 raise exception(msg) # ------------------------------------------------------------------------------- # # debug the request via the response # ------------------------------------------------------------------------------- #
Example #7
Source File: traceback.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ if file is None: file = sys.stderr if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name _print(file, ' File "%s", line %d, in %s' % (filename, lineno, name)) linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: _print(file, ' ' + line.strip()) tb = tb.tb_next n = n+1
Example #8
Source File: traceback.py From canape with GNU General Public License v3.0 | 5 votes |
def extract_stack(f=None, limit = None): """Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame. """ if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while f is not None and (limit is None or n < limit): lineno = f.f_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) f = f.f_back n = n+1 list.reverse() return list
Example #9
Source File: traceback.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def extract_tb(tb, limit = None): """Return list of up to limit pre-processed entries from traceback. This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a quadruple (filename, line number, function name, text) representing the information that is usually printed for a stack trace. The text is a string with leading and trailing whitespace stripped; if the source is not available it is None. """ if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) tb = tb.tb_next n = n+1 return list
Example #10
Source File: traceback.py From canape with GNU General Public License v3.0 | 5 votes |
def extract_tb(tb, limit = None): """Return list of up to limit pre-processed entries from traceback. This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a quadruple (filename, line number, function name, text) representing the information that is usually printed for a stack trace. The text is a string with leading and trailing whitespace stripped; if the source is not available it is None. """ if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) tb = tb.tb_next n = n+1 return list
Example #11
Source File: traceback.py From canape with GNU General Public License v3.0 | 5 votes |
def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ if file is None: file = sys.stderr if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name _print(file, ' File "%s", line %d, in %s' % (filename, lineno, name)) linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: _print(file, ' ' + line.strip()) tb = tb.tb_next n = n+1
Example #12
Source File: traceback.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def extract_tb(tb, limit = None): """Return list of up to limit pre-processed entries from traceback. This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a quadruple (filename, line number, function name, text) representing the information that is usually printed for a stack trace. The text is a string with leading and trailing whitespace stripped; if the source is not available it is None. """ if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) tb = tb.tb_next n = n+1 return list
Example #13
Source File: traceback.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def extract_tb(tb, limit = None): """Return list of up to limit pre-processed entries from traceback. This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a quadruple (filename, line number, function name, text) representing the information that is usually printed for a stack trace. The text is a string with leading and trailing whitespace stripped; if the source is not available it is None. """ if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) tb = tb.tb_next n = n+1 return list
Example #14
Source File: traceback.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ if file is None: file = sys.stderr if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name _print(file, ' File "%s", line %d, in %s' % (filename, lineno, name)) linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: _print(file, ' ' + line.strip()) tb = tb.tb_next n = n+1
Example #15
Source File: traceback.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def extract_stack(f=None, limit = None): """Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame. """ if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while f is not None and (limit is None or n < limit): lineno = f.f_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) f = f.f_back n = n+1 list.reverse() return list
Example #16
Source File: traceback.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def extract_tb(tb, limit = None): """Return list of up to limit pre-processed entries from traceback. This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a quadruple (filename, line number, function name, text) representing the information that is usually printed for a stack trace. The text is a string with leading and trailing whitespace stripped; if the source is not available it is None. """ if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) tb = tb.tb_next n = n+1 return list
Example #17
Source File: traceback.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ if file is None: file = sys.stderr if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name _print(file, ' File "%s", line %d, in %s' % (filename, lineno, name)) linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: _print(file, ' ' + line.strip()) tb = tb.tb_next n = n+1
Example #18
Source File: tbprint.py From plugin.program.indigo with GNU General Public License v3.0 | 5 votes |
def extract_stack(f=None, limit=None): """Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame. """ if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while f is not None and (limit is None or n < limit): lineno = f.f_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) f = f.f_back n = n+1 list.reverse() return list
Example #19
Source File: tbprint.py From plugin.program.indigo with GNU General Public License v3.0 | 5 votes |
def extract_tb(tb, limit=None): """Return list of up to limit pre-processed entries from traceback. This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a quadruple (filename, line number, function name, text) representing the information that is usually printed for a stack trace. The text is a string with leading and trailing whitespace stripped; if the source is not available it is None. """ if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) tb = tb.tb_next n = n+1 return list
Example #20
Source File: tbprint.py From plugin.program.indigo with GNU General Public License v3.0 | 5 votes |
def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ if file is None: file = sys.stderr if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name _print(file, ' File "%s", line %d, in %s' % (filename, lineno, name)) linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: _print(file, ' ' + line.strip()) tb = tb.tb_next n = n+1
Example #21
Source File: proxysql.py From mysqlshell-plugins with GNU General Public License v2.0 | 5 votes |
def __init__(self, uri=False): self.user = None self.ip = None self.port = None self.members = [] self.hosts = [] self.version = None self.w_hostgroup = 2 self.b_w_hostgroup = 4 self.r_hostgroup = 3 self.o_hostgroup = 1 self.max_writer = 1 self.writer_is_reader = 0 self.max_transaction_behind = 100 self.monitor_user = "monitor" self.monitor_pwd = "monitor" self.uri = uri self.user = shell.parse_uri(self.uri)['user'] if self.user == 'admin': sys.tracebacklimit = 0 raise Exception("You should not use the default 'admin' user, please create a new one in ProxySQL") self.ip = shell.parse_uri(self.uri)['host'] self.port = shell.parse_uri(self.uri)['port'] if not "password" in shell.parse_uri(self.uri): self.__password = shell.prompt('Password: ',{'type': 'password'}) else: self.__password = shell.parse_uri(self.uri)['password'] try: self.session = mysql.get_session("%s:%s@%s:%s?ssl-mode=DISABLED" % (self.user, self.__password, self.ip, self.port)) stmt = "select version()" result = self.session.run_sql(stmt) self.version = result.fetch_one()[0] print("Connected to ProxySQL (%s)" % self.version) except: sys.tracebacklimit = 0 raise Exception("Not possible to connect to ProxySQL admin interface !")
Example #22
Source File: pjf_logger.py From PyJFuzz with MIT License | 5 votes |
def init_logger(): logger = logging.getLogger(__name__) logger.setLevel(level=PYJFUZZ_LOGLEVEL) filehandler = logging.FileHandler("pjf_{0}.log".format(time.strftime("%d_%m_%Y"))) logger.addHandler(filehandler) sys.tracebacklimit = 10 return logger
Example #23
Source File: traceback.py From medicare-demo with Apache License 2.0 | 5 votes |
def extract_stack(f=None, limit = None): """Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame. """ if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while f is not None and (limit is None or n < limit): lineno = f.f_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) f = f.f_back n = n+1 list.reverse() return list
Example #24
Source File: traceback.py From medicare-demo with Apache License 2.0 | 5 votes |
def extract_tb(tb, limit = None): """Return list of up to limit pre-processed entries from traceback. This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a quadruple (filename, line number, function name, text) representing the information that is usually printed for a stack trace. The text is a string with leading and trailing whitespace stripped; if the source is not available it is None. """ if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) tb = tb.tb_next n = n+1 return list
Example #25
Source File: traceback.py From medicare-demo with Apache License 2.0 | 5 votes |
def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ if file is None: file = sys.stderr if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name _print(file, ' File "%s", line %d, in %s' % (filename,lineno,name)) linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: _print(file, ' ' + line.strip()) tb = tb.tb_next n = n+1
Example #26
Source File: test_traceback.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_format_exception(self): try: self.last_raises5() except Exception: exc_type, exc_value, tb = sys.exc_info() # [1:-1] to exclude "Traceback (...)" header and # exception type and value def extract(**kwargs): return traceback.format_exception(exc_type, exc_value, tb, **kwargs)[1:-1] with support.swap_attr(sys, 'tracebacklimit', 1000): nolim = extract() self.assertEqual(len(nolim), 5+1) self.assertEqual(extract(limit=2), nolim[:2]) self.assertEqual(extract(limit=10), nolim) self.assertEqual(extract(limit=-2), nolim[-2:]) self.assertEqual(extract(limit=-10), nolim) self.assertEqual(extract(limit=0), []) del sys.tracebacklimit self.assertEqual(extract(), nolim) sys.tracebacklimit = 2 self.assertEqual(extract(), nolim[:2]) self.assertEqual(extract(limit=3), nolim[:3]) self.assertEqual(extract(limit=-3), nolim[-3:]) sys.tracebacklimit = 0 self.assertEqual(extract(), []) sys.tracebacklimit = -1 self.assertEqual(extract(), [])
Example #27
Source File: test_traceback.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_extract_tb(self): try: self.last_raises5() except Exception: exc_type, exc_value, tb = sys.exc_info() def extract(**kwargs): return traceback.extract_tb(tb, **kwargs) with support.swap_attr(sys, 'tracebacklimit', 1000): nolim = extract() self.assertEqual(len(nolim), 5+1) self.assertEqual(extract(limit=2), nolim[:2]) self.assertEqual(extract(limit=10), nolim) self.assertEqual(extract(limit=-2), nolim[-2:]) self.assertEqual(extract(limit=-10), nolim) self.assertEqual(extract(limit=0), []) del sys.tracebacklimit self.assertEqual(extract(), nolim) sys.tracebacklimit = 2 self.assertEqual(extract(), nolim[:2]) self.assertEqual(extract(limit=3), nolim[:3]) self.assertEqual(extract(limit=-3), nolim[-3:]) sys.tracebacklimit = 0 self.assertEqual(extract(), []) sys.tracebacklimit = -1 self.assertEqual(extract(), [])
Example #28
Source File: test_traceback.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_extract_stack(self): frame = self.last_returns_frame5() def extract(**kwargs): return traceback.extract_stack(frame, **kwargs) def assertEqualExcept(actual, expected, ignore): self.assertEqual(actual[:ignore], expected[:ignore]) self.assertEqual(actual[ignore+1:], expected[ignore+1:]) self.assertEqual(len(actual), len(expected)) with support.swap_attr(sys, 'tracebacklimit', 1000): nolim = extract() self.assertGreater(len(nolim), 5) self.assertEqual(extract(limit=2), nolim[-2:]) assertEqualExcept(extract(limit=100), nolim[-100:], -5-1) self.assertEqual(extract(limit=-2), nolim[:2]) assertEqualExcept(extract(limit=-100), nolim[:100], len(nolim)-5-1) self.assertEqual(extract(limit=0), []) del sys.tracebacklimit assertEqualExcept(extract(), nolim, -5-1) sys.tracebacklimit = 2 self.assertEqual(extract(), nolim[-2:]) self.assertEqual(extract(limit=3), nolim[-3:]) self.assertEqual(extract(limit=-3), nolim[:3]) sys.tracebacklimit = 0 self.assertEqual(extract(), []) sys.tracebacklimit = -1 self.assertEqual(extract(), [])
Example #29
Source File: nodejs.py From script.module.openscrapers with GNU General Public License v3.0 | 5 votes |
def eval(self, body, domain): try: js = 'var atob = function(str) {return Buffer.from(str, "base64").toString("binary");};' \ 'var challenge = atob("%s");' \ 'var context = {atob: atob};' \ 'var options = {filename: "iuam-challenge.js", timeout: 4000};' \ 'var answer = require("vm").runInNewContext(challenge, context, options);' \ 'process.stdout.write(String(answer));' \ % base64.b64encode(template(body, domain).encode('UTF-8')).decode('ascii') return subprocess.check_output(['node', '-e', js]) except OSError as e: if e.errno == 2: raise EnvironmentError( 'Missing Node.js runtime. Node is required and must be in the PATH (check with `node -v`).\n\n' 'Your Node binary may be called `nodejs` rather than `node`, ' 'in which case you may need to run `apt-get install nodejs-legacy` on some Debian-based systems.\n\n' '(Please read the cloudscraper README\'s Dependencies section: ' 'https://github.com/VeNoMouS/cloudscraper#dependencies.)' ) raise except Exception: sys.tracebacklimit = 0 raise RuntimeError('Error executing Cloudflare IUAM Javascript in nodejs') # ------------------------------------------------------------------------------- #
Example #30
Source File: data.py From osm-python-tools with GNU General Public License v3.0 | 5 votes |
def _raiseException(prefix, msg): sys.tracebacklimit = None raise(Exception('[OSMPythonTools.' + prefix + '] ' + msg))