Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kjd/idna
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.1
Choose a base ref
...
head repository: kjd/idna
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.2
Choose a head ref
  • 5 commits
  • 13 files changed
  • 4 contributors

Commits on Jan 19, 2021

  1. Add type stubs (#94)

    sethmlarson authored Jan 19, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2b16336 View commit details

Commits on Jan 20, 2021

  1. Partially verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
    Copy the full SHA
    f7cfd0e View commit details

Commits on Jan 21, 2021

  1. Merge pull request #95 from jayaddison/tools-dir-pyupgrade

    Apply pyupgrade to the tools directory
    kjd authored Jan 21, 2021
    Copy the full SHA
    a9e4f73 View commit details

Commits on Jan 29, 2021

  1. Move types into source, drop Python 3.4 (#96)

    * Move types into source, drop Python 3.4
    * Make number_type Optional[str]
    sethmlarson authored Jan 29, 2021
    Copy the full SHA
    b0ef4bf View commit details

Commits on May 29, 2021

  1. Release v3.2

    kjd committed May 29, 2021
    Copy the full SHA
    9879123 View commit details
Showing with 248 additions and 79 deletions.
  1. +9 −2 .travis.yml
  2. +6 −0 HISTORY.rst
  3. +1 −0 MANIFEST.in
  4. +43 −1 idna/__init__.py
  5. +19 −12 idna/codec.py
  6. +4 −0 idna/compat.py
  7. +54 −41 idna/core.py
  8. +5 −0 idna/intranges.py
  9. +1 −1 idna/package_data.py
  10. 0 idna/py.typed
  11. +83 −1 idna/uts46data.py
  12. +3 −2 setup.py
  13. +20 −19 tools/idna-data
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -3,19 +3,26 @@ arch:
- amd64
- ppc64le
python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "pypy3"
# Disable unsuported version pypy for ppc64le
# Disable unsupported version pypy for ppc64le
jobs:
exclude:
- arch: ppc64le
python: pypy3

matrix:
include:
- python: 3.9
install:
- pip install mypy
script:
- mypy --strict idna/

install:
- pip install .
script:
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -3,6 +3,12 @@
History
-------

3.2 (2021-05-29)
++++++++++++++++

- Add type hints (Thanks, Seth Michael Larson!)
- Remove support for Python 3.4

3.1 (2021-01-04)
++++++++++++++++

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include *.rst
include LICENSE.md
include idna/py.typed
recursive-include tools *
recursive-exclude tools *.pyc
recursive-include tests *
44 changes: 43 additions & 1 deletion idna/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
from .package_data import __version__
from .core import *
from .core import (
IDNABidiError,
IDNAError,
InvalidCodepoint,
InvalidCodepointContext,
alabel,
check_bidi,
check_hyphen_ok,
check_initial_combiner,
check_label,
check_nfc,
decode,
encode,
ulabel,
uts46_remap,
valid_contextj,
valid_contexto,
valid_label_length,
valid_string_length,
)
from .intranges import intranges_contain

__all__ = [
"IDNABidiError",
"IDNAError",
"InvalidCodepoint",
"InvalidCodepointContext",
"alabel",
"check_bidi",
"check_hyphen_ok",
"check_initial_combiner",
"check_label",
"check_nfc",
"decode",
"encode",
"intranges_contain",
"ulabel",
"uts46_remap",
"valid_contextj",
"valid_contexto",
"valid_label_length",
"valid_string_length",
]
31 changes: 19 additions & 12 deletions idna/codec.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from .core import encode, decode, alabel, ulabel, IDNAError
import codecs
import re
from typing import Tuple, Optional

_unicode_dots_re = re.compile('[\u002e\u3002\uff0e\uff61]')

class Codec(codecs.Codec):

def encode(self, data, errors='strict'):

# type: (str, str) -> Tuple[bytes, int]
if errors != 'strict':
raise IDNAError('Unsupported error handling \"{}\"'.format(errors))

if not data:
return "", 0
return b"", 0

return encode(data), len(data)

def decode(self, data, errors='strict'):

# type: (bytes, str) -> Tuple[str, int]
if errors != 'strict':
raise IDNAError('Unsupported error handling \"{}\"'.format(errors))

@@ -27,12 +28,13 @@ def decode(self, data, errors='strict'):
return decode(data), len(data)

class IncrementalEncoder(codecs.BufferedIncrementalEncoder):
def _buffer_encode(self, data, errors, final):
def _buffer_encode(self, data, errors, final): # type: ignore
# type: (str, str, bool) -> Tuple[str, int]
if errors != 'strict':
raise IDNAError('Unsupported error handling \"{}\"'.format(errors))

if not data:
return ('', 0)
return "", 0

labels = _unicode_dots_re.split(data)
trailing_dot = ''
@@ -55,12 +57,13 @@ def _buffer_encode(self, data, errors, final):
size += len(label)

# Join with U+002E
result = '.'.join(result) + trailing_dot
result_str = '.'.join(result) + trailing_dot # type: ignore
size += len(trailing_dot)
return (result, size)
return result_str, size

class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
def _buffer_decode(self, data, errors, final):
def _buffer_decode(self, data, errors, final): # type: ignore
# type: (str, str, bool) -> Tuple[str, int]
if errors != 'strict':
raise IDNAError('Unsupported error handling \"{}\"'.format(errors))

@@ -87,22 +90,26 @@ def _buffer_decode(self, data, errors, final):
size += 1
size += len(label)

result = '.'.join(result) + trailing_dot
result_str = '.'.join(result) + trailing_dot
size += len(trailing_dot)
return (result, size)
return (result_str, size)


class StreamWriter(Codec, codecs.StreamWriter):
pass


class StreamReader(Codec, codecs.StreamReader):
pass


def getregentry():
# type: () -> codecs.CodecInfo
# Compatibility as a search_function for codecs.register()
return codecs.CodecInfo(
name='idna',
encode=Codec().encode,
decode=Codec().decode,
encode=Codec().encode, # type: ignore
decode=Codec().decode, # type: ignore
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamwriter=StreamWriter,
4 changes: 4 additions & 0 deletions idna/compat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from .core import *
from .codec import *
from typing import Any, Union

def ToASCII(label):
# type: (str) -> bytes
return encode(label)

def ToUnicode(label):
# type: (Union[bytes, bytearray]) -> str
return decode(label)

def nameprep(s):
# type: (Any) -> None
raise NotImplementedError('IDNA 2008 does not utilise nameprep protocol')

Loading