mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
Report attacking by "."
This commit is contained in:
33
sith.py
33
sith.py
@@ -11,6 +11,11 @@ import random
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
try:
|
||||||
|
from itertools import izip as zip
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
|
|
||||||
|
|
||||||
@@ -105,6 +110,31 @@ class MixinLoader(object):
|
|||||||
self.load_record(record)
|
self.load_record(record)
|
||||||
|
|
||||||
|
|
||||||
|
class AttackReporter(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.tries = 0
|
||||||
|
self.errors = 0
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
self.tries += 1
|
||||||
|
sys.stderr.write('.')
|
||||||
|
sys.stderr.flush()
|
||||||
|
return self.tries
|
||||||
|
|
||||||
|
next = __next__
|
||||||
|
|
||||||
|
def error(self):
|
||||||
|
self.errors += 1
|
||||||
|
sys.stderr.write('\n')
|
||||||
|
sys.stderr.flush()
|
||||||
|
print('{0}th error is encountered after {1} tries.'
|
||||||
|
.format(self.errors, self.tries))
|
||||||
|
|
||||||
|
|
||||||
class RandomAtaccker(MixinPrinter, BaseAttacker):
|
class RandomAtaccker(MixinPrinter, BaseAttacker):
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@@ -122,13 +152,16 @@ class RandomAtaccker(MixinPrinter, BaseAttacker):
|
|||||||
|
|
||||||
def do_run(self, record, rootpath, maxtries):
|
def do_run(self, record, rootpath, maxtries):
|
||||||
finder = SourceFinder(rootpath)
|
finder = SourceFinder(rootpath)
|
||||||
|
reporter = AttackReporter()
|
||||||
for (operation, args) in self.generate_attacks(maxtries, finder):
|
for (operation, args) in self.generate_attacks(maxtries, finder):
|
||||||
|
reporter.next()
|
||||||
try:
|
try:
|
||||||
self.attack(operation, *args)
|
self.attack(operation, *args)
|
||||||
except jedi.NotFoundError:
|
except jedi.NotFoundError:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
self.add_record(sys.exc_info(), operation, args)
|
self.add_record(sys.exc_info(), operation, args)
|
||||||
|
reporter.error()
|
||||||
self.print_record()
|
self.print_record()
|
||||||
raise
|
raise
|
||||||
self.save_record(record)
|
self.save_record(record)
|
||||||
|
|||||||
Reference in New Issue
Block a user