def tokenize(string): """ This function scans the entire message with a simple regex to find all Content-Types and boundaries. """ tokens = deque() for m in pattern.finditer(string): if m.group(CTYPE): name, token = parsing.parse_header(m.group(CTYPE)) else: token = Boundary( m.group(BOUNDARY).strip("\t\r\n"), grab_newline(m.start(), string, -1), grab_newline(m.end(), string, 1)) tokens.append(token) return setup_boundaries(tokens)
def tokenize(string): """ Scans the entire message to find all Content-Types and boundaries. """ tokens = deque() for m in _RE_TOKENIZER.finditer(string): if m.group(_CTYPE): name, token = parsing.parse_header(m.group(_CTYPE)) elif m.group(_BOUNDARY): token = Boundary(m.group(_BOUNDARY).strip("\t\r\n"), _grab_newline(m.start(), string, -1), _grab_newline(m.end(), string, 1)) else: token = _EMPTY_LINE tokens.append(token) return _filter_false_tokens(tokens)
def tokenize(string): """ Scans the entire message to find all Content-Types and boundaries. """ if not six.PY2 and isinstance(string, six.binary_type): string = string.decode('utf-8') tokens = deque() for m in _RE_TOKENIZER.finditer(string): if m.group(_CTYPE): name, token = parsing.parse_header(m.group(_CTYPE)) elif m.group(_BOUNDARY): token = Boundary(m.group(_BOUNDARY).strip('\t\r\n'), _grab_newline(m.start(), string, -1), _grab_newline(m.end(), string, 1)) else: token = _EMPTY_LINE tokens.append(token) return _filter_false_tokens(tokens)
def tokenize(string): """ Scans the entire message to find all Content-Types and boundaries. """ if not six.PY2 and isinstance(string, six.binary_type): string = string.decode('utf-8') tokens = deque() for m in _RE_TOKENIZER.finditer(string): if m.group(_CTYPE): name, token = parsing.parse_header(m.group(_CTYPE)) elif m.group(_BOUNDARY): token = Boundary( m.group(_BOUNDARY).strip('\t\r\n'), _grab_newline(m.start(), string, -1), _grab_newline(m.end(), string, 1)) else: token = _EMPTY_LINE tokens.append(token) return _filter_false_tokens(tokens)
def test_content_type_star(): _, ctype = parsing.parse_header('Content-Type: image/* ; name="Stuart *Wells.PNG"') eq_(ctype.value, "image/*")
def test_content_type_star(): _, ctype = parsing.parse_header('Content-Type: image/* ; name="Stuart *Wells.PNG"') eq_(ctype.value, 'image/*')