diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-03-02 23:31:26 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-03-02 23:31:26 (GMT) |
commit | f5b52246ed8a1191c3aa1da7d3c63bbe11aee020 (patch) | |
tree | dcac9a1daca7f583ff958cb61f73e9ed11b5564b /Parser/tokenizer.c | |
parent | 0663a1ed793c164fb11d3dd62bebc677e260891e (diff) | |
download | cpython-f5b52246ed8a1191c3aa1da7d3c63bbe11aee020.zip cpython-f5b52246ed8a1191c3aa1da7d3c63bbe11aee020.tar.gz cpython-f5b52246ed8a1191c3aa1da7d3c63bbe11aee020.tar.bz2 |
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r-- | Parser/tokenizer.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 3d52bed..c4f447d 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -715,6 +715,28 @@ PyTokenizer_FromString(const char *str) return tok; } +struct tok_state * +PyTokenizer_FromUTF8(const char *str) +{ + struct tok_state *tok = tok_new(); + if (tok == NULL) + return NULL; + tok->decoding_state = STATE_RAW; + tok->read_coding_spec = 1; + tok->enc = NULL; + tok->str = str; + tok->encoding = (char *)PyMem_MALLOC(6); + if (!tok->encoding) { + PyTokenizer_Free(tok); + return NULL; + } + strcpy(tok->encoding, "utf-8"); + + /* XXX: constify members. */ + tok->buf = tok->cur = tok->end = tok->inp = (char*)str; + return tok; +} + /* Set up tokenizer for file */ |