Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
formatter = colorlog.ColoredFormatter(self.logformat)
stream = logging.StreamHandler()
stream.setLevel(logging.DEBUG)
stream.setFormatter(formatter)
self.logger = logging.getLogger('colorlog')
self.logger.setLevel(logging.DEBUG)
self.logger.addHandler(stream)
def _configure_logger(logger_name, stream_format, file_format, logfile, level, log_colors):
logger = logging.getLogger(logger_name)
logger.setLevel(level)
# Clear any existing handlers
logger.handlers = []
if file_format and logfile:
file_handler = logging.FileHandler(logfile, mode='a', encoding='utf-8')
file_handler.setFormatter(logging.Formatter(file_format))
logger.addHandler(file_handler)
if stream_format:
formatter = colorlog.TTYColoredFormatter(stream=sys.stdout, fmt=stream_format, log_colors=log_colors)
stream_handler = logging.StreamHandler(stream=sys.stdout)
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
logger.setLevel(loglevel)
if 'LogFile' in config and config['LogFile'] != '__screen__':
logfile = config['LogFile']
if not os.path.isdir(os.path.dirname(logfile)):
warnings.warn("Logging directory {0} does not exist".format(
os.path.abspath(os.path.dirname(logfile))))
sys.exit(-1)
flog = logging.FileHandler(logfile)
flog.setFormatter(logging.Formatter(
'[%(asctime)s, %(levelno)d, %(module)s] %(message)s', "%H:%M:%S"))
logger.addHandler(flog)
else:
clog = logging.StreamHandler()
formatter = ColoredFormatter(
"%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s "
"%(white)s%(message)s",
datefmt="%H:%M:%S",
reset=True,
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red',
})
clog.setFormatter(formatter)
clog.setLevel(loglevel)
logger.addHandler(clog)
def entry_point():
"""Zero-argument entry point for use with setuptools/distribute."""
logger = logging.getLogger()
logger.setLevel(logging.INFO)
handler = colorlog.StreamHandler()
fmt = (
'%(asctime)-8s (%(bold)s%(log_color)s%(levelname)s%(reset)s) '
'%(message)s')
formatter = colorlog.ColoredFormatter(fmt, datefmt='%H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
keyman = Keyman(sys.argv)
raise SystemExit(keyman.main())
help='VBA expression to be evaluated')
parser.add_option('-l', '--loglevel', dest="loglevel", action="store", default=DEFAULT_LOG_LEVEL,
help="logging level debug/info/warning/error/critical (default=%default)")
(options, args) = parser.parse_args()
# Print help if no arguments are passed
# if len(args) == 0:
# print(__doc__)
# parser.print_help()
# sys.exit()
# setup logging to the console
# logging.basicConfig(level=LOG_LEVELS[options.loglevel], format='%(levelname)-8s %(message)s')
colorlog.basicConfig(level=LOG_LEVELS[options.loglevel], format='%(log_color)s%(levelname)-8s %(message)s')
if options.parse_file:
parse(options.parse_file)
if options.eval_expr:
eval_expression(options.eval_expr)
while True:
try:
print("VBA> ", end='')
cmd = raw_input()
if cmd.startswith('exit'):
break
if cmd.startswith('parse'):
(options, args) = parser.parse_args()
# Print version information and exit?
if (options.print_version):
print_version()
sys.exit(0)
# Print help if no arguments are passed
if len(args) == 0:
safe_print(__doc__)
parser.print_help()
sys.exit(0)
# setup logging to the console
# logging.basicConfig(level=LOG_LEVELS[options.loglevel], format='%(levelname)-8s %(message)s')
colorlog.basicConfig(level=LOG_LEVELS[options.loglevel], format='%(log_color)s%(levelname)-8s %(message)s')
json_results = []
for container, filename, data in xglob.iter_files(args,
recursive=options.recursive,
zip_password=options.zip_password,
zip_fname=options.zip_fname):
# ignore directory names stored in zip files:
if container and filename.endswith('/'):
continue
if options.scan_expressions:
process_file_scanexpr(container, filename, data)
else:
entry_points = None
if (options.entry_points is not None):
def init():
if len(logging.getLogger("").handlers) > 1:
return
shandler = logging.StreamHandler(stream=sys.stdout)
shandler.setFormatter(colorlog.LevelFormatter(
fmt = {
"DEBUG": "{log_color}[{levelname}] {message}",
"INFO": "{log_color}[{levelname}] {message}",
"WARNING": "{log_color}[{levelname}] {message}",
"ERROR": "{log_color}[{levelname}] {message}",
"CRITICAL": "{log_color}[{levelname}] {message}"
},
log_colors = {
"DEBUG": "cyan",
"INFO": "white",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "bold_red"
},
style = "{",
datefmt = ""
def init():
if len(logging.getLogger("").handlers) > 1:
return
shandler = logging.StreamHandler(stream=sys.stdout)
shandler.setFormatter(colorlog.LevelFormatter(
fmt = {
"DEBUG": "{log_color}[{levelname}] {message}",
"INFO": "{log_color}[{levelname}] {message}",
"WARNING": "{log_color}[{levelname}] {message}",
"ERROR": "{log_color}[{levelname}] {message}",
"CRITICAL": "{log_color}[{levelname}] {message}"
},
log_colors = {
"DEBUG": "cyan",
"INFO": "white",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "bold_red"
},
style = "{",
datefmt = ""
response = tokenize(example['labels'][0])
else:
response = tokenize(example['eval_labels'][0])
chosen_topic = tokenize(example['chosen_topic'])
# Set up knowledge
checked_knowledge = example['title'] + ' __knowledge__ ' + example['checked_sentence']
knowledges = [checked_knowledge] + \
[k for k in example['knowledge'].rstrip().split('\n')]
for idx, k in enumerate(knowledges[1:]):
if k == checked_knowledge:
break
else:
# Sometimes, knowledge does not include checked_sentnece
idx = None
colorlog.warning("Knowledge does not include checked sentence.")
if idx is not None:
del knowledges[idx + 1]
# Tokenize knowledge
knowledge_sentences = [tokenize(k) for k in knowledges]
new_example = {'context': context,
'response': response,
'chosen_topic': chosen_topic,
'knowledge_sentences': knowledge_sentences,
'episode_num': episode_num,
'example_num': example_num}
if 'multi_eval_labels' in example:
responses = [tokenize(response) for response in example['multi_eval_labels']]
new_example['responses'] = responses
if 'multi_checked_sentences' in example:
response = tokenize(example['labels'][0])
else:
response = tokenize(example['eval_labels'][0])
chosen_topic = tokenize(example['chosen_topic'])
# Set up knowledge
checked_knowledge = example['title'] + ' __knowledge__ ' + example['checked_sentence']
knowledges = [checked_knowledge] + \
[k for k in example['knowledge'].rstrip().split('\n')]
for idx, k in enumerate(knowledges[1:]):
if k == checked_knowledge:
break
else:
# Sometimes, knowledge does not include checked_sentnece
idx = None
colorlog.warning("Knowledge does not include checked sentence.")
if idx is not None:
del knowledges[idx + 1]
# Tokenize knowledge
knowledge_sentences = [tokenize(k) for k in knowledges]
new_example = {'context': context,
'response': response,
'chosen_topic': chosen_topic,
'knowledge_sentences': knowledge_sentences,
'episode_num': episode_num,
'example_num': example_num}
new_examples.append(new_example)
new_episodes.append(new_examples)
if self._datapath: