def copy_data(self):
HASH_FUNCTION = hashlib.sha256()<EOL>try:<EOL><INDENT>raw_iterator = self.get_binary_iterator()<EOL><DEDENT>except AttributeError:<EOL><INDENT>raw_iterator = self.get_non_binary_iterator()<EOL>self.copy_file = tempfile.NamedTemporaryFile(mode='<STR_LIT>')<EOL>for part in raw_iterator:<EOL><INDENT>encoded_part = dbsafe_encode(part)<EOL>self.copy_file.write(encoded_part)<EOL>self.copy_file.write('<STR_LIT:\n>')<EOL>HASH_FUNCTION.update(encoded_part)<EOL><DEDENT>self.copy_file.seek(<NUM_LIT:0>)<EOL>self.data_iterator = (dbsafe_decode(line) for line in self.copy_file)<EOL><DEDENT>else:<EOL><INDENT>self.copy_file = tempfile.NamedTemporaryFile(mode='<STR_LIT>')<EOL>for part in raw_iterator:<EOL><INDENT>self.copy_file.write(part)<EOL>HASH_FUNCTION.update(part)<EOL><DEDENT>self.copy_file.seek(<NUM_LIT:0>)<EOL>self.data_iterator = self.copy_file<EOL><DEDENT>self.new_hash = HASH_FUNCTION.hexdigest()<EOL>
Copy the data from the it's point of origin, serializing it,
storing it serialized as well as in it's raw form and calculate
a running hash of the serialized representation