# Path: pdfminer/encodingdb.py
# def name2unicode(name: str) -> str:
#     """Converts Adobe glyph names to Unicode numbers.
# 
#     In contrast to the specification, this raises a KeyError instead of return
#     an empty string when the key is unknown.
#     This way the caller must explicitly define what to do
#     when there is not a match.
# 
#     Reference:
#     https://github.com/adobe-type-tools/agl-specification#2-the-mapping
# 
#     :returns unicode character if name resembles something,
#     otherwise a KeyError
#     """
#     name = name.split(".")[0]
#     components = name.split("_")
# 
#     if len(components) > 1:
#         return "".join(map(name2unicode, components))
# 
#     else:
#         if name in glyphname2unicode:
#             return glyphname2unicode[name]
# 
#         elif name.startswith("uni"):
#             name_without_uni = name.strip("uni")
# 
#             if HEXADECIMAL.match(name_without_uni) and len(name_without_uni) % 4 == 0:
#                 unicode_digits = [
#                     int(name_without_uni[i : i + 4], base=16)
#                     for i in range(0, len(name_without_uni), 4)
#                 ]
#                 for digit in unicode_digits:
#                     raise_key_error_for_invalid_unicode(digit)
#                 characters = map(chr, unicode_digits)
#                 return "".join(characters)
# 
#         elif name.startswith("u"):
#             name_without_u = name.strip("u")
# 
#             if HEXADECIMAL.match(name_without_u) and 4 <= len(name_without_u) <= 6:
#                 unicode_digit = int(name_without_u, base=16)
#                 raise_key_error_for_invalid_unicode(unicode_digit)
#                 return chr(unicode_digit)
# 
#     raise KeyError(
#         'Could not convert unicode name "%s" to character because '
#         "it does not match specification" % name
#     )
# 
# class EncodingDB:
# 
#     std2unicode: Dict[int, str] = {}
#     mac2unicode: Dict[int, str] = {}
#     win2unicode: Dict[int, str] = {}
#     pdf2unicode: Dict[int, str] = {}
#     for (name, std, mac, win, pdf) in ENCODING:
#         c = name2unicode(name)
#         if std:
#             std2unicode[std] = c
#         if mac:
#             mac2unicode[mac] = c
#         if win:
#             win2unicode[win] = c
#         if pdf:
#             pdf2unicode[pdf] = c
# 
#     encodings = {
#         "StandardEncoding": std2unicode,
#         "MacRomanEncoding": mac2unicode,
#         "WinAnsiEncoding": win2unicode,
#         "PDFDocEncoding": pdf2unicode,
#     }
# 
#     @classmethod
#     def get_encoding(
#         cls, name: str, diff: Optional[Iterable[object]] = None
#     ) -> Dict[int, str]:
#         cid2unicode = cls.encodings.get(name, cls.std2unicode)
#         if diff:
#             cid2unicode = cid2unicode.copy()
#             cid = 0
#             for x in diff:
#                 if isinstance(x, int):
#                     cid = x
#                 elif isinstance(x, PSLiteral):
#                     try:
#                         cid2unicode[cid] = name2unicode(cast(str, x.name))
#                     except (KeyError, ValueError) as e:
#                         log.debug(str(e))
#                     cid += 1
#         return cid2unicode
# 
# Path: pdfminer/psparser.py
# class PSLiteral(PSObject):
# 
#     """A class that represents a PostScript literal.
# 
#     Postscript literals are used as identifiers, such as
#     variable names, property names and dictionary keys.
#     Literals are case sensitive and denoted by a preceding
#     slash sign (e.g. "/Name")
# 
#     Note: Do not create an instance of PSLiteral directly.
#     Always use PSLiteralTable.intern().
#     """
# 
#     NameType = Union[str, bytes]
# 
#     def __init__(self, name: NameType) -> None:
#         self.name = name
# 
#     def __repr__(self) -> str:
#         name = self.name
#         return "/%r" % name


import pytest
from pdfminer.encodingdb import name2unicode, EncodingDB
from pdfminer.psparser import PSLiteral
    and because it does not start with a 'u.'"""
    with pytest.raises(KeyError):
        name2unicode("foo")


def test_name2unicode_notdef():
    """The name ".notdef" is reduced to an empty string (step 1)
    and mapped to an empty string (step 3)"""
    with pytest.raises(KeyError):
        name2unicode(".notdef")


def test_name2unicode_pua_ogoneksmall():
    """ "
    Ogoneksmall" and "uniF6FB" both map to the string
    that corresponds to U+F6FB."""
    assert "\uF6FB" == name2unicode("Ogoneksmall")


def test_name2unicode_overflow_error():
    with pytest.raises(KeyError):
        name2unicode("226215240241240240240240")


def test_get_encoding_with_invalid_differences():
    """Invalid differences should be silently ignored

    Regression test for https://github.com/pdfminer/pdfminer.six/issues/385
    """
    invalid_differences = [PSLiteral("ubuntu"), PSLiteral("1234")]

# Path: pdfminer/encodingdb.py
# def name2unicode(name: str) -> str:
#     """Converts Adobe glyph names to Unicode numbers.
# 
#     In contrast to the specification, this raises a KeyError instead of return
#     an empty string when the key is unknown.
#     This way the caller must explicitly define what to do
#     when there is not a match.
# 
#     Reference:
#     https://github.com/adobe-type-tools/agl-specification#2-the-mapping
# 
#     :returns unicode character if name resembles something,
#     otherwise a KeyError
#     """
#     name = name.split(".")[0]
#     components = name.split("_")
# 
#     if len(components) > 1:
#         return "".join(map(name2unicode, components))
# 
#     else:
#         if name in glyphname2unicode:
#             return glyphname2unicode[name]
# 
#         elif name.startswith("uni"):
#             name_without_uni = name.strip("uni")
# 
#             if HEXADECIMAL.match(name_without_uni) and len(name_without_uni) % 4 == 0:
#                 unicode_digits = [
#                     int(name_without_uni[i : i + 4], base=16)
#                     for i in range(0, len(name_without_uni), 4)
#                 ]
#                 for digit in unicode_digits:
#                     raise_key_error_for_invalid_unicode(digit)
#                 characters = map(chr, unicode_digits)
#                 return "".join(characters)
# 
#         elif name.startswith("u"):
#             name_without_u = name.strip("u")
# 
#             if HEXADECIMAL.match(name_without_u) and 4 <= len(name_without_u) <= 6:
#                 unicode_digit = int(name_without_u, base=16)
#                 raise_key_error_for_invalid_unicode(unicode_digit)
#                 return chr(unicode_digit)
# 
#     raise KeyError(
#         'Could not convert unicode name "%s" to character because '
#         "it does not match specification" % name
#     )
# 
# class EncodingDB:
# 
#     std2unicode: Dict[int, str] = {}
#     mac2unicode: Dict[int, str] = {}
#     win2unicode: Dict[int, str] = {}
#     pdf2unicode: Dict[int, str] = {}
#     for (name, std, mac, win, pdf) in ENCODING:
#         c = name2unicode(name)
#         if std:
#             std2unicode[std] = c
#         if mac:
#             mac2unicode[mac] = c
#         if win:
#             win2unicode[win] = c
#         if pdf:
#             pdf2unicode[pdf] = c
# 
#     encodings = {
#         "StandardEncoding": std2unicode,
#         "MacRomanEncoding": mac2unicode,
#         "WinAnsiEncoding": win2unicode,
#         "PDFDocEncoding": pdf2unicode,
#     }
# 
#     @classmethod
#     def get_encoding(
#         cls, name: str, diff: Optional[Iterable[object]] = None
#     ) -> Dict[int, str]:
#         cid2unicode = cls.encodings.get(name, cls.std2unicode)
#         if diff:
#             cid2unicode = cid2unicode.copy()
#             cid = 0
#             for x in diff:
#                 if isinstance(x, int):
#                     cid = x
#                 elif isinstance(x, PSLiteral):
#                     try:
#                         cid2unicode[cid] = name2unicode(cast(str, x.name))
#                     except (KeyError, ValueError) as e:
#                         log.debug(str(e))
#                     cid += 1
#         return cid2unicode
# 
# Path: pdfminer/psparser.py
# class PSLiteral(PSObject):
# 
#     """A class that represents a PostScript literal.
# 
#     Postscript literals are used as identifiers, such as
#     variable names, property names and dictionary keys.
#     Literals are case sensitive and denoted by a preceding
#     slash sign (e.g. "/Name")
# 
#     Note: Do not create an instance of PSLiteral directly.
#     Always use PSLiteralTable.intern().
#     """
# 
#     NameType = Union[str, bytes]
# 
#     def __init__(self, name: NameType) -> None:
#         self.name = name
# 
#     def __repr__(self) -> str:
#         name = self.name
#         return "/%r" % name


# Path: tests/test_encodingdb.py
import pytest
from pdfminer.encodingdb import name2unicode, EncodingDB
from pdfminer.psparser import PSLiteral

    and because it does not start with a 'u.'"""
    with pytest.raises(KeyError):
        name2unicode("foo")


def test_name2unicode_notdef():
    """The name ".notdef" is reduced to an empty string (step 1)
    and mapped to an empty string (step 3)"""
    with pytest.raises(KeyError):
        name2unicode(".notdef")


def test_name2unicode_pua_ogoneksmall():
    """ "
    Ogoneksmall" and "uniF6FB" both map to the string
    that corresponds to U+F6FB."""
    assert "\uF6FB" == name2unicode("Ogoneksmall")


def test_name2unicode_overflow_error():
    with pytest.raises(KeyError):
        name2unicode("226215240241240240240240")


def test_get_encoding_with_invalid_differences():
    """Invalid differences should be silently ignored

    Regression test for https://github.com/pdfminer/pdfminer.six/issues/385
    """
    invalid_differences = [PSLiteral("ubuntu"), PSLiteral("1234")]

    EncodingDB.get_encoding("StandardEncoding", invalid_differences)