def parse(src, encoding=None):
def safe_is_file(filename):<EOL><INDENT>try:<EOL><INDENT>return os.path.isfile(src)<EOL><DEDENT>except ValueError:  <EOL><INDENT>return False<EOL><DEDENT><DEDENT>if hasattr(src, '<STR_LIT>'):  <EOL><INDENT>data = src.read()<EOL><DEDENT>elif safe_is_file(src):<EOL><INDENT>with open(src, '<STR_LIT:rb>') as fh:<EOL><INDENT>data = fh.read()<EOL><DEDENT><DEDENT>else:  <EOL><INDENT>data = src<EOL><DEDENT>if hasattr(data, '<STR_LIT>'):  <EOL><INDENT>exception = None<EOL>encodings = [encoding, '<STR_LIT:utf-8>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>for encoding in encodings:  <EOL><INDENT>if not encoding:<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>data = data.decode(encoding)<EOL>break<EOL><DEDENT>except UnicodeDecodeError as e:<EOL><INDENT>exception = e<EOL><DEDENT>except UnicodeEncodeError:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise exception  <EOL><DEDENT><DEDENT>transactions = mt940.models.Transactions()<EOL>transactions.parse(data)<EOL>return transactions<EOL>
Parses mt940 data and returns transactions object

:param src: file handler to read, filename to read or raw data as string
:return: Collection of transactions
:rtype: Transactions