We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`name` table decoding error
While using the following code:
```
for record in font['name'].names:
    if record.nameID == 1:
        print(record)
```
It gave an error for some of the Chinese fonts I have:
```
Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\fontTools\encodings\codecs.py", line 54, in decode
    assert errors == 'strict'
AssertionError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "d:\Desktop\coding\fontname\main.py", line 75, in <module>
    print(record)
  File "C:\Python39\lib\site-packages\fontTools\ttLib\tables\_n_a_m_e.py", line 414, in __str__
    return self.toStr(errors='backslashreplace')
  File "C:\Python39\lib\site-packages\fontTools\ttLib\tables\_n_a_m_e.py", line 460, in toUnicode
    string = tounicode(string, encoding=encoding, errors=errors)
  File "C:\Python39\lib\site-packages\fontTools\misc\py23.py", line 82, in tounicode
    return s.decode(encoding, errors)
AssertionError: decoding with 'x_mac_simp_chinese_ttx' codec failed (AssertionError: )
```
It seems to be stuck on this section (based on `ttx`):
```
    <namerecord nameID="1" platformID="3" platEncID="1" langID="0x804">
      汉仪彩云体简
    </namerecord>
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `Lib/fontTools/encodings/codecs.py`
Content:
```
1 """Extend the Python codecs module with a few encodings that are used in OpenType (name table)
2 but missing from Python.  See https://github.com/fonttools/fonttools/issues/236 for details."""
3 
4 from fontTools.misc.py23 import *
5 import codecs
6 import encodings
7 
8 class ExtendCodec(codecs.Codec):
9 
10 	def __init__(self, name, base_encoding, mapping):
11 		self.name = name
12 		self.base_encoding = base_encoding
13 		self.mapping = mapping
14 		self.reverse = {v:k for k,v in mapping.items()}
15 		self.max_len = max(len(v) for v in mapping.values())
16 		self.info = codecs.CodecInfo(name=self.name, encode=self.encode, decode=self.decode)
17 		codecs.register_error(name, self.error)
18 
19 	def encode(self, input, errors='strict'):
20 		assert errors == 'strict'
21 		#return codecs.encode(input, self.base_encoding, self.name), len(input)
22 
23 		# The above line could totally be all we needed, relying on the error
24 		# handling to replace the unencodable Unicode characters with our extended
25 		# byte sequences.
26 		#
27 		# However, there seems to be a design bug in Python (probably intentional):
28 		# the error handler for encoding is supposed to return a **Unicode** character,
29 		# that then needs to be encodable itself...  Ugh.
30 		#
31 		# So we implement what codecs.encode() should have been doing: which is expect
32 		# error handler to return bytes() to be added to the output.
33 		#
34 		# This seems to have been fixed in Python 3.3.  We should try using that and
35 		# use fallback only if that failed.
36 		# https://docs.python.org/3.3/library/codecs.html#codecs.register_error
37 
38 		length = len(input)
39 		out = b''
40 		while input:
41 			try:
42 				part = codecs.encode(input, self.base_encoding)
43 				out += part
44 				input = '' # All converted
45 			except UnicodeEncodeError as e:
46 				# Convert the correct part
47 				out += codecs.encode(input[:e.start], self.base_encoding)
48 				replacement, pos = self.error(e)
49 				out += replacement
50 				input = input[pos:]
51 		return out, length
52 
53 	def decode(self, input, errors='strict'):
54 		assert errors == 'strict'
55 		return codecs.decode(input, self.base_encoding, self.name), len(input)
56 
57 	def error(self, e):
58 		if isinstance(e, UnicodeDecodeError):
59 			for end in range(e.start + 1, e.end + 1):
60 				s = e.object[e.start:end]
61 				if s in self.mapping:
62 					return self.mapping[s], end
63 		elif isinstance(e, UnicodeEncodeError):
64 			for end in range(e.start + 1, e.start + self.max_len + 1):
65 				s = e.object[e.start:end]
66 				if s in self.reverse:
67 					return self.reverse[s], end
68 		e.encoding = self.name
69 		raise e
70 
71 
72 _extended_encodings = {
73 	"x_mac_japanese_ttx": ("shift_jis", {
74 					b"\xFC": unichr(0x007C),
75 					b"\x7E": unichr(0x007E),
76 					b"\x80": unichr(0x005C),
77 					b"\xA0": unichr(0x00A0),
78 					b"\xFD": unichr(0x00A9),
79 					b"\xFE": unichr(0x2122),
80 					b"\xFF": unichr(0x2026),
81 				}),
82 	"x_mac_trad_chinese_ttx": ("big5", {
83 					b"\x80": unichr(0x005C),
84 					b"\xA0": unichr(0x00A0),
85 					b"\xFD": unichr(0x00A9),
86 					b"\xFE": unichr(0x2122),
87 					b"\xFF": unichr(0x2026),
88 				}),
89 	"x_mac_korean_ttx": ("euc_kr", {
90 					b"\x80": unichr(0x00A0),
91 					b"\x81": unichr(0x20A9),
92 					b"\x82": unichr(0x2014),
93 					b"\x83": unichr(0x00A9),
94 					b"\xFE": unichr(0x2122),
95 					b"\xFF": unichr(0x2026),
96 				}),
97 	"x_mac_simp_chinese_ttx": ("gb2312", {
98 					b"\x80": unichr(0x00FC),
99 					b"\xA0": unichr(0x00A0),
100 					b"\xFD": unichr(0x00A9),
101 					b"\xFE": unichr(0x2122),
102 					b"\xFF": unichr(0x2026),
103 				}),
104 }
105 
106 _cache = {}
107 
108 def search_function(name):
109 	name = encodings.normalize_encoding(name) # Rather undocumented...
110 	if name in _extended_encodings:
111 		if name not in _cache:
112 			base_encoding, mapping = _extended_encodings[name]
113 			assert(name[-4:] == "_ttx")
114 			# Python 2 didn't have any of the encodings that we are implementing
115 			# in this file.  Python 3 added aliases for the East Asian ones, mapping
116 			# them "temporarily" to the same base encoding as us, with a comment
117 			# suggesting that full implementation will appear some time later.
118 			# As such, try the Python version of the x_mac_... first, if that is found,
119 			# use *that* as our base encoding.  This would make our encoding upgrade
120 			# to the full encoding when and if Python finally implements that.
121 			# http://bugs.python.org/issue24041
122 			base_encodings = [name[:-4], base_encoding]
123 			for base_encoding in base_encodings:
124 				try:
125 					codecs.lookup(base_encoding)
126 				except LookupError:
127 					continue
128 				_cache[name] = ExtendCodec(name, base_encoding, mapping)
129 				break
130 		return _cache[name].info
131 
132 	return None
133 
134 codecs.register(search_function)
135
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/Lib/fontTools/encodings/codecs.py b/Lib/fontTools/encodings/codecs.py
--- a/Lib/fontTools/encodings/codecs.py
+++ b/Lib/fontTools/encodings/codecs.py
@@ -16,43 +16,29 @@
 		self.info = codecs.CodecInfo(name=self.name, encode=self.encode, decode=self.decode)
 		codecs.register_error(name, self.error)
 
-	def encode(self, input, errors='strict'):
-		assert errors == 'strict'
-		#return codecs.encode(input, self.base_encoding, self.name), len(input)
-
-		# The above line could totally be all we needed, relying on the error
-		# handling to replace the unencodable Unicode characters with our extended
-		# byte sequences.
-		#
-		# However, there seems to be a design bug in Python (probably intentional):
-		# the error handler for encoding is supposed to return a **Unicode** character,
-		# that then needs to be encodable itself...  Ugh.
-		#
-		# So we implement what codecs.encode() should have been doing: which is expect
-		# error handler to return bytes() to be added to the output.
-		#
-		# This seems to have been fixed in Python 3.3.  We should try using that and
-		# use fallback only if that failed.
-		# https://docs.python.org/3.3/library/codecs.html#codecs.register_error
-
+	def _map(self, mapper, output_type, exc_type, input, errors):
+		base_error_handler = codecs.lookup_error(errors)
 		length = len(input)
-		out = b''
+		out = output_type()
 		while input:
+			# first try to use self.error as the error handler
 			try:
-				part = codecs.encode(input, self.base_encoding)
+				part = mapper(input, self.base_encoding, errors=self.name)
 				out += part
-				input = '' # All converted
-			except UnicodeEncodeError as e:
-				# Convert the correct part
-				out += codecs.encode(input[:e.start], self.base_encoding)
-				replacement, pos = self.error(e)
+				break  # All converted
+			except exc_type as e:
+				# else convert the correct part, handle error as requested and continue
+				out += mapper(input[:e.start], self.base_encoding, self.name)
+				replacement, pos = base_error_handler(e)
 				out += replacement
 				input = input[pos:]
 		return out, length
 
+	def encode(self, input, errors='strict'):
+		return self._map(codecs.encode, bytes, UnicodeEncodeError, input, errors)
+
 	def decode(self, input, errors='strict'):
-		assert errors == 'strict'
-		return codecs.decode(input, self.base_encoding, self.name), len(input)
+		return self._map(codecs.decode, str, UnicodeDecodeError, input, errors)
 
 	def error(self, e):
 		if isinstance(e, UnicodeDecodeError):

{"golden_diff": "diff --git a/Lib/fontTools/encodings/codecs.py b/Lib/fontTools/encodings/codecs.py\n--- a/Lib/fontTools/encodings/codecs.py\n+++ b/Lib/fontTools/encodings/codecs.py\n@@ -16,43 +16,29 @@\n \t\tself.info = codecs.CodecInfo(name=self.name, encode=self.encode, decode=self.decode)\n \t\tcodecs.register_error(name, self.error)\n \n-\tdef encode(self, input, errors='strict'):\n-\t\tassert errors == 'strict'\n-\t\t#return codecs.encode(input, self.base_encoding, self.name), len(input)\n-\n-\t\t# The above line could totally be all we needed, relying on the error\n-\t\t# handling to replace the unencodable Unicode characters with our extended\n-\t\t# byte sequences.\n-\t\t#\n-\t\t# However, there seems to be a design bug in Python (probably intentional):\n-\t\t# the error handler for encoding is supposed to return a **Unicode** character,\n-\t\t# that then needs to be encodable itself...  Ugh.\n-\t\t#\n-\t\t# So we implement what codecs.encode() should have been doing: which is expect\n-\t\t# error handler to return bytes() to be added to the output.\n-\t\t#\n-\t\t# This seems to have been fixed in Python 3.3.  We should try using that and\n-\t\t# use fallback only if that failed.\n-\t\t# https://docs.python.org/3.3/library/codecs.html#codecs.register_error\n-\n+\tdef _map(self, mapper, output_type, exc_type, input, errors):\n+\t\tbase_error_handler = codecs.lookup_error(errors)\n \t\tlength = len(input)\n-\t\tout = b''\n+\t\tout = output_type()\n \t\twhile input:\n+\t\t\t# first try to use self.error as the error handler\n \t\t\ttry:\n-\t\t\t\tpart = codecs.encode(input, self.base_encoding)\n+\t\t\t\tpart = mapper(input, self.base_encoding, errors=self.name)\n \t\t\t\tout += part\n-\t\t\t\tinput = '' # All converted\n-\t\t\texcept UnicodeEncodeError as e:\n-\t\t\t\t# Convert the correct part\n-\t\t\t\tout += codecs.encode(input[:e.start], self.base_encoding)\n-\t\t\t\treplacement, pos = self.error(e)\n+\t\t\t\tbreak  # All converted\n+\t\t\texcept exc_type as e:\n+\t\t\t\t# else convert the correct part, handle error as requested and continue\n+\t\t\t\tout += mapper(input[:e.start], self.base_encoding, self.name)\n+\t\t\t\treplacement, pos = base_error_handler(e)\n \t\t\t\tout += replacement\n \t\t\t\tinput = input[pos:]\n \t\treturn out, length\n \n+\tdef encode(self, input, errors='strict'):\n+\t\treturn self._map(codecs.encode, bytes, UnicodeEncodeError, input, errors)\n+\n \tdef decode(self, input, errors='strict'):\n-\t\tassert errors == 'strict'\n-\t\treturn codecs.decode(input, self.base_encoding, self.name), len(input)\n+\t\treturn self._map(codecs.decode, str, UnicodeDecodeError, input, errors)\n \n \tdef error(self, e):\n \t\tif isinstance(e, UnicodeDecodeError):\n", "issue": "`name` table decoding error\nWhile using the following code:\r\n```\r\nfor record in font['name'].names:\r\n    if record.nameID == 1:\r\n        print(record)\r\n```\r\nIt gave an error for some of the Chinese fonts I have:\r\n```\r\nTraceback (most recent call last):\r\n  File \"C:\\Python39\\lib\\site-packages\\fontTools\\encodings\\codecs.py\", line 54, in decode\r\n    assert errors == 'strict'\r\nAssertionError\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"d:\\Desktop\\coding\\fontname\\main.py\", line 75, in <module>\r\n    print(record)\r\n  File \"C:\\Python39\\lib\\site-packages\\fontTools\\ttLib\\tables\\_n_a_m_e.py\", line 414, in __str__\r\n    return self.toStr(errors='backslashreplace')\r\n  File \"C:\\Python39\\lib\\site-packages\\fontTools\\ttLib\\tables\\_n_a_m_e.py\", line 460, in toUnicode\r\n    string = tounicode(string, encoding=encoding, errors=errors)\r\n  File \"C:\\Python39\\lib\\site-packages\\fontTools\\misc\\py23.py\", line 82, in tounicode\r\n    return s.decode(encoding, errors)\r\nAssertionError: decoding with 'x_mac_simp_chinese_ttx' codec failed (AssertionError: )\r\n```\r\nIt seems to be stuck on this section (based on `ttx`):\r\n```\r\n    <namerecord nameID=\"1\" platformID=\"3\" platEncID=\"1\" langID=\"0x804\">\r\n      \u6c49\u4eea\u5f69\u4e91\u4f53\u7b80\r\n    </namerecord>\r\n```\n", "before_files": [{"content": "\"\"\"Extend the Python codecs module with a few encodings that are used in OpenType (name table)\nbut missing from Python.  See https://github.com/fonttools/fonttools/issues/236 for details.\"\"\"\n\nfrom fontTools.misc.py23 import *\nimport codecs\nimport encodings\n\nclass ExtendCodec(codecs.Codec):\n\n\tdef __init__(self, name, base_encoding, mapping):\n\t\tself.name = name\n\t\tself.base_encoding = base_encoding\n\t\tself.mapping = mapping\n\t\tself.reverse = {v:k for k,v in mapping.items()}\n\t\tself.max_len = max(len(v) for v in mapping.values())\n\t\tself.info = codecs.CodecInfo(name=self.name, encode=self.encode, decode=self.decode)\n\t\tcodecs.register_error(name, self.error)\n\n\tdef encode(self, input, errors='strict'):\n\t\tassert errors == 'strict'\n\t\t#return codecs.encode(input, self.base_encoding, self.name), len(input)\n\n\t\t# The above line could totally be all we needed, relying on the error\n\t\t# handling to replace the unencodable Unicode characters with our extended\n\t\t# byte sequences.\n\t\t#\n\t\t# However, there seems to be a design bug in Python (probably intentional):\n\t\t# the error handler for encoding is supposed to return a **Unicode** character,\n\t\t# that then needs to be encodable itself...  Ugh.\n\t\t#\n\t\t# So we implement what codecs.encode() should have been doing: which is expect\n\t\t# error handler to return bytes() to be added to the output.\n\t\t#\n\t\t# This seems to have been fixed in Python 3.3.  We should try using that and\n\t\t# use fallback only if that failed.\n\t\t# https://docs.python.org/3.3/library/codecs.html#codecs.register_error\n\n\t\tlength = len(input)\n\t\tout = b''\n\t\twhile input:\n\t\t\ttry:\n\t\t\t\tpart = codecs.encode(input, self.base_encoding)\n\t\t\t\tout += part\n\t\t\t\tinput = '' # All converted\n\t\t\texcept UnicodeEncodeError as e:\n\t\t\t\t# Convert the correct part\n\t\t\t\tout += codecs.encode(input[:e.start], self.base_encoding)\n\t\t\t\treplacement, pos = self.error(e)\n\t\t\t\tout += replacement\n\t\t\t\tinput = input[pos:]\n\t\treturn out, length\n\n\tdef decode(self, input, errors='strict'):\n\t\tassert errors == 'strict'\n\t\treturn codecs.decode(input, self.base_encoding, self.name), len(input)\n\n\tdef error(self, e):\n\t\tif isinstance(e, UnicodeDecodeError):\n\t\t\tfor end in range(e.start + 1, e.end + 1):\n\t\t\t\ts = e.object[e.start:end]\n\t\t\t\tif s in self.mapping:\n\t\t\t\t\treturn self.mapping[s], end\n\t\telif isinstance(e, UnicodeEncodeError):\n\t\t\tfor end in range(e.start + 1, e.start + self.max_len + 1):\n\t\t\t\ts = e.object[e.start:end]\n\t\t\t\tif s in self.reverse:\n\t\t\t\t\treturn self.reverse[s], end\n\t\te.encoding = self.name\n\t\traise e\n\n\n_extended_encodings = {\n\t\"x_mac_japanese_ttx\": (\"shift_jis\", {\n\t\t\t\t\tb\"\\xFC\": unichr(0x007C),\n\t\t\t\t\tb\"\\x7E\": unichr(0x007E),\n\t\t\t\t\tb\"\\x80\": unichr(0x005C),\n\t\t\t\t\tb\"\\xA0\": unichr(0x00A0),\n\t\t\t\t\tb\"\\xFD\": unichr(0x00A9),\n\t\t\t\t\tb\"\\xFE\": unichr(0x2122),\n\t\t\t\t\tb\"\\xFF\": unichr(0x2026),\n\t\t\t\t}),\n\t\"x_mac_trad_chinese_ttx\": (\"big5\", {\n\t\t\t\t\tb\"\\x80\": unichr(0x005C),\n\t\t\t\t\tb\"\\xA0\": unichr(0x00A0),\n\t\t\t\t\tb\"\\xFD\": unichr(0x00A9),\n\t\t\t\t\tb\"\\xFE\": unichr(0x2122),\n\t\t\t\t\tb\"\\xFF\": unichr(0x2026),\n\t\t\t\t}),\n\t\"x_mac_korean_ttx\": (\"euc_kr\", {\n\t\t\t\t\tb\"\\x80\": unichr(0x00A0),\n\t\t\t\t\tb\"\\x81\": unichr(0x20A9),\n\t\t\t\t\tb\"\\x82\": unichr(0x2014),\n\t\t\t\t\tb\"\\x83\": unichr(0x00A9),\n\t\t\t\t\tb\"\\xFE\": unichr(0x2122),\n\t\t\t\t\tb\"\\xFF\": unichr(0x2026),\n\t\t\t\t}),\n\t\"x_mac_simp_chinese_ttx\": (\"gb2312\", {\n\t\t\t\t\tb\"\\x80\": unichr(0x00FC),\n\t\t\t\t\tb\"\\xA0\": unichr(0x00A0),\n\t\t\t\t\tb\"\\xFD\": unichr(0x00A9),\n\t\t\t\t\tb\"\\xFE\": unichr(0x2122),\n\t\t\t\t\tb\"\\xFF\": unichr(0x2026),\n\t\t\t\t}),\n}\n\n_cache = {}\n\ndef search_function(name):\n\tname = encodings.normalize_encoding(name) # Rather undocumented...\n\tif name in _extended_encodings:\n\t\tif name not in _cache:\n\t\t\tbase_encoding, mapping = _extended_encodings[name]\n\t\t\tassert(name[-4:] == \"_ttx\")\n\t\t\t# Python 2 didn't have any of the encodings that we are implementing\n\t\t\t# in this file.  Python 3 added aliases for the East Asian ones, mapping\n\t\t\t# them \"temporarily\" to the same base encoding as us, with a comment\n\t\t\t# suggesting that full implementation will appear some time later.\n\t\t\t# As such, try the Python version of the x_mac_... first, if that is found,\n\t\t\t# use *that* as our base encoding.  This would make our encoding upgrade\n\t\t\t# to the full encoding when and if Python finally implements that.\n\t\t\t# http://bugs.python.org/issue24041\n\t\t\tbase_encodings = [name[:-4], base_encoding]\n\t\t\tfor base_encoding in base_encodings:\n\t\t\t\ttry:\n\t\t\t\t\tcodecs.lookup(base_encoding)\n\t\t\t\texcept LookupError:\n\t\t\t\t\tcontinue\n\t\t\t\t_cache[name] = ExtendCodec(name, base_encoding, mapping)\n\t\t\t\tbreak\n\t\treturn _cache[name].info\n\n\treturn None\n\ncodecs.register(search_function)\n", "path": "Lib/fontTools/encodings/codecs.py"}], "after_files": [{"content": "\"\"\"Extend the Python codecs module with a few encodings that are used in OpenType (name table)\nbut missing from Python.  See https://github.com/fonttools/fonttools/issues/236 for details.\"\"\"\n\nfrom fontTools.misc.py23 import *\nimport codecs\nimport encodings\n\nclass ExtendCodec(codecs.Codec):\n\n\tdef __init__(self, name, base_encoding, mapping):\n\t\tself.name = name\n\t\tself.base_encoding = base_encoding\n\t\tself.mapping = mapping\n\t\tself.reverse = {v:k for k,v in mapping.items()}\n\t\tself.max_len = max(len(v) for v in mapping.values())\n\t\tself.info = codecs.CodecInfo(name=self.name, encode=self.encode, decode=self.decode)\n\t\tcodecs.register_error(name, self.error)\n\n\tdef _map(self, mapper, output_type, exc_type, input, errors):\n\t\tbase_error_handler = codecs.lookup_error(errors)\n\t\tlength = len(input)\n\t\tout = output_type()\n\t\twhile input:\n\t\t\t# first try to use self.error as the error handler\n\t\t\ttry:\n\t\t\t\tpart = mapper(input, self.base_encoding, errors=self.name)\n\t\t\t\tout += part\n\t\t\t\tbreak  # All converted\n\t\t\texcept exc_type as e:\n\t\t\t\t# else convert the correct part, handle error as requested and continue\n\t\t\t\tout += mapper(input[:e.start], self.base_encoding, self.name)\n\t\t\t\treplacement, pos = base_error_handler(e)\n\t\t\t\tout += replacement\n\t\t\t\tinput = input[pos:]\n\t\treturn out, length\n\n\tdef encode(self, input, errors='strict'):\n\t\treturn self._map(codecs.encode, bytes, UnicodeEncodeError, input, errors)\n\n\tdef decode(self, input, errors='strict'):\n\t\treturn self._map(codecs.decode, str, UnicodeDecodeError, input, errors)\n\n\tdef error(self, e):\n\t\tif isinstance(e, UnicodeDecodeError):\n\t\t\tfor end in range(e.start + 1, e.end + 1):\n\t\t\t\ts = e.object[e.start:end]\n\t\t\t\tif s in self.mapping:\n\t\t\t\t\treturn self.mapping[s], end\n\t\telif isinstance(e, UnicodeEncodeError):\n\t\t\tfor end in range(e.start + 1, e.start + self.max_len + 1):\n\t\t\t\ts = e.object[e.start:end]\n\t\t\t\tif s in self.reverse:\n\t\t\t\t\treturn self.reverse[s], end\n\t\te.encoding = self.name\n\t\traise e\n\n\n_extended_encodings = {\n\t\"x_mac_japanese_ttx\": (\"shift_jis\", {\n\t\t\t\t\tb\"\\xFC\": unichr(0x007C),\n\t\t\t\t\tb\"\\x7E\": unichr(0x007E),\n\t\t\t\t\tb\"\\x80\": unichr(0x005C),\n\t\t\t\t\tb\"\\xA0\": unichr(0x00A0),\n\t\t\t\t\tb\"\\xFD\": unichr(0x00A9),\n\t\t\t\t\tb\"\\xFE\": unichr(0x2122),\n\t\t\t\t\tb\"\\xFF\": unichr(0x2026),\n\t\t\t\t}),\n\t\"x_mac_trad_chinese_ttx\": (\"big5\", {\n\t\t\t\t\tb\"\\x80\": unichr(0x005C),\n\t\t\t\t\tb\"\\xA0\": unichr(0x00A0),\n\t\t\t\t\tb\"\\xFD\": unichr(0x00A9),\n\t\t\t\t\tb\"\\xFE\": unichr(0x2122),\n\t\t\t\t\tb\"\\xFF\": unichr(0x2026),\n\t\t\t\t}),\n\t\"x_mac_korean_ttx\": (\"euc_kr\", {\n\t\t\t\t\tb\"\\x80\": unichr(0x00A0),\n\t\t\t\t\tb\"\\x81\": unichr(0x20A9),\n\t\t\t\t\tb\"\\x82\": unichr(0x2014),\n\t\t\t\t\tb\"\\x83\": unichr(0x00A9),\n\t\t\t\t\tb\"\\xFE\": unichr(0x2122),\n\t\t\t\t\tb\"\\xFF\": unichr(0x2026),\n\t\t\t\t}),\n\t\"x_mac_simp_chinese_ttx\": (\"gb2312\", {\n\t\t\t\t\tb\"\\x80\": unichr(0x00FC),\n\t\t\t\t\tb\"\\xA0\": unichr(0x00A0),\n\t\t\t\t\tb\"\\xFD\": unichr(0x00A9),\n\t\t\t\t\tb\"\\xFE\": unichr(0x2122),\n\t\t\t\t\tb\"\\xFF\": unichr(0x2026),\n\t\t\t\t}),\n}\n\n_cache = {}\n\ndef search_function(name):\n\tname = encodings.normalize_encoding(name) # Rather undocumented...\n\tif name in _extended_encodings:\n\t\tif name not in _cache:\n\t\t\tbase_encoding, mapping = _extended_encodings[name]\n\t\t\tassert(name[-4:] == \"_ttx\")\n\t\t\t# Python 2 didn't have any of the encodings that we are implementing\n\t\t\t# in this file.  Python 3 added aliases for the East Asian ones, mapping\n\t\t\t# them \"temporarily\" to the same base encoding as us, with a comment\n\t\t\t# suggesting that full implementation will appear some time later.\n\t\t\t# As such, try the Python version of the x_mac_... first, if that is found,\n\t\t\t# use *that* as our base encoding.  This would make our encoding upgrade\n\t\t\t# to the full encoding when and if Python finally implements that.\n\t\t\t# http://bugs.python.org/issue24041\n\t\t\tbase_encodings = [name[:-4], base_encoding]\n\t\t\tfor base_encoding in base_encodings:\n\t\t\t\ttry:\n\t\t\t\t\tcodecs.lookup(base_encoding)\n\t\t\t\texcept LookupError:\n\t\t\t\t\tcontinue\n\t\t\t\t_cache[name] = ExtendCodec(name, base_encoding, mapping)\n\t\t\t\tbreak\n\t\treturn _cache[name].info\n\n\treturn None\n\ncodecs.register(search_function)\n", "path": "Lib/fontTools/encodings/codecs.py"}]}