@@ -120,76 +120,53 @@ def build_page(element: ET.Element, byte: str, dct: dict, depth: int = 0):
120
120
build_page (sheet , "" , self .sheet )
121
121
return sheet
122
122
123
- def with_tokens (self , * ,
124
- version : OsVersion = None , tokens : Tokens = None , file = None ,
125
- lang : str = 'en' , strict : bool = False ) -> 'TokenIDESheet' :
123
+ def for_version (self , * , version : OsVersion = None , lang : str = 'en' ) -> 'TokenIDESheet' :
126
124
"""
127
- Constructs a copy of this sheet updated with the specified token data from the token sheets
125
+ Constructs a copy of this sheet tailored to a given OS version
128
126
129
127
If a token is entirely absent, its accessible name is used as its string value.
130
128
Metadata is always preserved.
131
129
132
- :param version: A minimum OS version to target (defaults to latest)
133
- :param tokens: A Tokens container of tokens to add (defaults to all tokens)
134
- :param file: A file object to read tokens from (defaults to the 8X token sheet)
130
+ :param version: The OS version to target (defaults to latest)
135
131
:param lang: A language code (defaults to "en")
136
- :param strict: Whether to remove tokens not present in the targeted version (default to False)
137
- :return: A TokenIDESheet containing the union of this sheet and the specified token data
132
+ :return: A TokenIDESheet supporting the given version with this sheet's metadata attached
138
133
"""
139
134
140
- sheet = self .sheet .copy ()
141
- if strict :
142
- sheet ["tokens" ] = {}
135
+ sheet = {"meta" : self .sheet ["meta" ].copy (), "tokens" : {}}
143
136
144
- if tokens is None :
145
- if file is None :
146
- with open (os .path .join (os .path .dirname (__file__ ), "../8X.xml" ), encoding = "UTF-8" ) as file :
147
- tokens = Tokens .from_xml_string (file .read (), version or OsVersions .LATEST )
137
+ with open (os .path .join (os .path .dirname (__file__ ), "../8X.xml" ), encoding = "UTF-8" ) as file :
138
+ tokens = Tokens .from_xml_string (file .read (), version or OsVersions .LATEST )
148
139
149
- else :
150
- tokens = Tokens .from_xml_string (file .read (), version or OsVersions .LATEST )
151
-
152
- all_bytes = tokens .bytes
153
-
154
- all_names = [name for token in all_bytes .values ()
155
- for name in [* token .langs .get (lang , "en" ).names (), token .langs .get (lang , "en" ).display ]]
156
-
157
- for byte , token in all_bytes .items ():
140
+ for byte , token in tokens .bytes .items ():
158
141
if version is not None and token .since > version :
159
142
continue
160
143
161
144
leading , trailing = byte [:1 ], byte [1 :]
162
145
163
- old = self .sheet .copy ()["tokens" ]
164
146
new = sheet ["tokens" ]
165
-
147
+ attrib = self . sheet [ "tokens" ]. copy ()
166
148
value = f"${ leading .hex ().upper ()} "
149
+
167
150
if value not in new :
168
- new [value ] = old .get (value , {"string" : None , "variants" : set (), "attrib" : {}, "tokens" : {}})
169
- if strict :
170
- new [value ]["tokens" ] = {}
151
+ new [value ] = {"string" : None , "variants" : set (), "attrib" : {}, "tokens" : {}}
171
152
172
153
if trailing :
173
- old = old [value ]["tokens" ]
154
+ attrib = attrib [value ]["tokens" ]
174
155
new = new [value ]["tokens" ]
175
156
value = f"${ trailing .hex ().upper ()} "
176
157
177
- new [value ] = old . get ( value , {"string" : None , "variants" : set (), "attrib" : {}, "tokens" : {}})
158
+ new [value ] = {"string" : None , "variants" : set (), "attrib" : {}, "tokens" : {}}
178
159
179
160
translation = token .langs .get (lang , "en" )
180
161
display = translation .display
181
162
182
163
if new [value ]["string" ] not in [* translation .names (), display ]:
183
164
new [value ]["string" ] = translation .accessible
184
165
185
- new [value ]["variants" ] |= {name for name in translation .names () if all_names .count (name ) == 1 }
186
-
187
- string = new [value ]["string" ]
188
- if string not in display and display not in string and all_names .count (display ) == 1 :
189
- new [value ]["variants" ].add (display )
190
-
191
- new [value ]["variants" ] -= {string }
166
+ new [value ]["variants" ] |= {* translation .names ()}
167
+ new [value ]["variants" ] -= {new [value ]["string" ]}
192
168
169
+ new [value ]["attrib" ] |= attrib .get (value , {}).get ("attrib" , {})
193
170
if byte in TokenIDESheet .STARTERS :
194
171
new [value ]["attrib" ]["stringStarter" ] = "true"
195
172
0 commit comments