def __init__(self, file_path=None, file_object=None, input_string=None, cif_object=None, builder=None, raise_if_errors=True, strict=True): assert [file_path, file_object, input_string].count(None) == 2 self.file_path = file_path if builder is None: builder = builders.cif_model_builder(cif_object) else: assert cif_object is None self.builder = builder if file_path is not None: file_object = smart_open.for_reading(file_path) else: file_path = "memory" if file_object is not None: input_string = file_object.read() # check input_string for binary, and abort if necessary binary_detector = detect_binary_file() binary_detector.monitor_initial = min(len(input_string), binary_detector.monitor_initial) if binary_detector.is_binary_file(block=input_string): raise CifParserError("Binary file detected, aborting parsing.") self.parser = ext.fast_reader(builder, input_string, file_path, strict) if raise_if_errors and len(self.parser.lexer_errors()): raise CifParserError(self.parser.lexer_errors()[0]) if raise_if_errors and len(self.parser.parser_errors()): raise CifParserError(self.parser.parser_errors()[0])
def __init__(self, file_path=None, file_object=None, input_string=None, cif_object=None, builder=None, raise_if_errors=True, strict=True): assert [file_path, file_object, input_string].count(None) == 2 self.file_path = file_path if builder is None: builder = builders.cif_model_builder(cif_object) else: assert cif_object is None self.builder = builder if file_path is not None: file_object = smart_open.for_reading(file_path) else: file_path = "memory" if file_object is not None: input_string = file_object.read() # check input_string for binary, and abort if necessary binary_detector = detect_binary_file() binary_detector.monitor_initial = min( len(input_string), binary_detector.monitor_initial) if binary_detector.is_binary_file(block=input_string): raise CifParserError("Binary file detected, aborting parsing.") self.parser = ext.fast_reader(builder, input_string, file_path, strict) if raise_if_errors and len(self.parser.lexer_errors()): raise CifParserError(self.parser.lexer_errors()[0]) if raise_if_errors and len(self.parser.parser_errors()): raise CifParserError(self.parser.parser_errors()[0])