(split_by, quote, as_type)
return regexp
Build regexp for use with split_quoted and split_pair.
    `split_by` and `quote` must be of type `as_type`.
Build regexp for use with split_quoted and split_pair.
    `split_by` and `quote` must be of type `as_type`.
Build regexp for use with split_quoted and split_pair . split_by and quote must be of type as_type .
def _build_split_regexp(split_by, quote, as_type):
    """
    Build regexp for use with split_quoted and split_pair.
    `split_by` and `quote` must be of type `as_type`.
    """
    if not quote:
        quote = as_type()
    quote = re.escape(quote)
    if split_by is None:
        # by default, split on whitespace
        split_by = u'\s'
    else:
        split_by = re.escape(split_by)
    # https://stackoverflow.com/questions/16710076/python-split-a-string-respect-and-preserve-quotes
    # note ur'' is not accepted by python 3, and r'' means bytes in python2.
    # bytes has no .format so using % which is awkward here
    pattern = (
        br'(?:[^{%s}{%s}]|[{%s}](?:\\.|[^{%s}])*[{%s}])+'
    )
    if as_type == type(u''):
        # we know the template pattern string and ascii is ok
        pattern = pattern.decode('ascii', 'ignore')
    regexp = pattern % (split_by, quote, quote, quote, quote)
    return regexp
def _build_split_regexp ( split_by , quote , as_type ) : if not quote : quote = as_type ( ) quote = re . escape ( quote ) if split_by is None : # by default, split on whitespace split_by = u'\s' else : split_by = re . escape ( split_by ) # https://stackoverflow.com/questions/16710076/python-split-a-string-respect-and-preserve-quotes # note ur'' is not accepted by python 3, and r'' means bytes in python2. # bytes has no .format so using % which is awkward here pattern = ( br'(?:[^{%s}{%s}]|[{%s}](?:\\.|[^{%s}])*[{%s}])+' ) if as_type == type ( u'' ) : # we know the template pattern string and ascii is ok pattern = pattern . decode ( 'ascii' , 'ignore' ) regexp = pattern % ( split_by , quote , quote , quote , quote ) return regexp