merge _codecs into 2and3 (#1228)

* merge _codecs into 1and3

* handle encoding maps correctly
This commit is contained in:
Jelle Zijlstra
2017-05-01 07:51:08 -07:00
committed by Matthias Kramm
parent 0728096541
commit 238c869965
3 changed files with 74 additions and 116 deletions

View File

@@ -1,55 +0,0 @@
"""Stub file for the '_codecs' module."""
from typing import Any, AnyStr, Callable, Tuple, Optional
import codecs
# For convenience:
_Handler = Callable[[Exception], Tuple[unicode, int]]
# Not exposed. In Python 2, this is defined in unicode.c:
class _EncodingMap(object):
def size(self) -> int: ...
def register(search_function: Callable[[str], Any]) -> None: ...
def register_error(errors: str, handler: _Handler) -> None: ...
def lookup(a: str) -> codecs.CodecInfo: ...
def lookup_error(a: str) -> _Handler: ...
def decode(obj: Any, encoding: str = ..., errors: str = ...) -> Any: ...
def encode(obj: Any, encoding: str = ..., errors: str = ...) -> Any: ...
def charmap_build(a: unicode) -> _EncodingMap: ...
def ascii_decode(data: AnyStr, errors: str = ...) -> Tuple[unicode, int]: ...
def ascii_encode(data: AnyStr, errors: str = ...) -> Tuple[str, int]: ...
def charbuffer_encode(data: AnyStr, errors: str = ...) -> Tuple[str, int]: ...
def charmap_decode(data: AnyStr, errors: str = ..., mapping: Optional[_EncodingMap] = ...) -> Tuple[unicode, int]: ...
def charmap_encode(data: AnyStr, errors: str, mapping: Optional[_EncodingMap] = ...) -> Tuple[str, int]: ...
def escape_decode(data: AnyStr, errors: str = ...) -> Tuple[unicode, int]: ...
def escape_encode(data: AnyStr, errors: str = ...) -> Tuple[str, int]: ...
def latin_1_decode(data: AnyStr, errors: str = ...) -> Tuple[unicode, int]: ...
def latin_1_encode(data: AnyStr, errors: str = ...) -> Tuple[str, int]: ...
def raw_unicode_escape_decode(data: AnyStr, errors: str = ...) -> Tuple[unicode, int]: ...
def raw_unicode_escape_encode(data: AnyStr, errors: str = ...) -> Tuple[str, int]: ...
def readbuffer_encode(data: AnyStr, errors: str = ...) -> Tuple[str, int]: ...
def unicode_escape_decode(data: AnyStr, errors: str = ...) -> Tuple[unicode, int]: ...
def unicode_escape_encode(data: AnyStr, errors: str = ...) -> Tuple[str, int]: ...
def unicode_internal_decode(data: AnyStr, errors: str = ...) -> Tuple[unicode, int]: ...
def unicode_internal_encode(data: AnyStr, errors: str = ...) -> Tuple[str, int]: ...
def utf_16_be_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_16_be_encode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_16_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_16_encode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_16_ex_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_16_le_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_16_le_encode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_32_be_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_32_be_encode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_32_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_32_encode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_32_ex_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_32_le_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_32_le_encode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_7_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_7_encode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_8_decode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[unicode, int]: ...
def utf_8_encode(data: AnyStr, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...

74
stdlib/2and3/_codecs.pyi Normal file
View File

@@ -0,0 +1,74 @@
"""Stub file for the '_codecs' module."""
import sys
from typing import Any, Callable, Tuple, Optional, Dict, Text, Union
import codecs
# For convenience:
_Handler = Callable[[Exception], Tuple[Text, int]]
_String = Union[bytes, str]
_Errors = Union[str, Text, None]
if sys.version_info < (3, 0):
_Decodable = Union[bytes, Text]
_Encodable = Union[bytes, Text]
else:
_Decodable = bytes
_Encodable = str
# This type is not exposed; it is defined in unicodeobject.c
class _EncodingMap(object):
def size(self) -> int: ...
_MapT = Union[Dict[int, int], _EncodingMap]
def register(search_function: Callable[[str], Any]) -> None: ...
def register_error(errors: Union[str, Text], handler: _Handler) -> None: ...
def lookup(encoding: Union[str, Text]) -> codecs.CodecInfo: ...
def lookup_error(name: Union[str, Text]) -> _Handler: ...
def decode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ...
def encode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ...
def charmap_build(map: Text) -> _MapT: ...
def ascii_decode(data: _Decodable, errors: _Errors = ...) -> Tuple[Text, int]: ...
def ascii_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def charbuffer_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def charmap_decode(data: _Decodable, errors: _Errors = ..., mapping: Optional[_MapT] = ...) -> Tuple[Text, int]: ...
def charmap_encode(data: _Encodable, errors: _Errors, mapping: Optional[_MapT] = ...) -> Tuple[bytes, int]: ...
def escape_decode(data: _String, errors: _Errors = ...) -> Tuple[str, int]: ...
def escape_encode(data: bytes, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def latin_1_decode(data: _Decodable, errors: _Errors = ...) -> Tuple[Text, int]: ...
def latin_1_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def raw_unicode_escape_decode(data: _String, errors: _Errors = ...) -> Tuple[Text, int]: ...
def raw_unicode_escape_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def readbuffer_encode(data: _String, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def unicode_escape_decode(data: _String, errors: _Errors = ...) -> Tuple[Text, int]: ...
def unicode_escape_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def unicode_internal_decode(data: _String, errors: _Errors = ...) -> Tuple[Text, int]: ...
def unicode_internal_encode(data: _String, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_16_be_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def utf_16_be_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_16_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def utf_16_encode(data: _Encodable, errors: _Errors = ..., byteorder: int = ...) -> Tuple[bytes, int]: ...
def utf_16_ex_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int, int]: ...
def utf_16_le_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def utf_16_le_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_32_be_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def utf_32_be_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_32_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def utf_32_encode(data: _Encodable, errors: _Errors = ..., byteorder: int = ...) -> Tuple[bytes, int]: ...
def utf_32_ex_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int, int]: ...
def utf_32_le_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def utf_32_le_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_7_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def utf_7_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_8_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def utf_8_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
if sys.platform == 'win32':
def mbcs_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def mbcs_encode(str: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ...
if sys.version_info >= (3, 0):
def oem_decode(data: bytes, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def code_page_decode(codepage: int, data: bytes, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ...
def oem_encode(str: Text, errors: _Errors = ...) -> Tuple[bytes, int]: ...
def code_page_encode(code_page: int, str: Text, errors: _Errors = ...) -> Tuple[bytes, int]: ...

View File

@@ -1,61 +0,0 @@
"""Stub file for the '_codecs' module."""
import sys
from typing import Any, Callable, Tuple, Optional, Dict, Union
import codecs
# For convenience:
_Handler = Callable[[Exception], Tuple[str, int]]
_String = Union[bytes, str]
def register(search_function: Callable[[str], Any]) -> None: ...
def register_error(errors: str, handler: _Handler) -> None: ...
def lookup(encoding: str) -> codecs.CodecInfo: ...
def lookup_error(name: str) -> _Handler: ...
def decode(obj: Any, encoding: str = ..., errors: str = ...) -> Any: ...
def encode(obj: Any, encoding: str = ..., errors: str = ...) -> Any: ...
def charmap_build(map: str) -> Dict[int, int]: ...
def ascii_decode(data: bytes, errors: str = ...) -> Tuple[str, int]: ...
def ascii_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def charbuffer_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def charmap_decode(data: bytes, errors: str = ..., mapping: Optional[Dict[int, int]] = ...) -> Tuple[str, int]: ...
def charmap_encode(data: str, errors: str, mapping: Optional[Dict[int, int]] = ...) -> Tuple[bytes, int]: ...
def escape_decode(data: _String, errors: str = ...) -> Tuple[str, int]: ...
def escape_encode(data: bytes, errors: str = ...) -> Tuple[bytes, int]: ...
def latin_1_decode(data: bytes, errors: str = ...) -> Tuple[str, int]: ...
def latin_1_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def raw_unicode_escape_decode(data: _String, errors: str = ...) -> Tuple[str, int]: ...
def raw_unicode_escape_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def readbuffer_encode(data: _String, errors: str = ...) -> Tuple[bytes, int]: ...
def unicode_escape_decode(data: _String, errors: str = ...) -> Tuple[str, int]: ...
def unicode_escape_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def unicode_internal_decode(data: _String, errors: str = ...) -> Tuple[str, int]: ...
def unicode_internal_encode(data: _String, errors: str = ...) -> Tuple[bytes, int]: ...
def utf_16_be_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_16_be_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def utf_16_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_16_encode(data: str, errors: str = ..., byteorder: int = ...) -> Tuple[bytes, int]: ...
def utf_16_ex_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int, int]: ...
def utf_16_le_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_16_le_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def utf_32_be_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_32_be_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def utf_32_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_32_encode(data: str, errors: str = ..., byteorder: int = ...) -> Tuple[bytes, int]: ...
def utf_32_ex_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int, int]: ...
def utf_32_le_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_32_le_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def utf_7_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_7_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def utf_8_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def utf_8_encode(data: str, errors: str = ...) -> Tuple[bytes, int]: ...
if sys.platform == 'win32':
def mbcs_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def oem_decode(data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def code_page_decode(codepage: int, data: bytes, errors: str = ..., final: int = ...) -> Tuple[str, int]: ...
def mbcs_encode(str: str, errors: str = ...) -> Tuple[bytes, int]: ...
def oem_encode(str: str, errors: str = ...) -> Tuple[bytes, int]: ...
def code_page_encode(code_page: int, str: str, errors: str = ...) -> Tuple[bytes, int]: ...