def _guess_quote_and_delimiter(self, data, delimiters):
matches = []<EOL>for restr in ('<STR_LIT>', <EOL>'<STR_LIT>',   <EOL>'<STR_LIT>',  <EOL>'<STR_LIT>'):                            <EOL><INDENT>regexp = re.compile(restr, re.DOTALL | re.MULTILINE)<EOL>matches = regexp.findall(data)<EOL>if matches:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if not matches:<EOL><INDENT>return ('<STR_LIT>', False, None, <NUM_LIT:0>)<EOL><DEDENT>quotes = {}<EOL>delims = {}<EOL>spaces = <NUM_LIT:0><EOL>for m in matches:<EOL><INDENT>n = regexp.groupindex['<STR_LIT>'] - <NUM_LIT:1><EOL>key = m[n]<EOL>if key:<EOL><INDENT>quotes[key] = quotes.get(key, <NUM_LIT:0>) + <NUM_LIT:1><EOL><DEDENT>try:<EOL><INDENT>n = regexp.groupindex['<STR_LIT>'] - <NUM_LIT:1><EOL>key = m[n]<EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT>if key and (delimiters is None or key in delimiters):<EOL><INDENT>delims[key] = delims.get(key, <NUM_LIT:0>) + <NUM_LIT:1><EOL><DEDENT>try:<EOL><INDENT>n = regexp.groupindex['<STR_LIT>'] - <NUM_LIT:1><EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT>if m[n]:<EOL><INDENT>spaces += <NUM_LIT:1><EOL><DEDENT><DEDENT>quotechar = reduce(lambda a, b, quotes = quotes:<EOL>(quotes[a] > quotes[b]) and a or b, list(quotes.keys()))<EOL>if delims:<EOL><INDENT>delim = reduce(lambda a, b, delims = delims:<EOL>(delims[a] > delims[b]) and a or b, list(delims.keys()))<EOL>skipinitialspace = delims[delim] == spaces<EOL>if delim == '<STR_LIT:\n>': <EOL><INDENT>delim = '<STR_LIT>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>delim = '<STR_LIT>'<EOL>skipinitialspace = <NUM_LIT:0><EOL><DEDENT>dq_regexp = re.compile(<EOL>r"<STR_LIT>" %{'<STR_LIT>':re.escape(delim), '<STR_LIT>':quotechar}, re.MULTILINE)<EOL>if dq_regexp.search(data):<EOL><INDENT>doublequote = True<EOL><DEDENT>else:<EOL><INDENT>doublequote = False<EOL><DEDENT>return (quotechar, doublequote, delim, skipinitialspace)<EOL>
Looks for text enclosed between two identical quotes
(the probable quotechar) which are preceded and followed
by the same character (the probable delimiter).
For example:
                 ,'some text',
The quote with the most wins, same with the delimiter.
If there is no quotechar the delimiter can't be determined
this way.