#NEWLINE# def split_first( s , delims ) : #NEWLINE# #INDENT# "\n    Given a string and an iterable of delimiters, split on the first found\n    delimiter. Return two split parts and the matched delimiter.\n\n    If not found, then the first part is the full input string.\n\n    Example::\n\n        >>> split_first('foo/bar?baz', '?/=')\n        ('foo', 'bar?baz', '/')\n        >>> split_first('foo/bar?baz', '123')\n        ('foo/bar?baz', '', None)\n\n    Scales linearly with number of delims. Not ideal for large number of delims.\n    " #NEWLINE# min_idx = None #NEWLINE# min_delim = None #NEWLINE# for d in delims : #NEWLINE# #INDENT# idx = s . find ( d ) #NEWLINE# if ( idx < 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( ( min_idx is None ) or ( idx < min_idx ) ) : #NEWLINE# #INDENT# min_idx = idx #NEWLINE# min_delim = d #NEWLINE# #UNINDENT# #UNINDENT# if ( ( min_idx is None ) or ( min_idx < 0 ) ) : #NEWLINE# #INDENT# return ( s , '' , None ) #NEWLINE# #UNINDENT# return ( s [ : min_idx ] , s [ ( min_idx + 1 ) : ] , min_delim )