Merge pull request #146 from trailofbits/dev-utf8

Open files with UTF-8 encoding
pull/132/head
Feist Josselin 6 years ago committed by GitHub
commit 05556c932b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      scripts/json_diff.py
  2. 4
      slither/__main__.py
  3. 6
      slither/core/declarations/function.py
  4. 2
      slither/printers/call/call_graph.py
  5. 2
      slither/printers/inheritance/inheritance_graph.py
  6. 2
      slither/slither.py
  7. 6
      slither/solc_parsing/slitherSolc.py

@ -7,10 +7,10 @@ if len(sys.argv) !=3:
print('Usage: python json_diff.py 1.json 2.json')
exit(-1)
with open(sys.argv[1]) as f:
with open(sys.argv[1], encoding='utf8') as f:
d1 = json.load(f)
with open(sys.argv[2]) as f:
with open(sys.argv[2], encoding='utf8') as f:
d2 = json.load(f)

@ -84,7 +84,7 @@ def process_files(filenames, args, detector_classes, printer_classes):
all_contracts = []
for filename in filenames:
with open(filename) as f:
with open(filename, encoding='utf8') as f:
contract_loaded = json.load(f)
all_contracts.append(contract_loaded['ast'])
@ -93,7 +93,7 @@ def process_files(filenames, args, detector_classes, printer_classes):
def output_json(results, filename):
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf8') as f:
json.dump(results, f)

@ -642,7 +642,7 @@ class Function(ChildContract, SourceMapping):
Args:
filename (str)
"""
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf8') as f:
f.write('digraph{\n')
for node in self.nodes:
f.write('{}[label="{}"];\n'.format(node.node_id, str(node)))
@ -658,7 +658,7 @@ class Function(ChildContract, SourceMapping):
filename (str)
"""
from slither.core.cfg.node import NodeType
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf8') as f:
f.write('digraph{\n')
for node in self.nodes:
label = 'Node Type: {} {}\n'.format(NodeType.str(node.type), node.node_id)
@ -684,7 +684,7 @@ class Function(ChildContract, SourceMapping):
if node.dominance_frontier:
desc += '\ndominance frontier: {}'.format([n.node_id for n in node.dominance_frontier])
return desc
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf8') as f:
f.write('digraph{\n')
for node in self.nodes:
f.write('{}[label="{}"];\n'.format(node.node_id, description(node)))

@ -145,7 +145,7 @@ class PrinterCallGraph(AbstractPrinter):
self.info(f'Call Graph: {filename}')
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf8') as f:
f.write('\n'.join([
'strict digraph {',
self._render_internal_calls(),

@ -117,7 +117,7 @@ class PrinterInheritanceGraph(AbstractPrinter):
filename += ".dot"
info = 'Inheritance Graph: ' + filename
self.info(info)
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf8') as f:
f.write('digraph{\n')
for c in self.contracts:
f.write(self._summary(c))

@ -117,7 +117,7 @@ class Slither(SlitherSolc):
raise Exception('Incorrect file format')
if is_ast_file:
with open(filename) as astFile:
with open(filename, encoding='utf8') as astFile:
stdout = astFile.read()
if not stdout:
logger.info('Empty AST file: %s', filename)

@ -63,7 +63,7 @@ class SlitherSolc(Slither):
if 'sourcePaths' in data_loaded:
for sourcePath in data_loaded['sourcePaths']:
if os.path.isfile(sourcePath):
with open(sourcePath) as f:
with open(sourcePath, encoding='utf8') as f:
source_code = f.read()
self.source_code[sourcePath] = source_code
@ -126,13 +126,13 @@ class SlitherSolc(Slither):
self._source_units[sourceUnit] = name
if os.path.isfile(name) and not name in self.source_code:
with open(name) as f:
with open(name, encoding='utf8') as f:
source_code = f.read()
self.source_code[name] = source_code
else:
lib_name = os.path.join('node_modules', name)
if os.path.isfile(lib_name) and not name in self.source_code:
with open(lib_name) as f:
with open(lib_name, encoding='utf8') as f:
source_code = f.read()
self.source_code[name] = source_code

Loading…
Cancel
Save