@@ -142,104 +142,67 @@ async def validate_license(
142142 if valid_from .tzinfo is None :
143143 valid_from = valid_from .replace (tzinfo = UTC )
144144 if now < valid_from :
145- raise LicenseNotYetValidError (
146- f"License is not valid until { license .valid_from .isoformat ()} ."
147- )
145+ raise LicenseNotYetValidError (f"License is not valid until { license .valid_from .isoformat ()} ." )
148146
149147 if license .expires_at is not None :
150148 expires_at = license .expires_at
151149 if expires_at .tzinfo is None :
152150 expires_at = expires_at .replace (tzinfo = UTC )
153151 if now > expires_at :
154- raise LicenseExpiredError (
155- f"License expired on { license .expires_at .isoformat ()} ."
156- )
152+ raise LicenseExpiredError (f"License expired on { license .expires_at .isoformat ()} ." )
157153
158154 # 3. Version policy
159155 if license .version_policy == VersionPolicy .MAINTENANCE :
160156 if app_version is None :
161- raise LicenseVersionError (
162- "app_version is required for maintenance license validation."
163- )
157+ raise LicenseVersionError ("app_version is required for maintenance license validation." )
164158 app_major = _parse_version (app_version )[0 ]
165159 if license .major_version != app_major :
166160 raise LicenseVersionError (
167- f"License covers major version { license .major_version } , "
168- f"but the application is version { app_version } ."
161+ f"License covers major version { license .major_version } , but the application is version { app_version } ."
169162 )
170163 elif license .version_policy == VersionPolicy .SPECIFIC :
171164 if app_version is None :
172- raise LicenseVersionError (
173- "app_version is required for specific-version license validation."
174- )
165+ raise LicenseVersionError ("app_version is required for specific-version license validation." )
175166 if license .locked_version != app_version :
176167 raise LicenseVersionError (
177- f"License is locked to version { license .locked_version } , "
178- f"but the application is version { app_version } ."
168+ f"License is locked to version { license .locked_version } , but the application is version { app_version } ."
179169 )
180170
181171 # 4. Entitlement matching
182172 matched : Entitlement | None = None
183173
184174 if license .entitlements :
185175 if app_id is None :
186- raise LicenseAppError (
187- "This license restricts access by application. "
188- "Provide app_id to validate."
189- )
176+ raise LicenseAppError ("This license restricts access by application. Provide app_id to validate." )
190177
191178 for ent in license .entitlements :
192179 if ent .app_id == app_id :
193180 matched = ent
194181 break
195182
196183 if matched is None :
197- raise LicenseAppError (
198- f"This license does not cover application '{ app_id } '."
199- )
184+ raise LicenseAppError (f"This license does not cover application '{ app_id } '." )
200185
201186 # 5. Effective edition check
202187 # Entitlement editions override license-level; None on either = no restriction.
203- eff_editions = (
204- matched .editions
205- if (matched is not None and matched .editions is not None )
206- else license .editions
207- )
188+ eff_editions = matched .editions if (matched is not None and matched .editions is not None ) else license .editions
208189 if eff_editions is not None and (edition is None or edition .lower () not in eff_editions ):
209- raise LicenseEditionError (
210- f"Edition '{ edition } ' is not permitted. "
211- f"Allowed editions: { ', ' .join (eff_editions )} ."
212- )
190+ raise LicenseEditionError (f"Edition '{ edition } ' is not permitted. Allowed editions: { ', ' .join (eff_editions )} ." )
213191
214192 # 6. Effective platform check (same fallback logic)
215- eff_platforms = (
216- matched .platforms
217- if (matched is not None and matched .platforms is not None )
218- else license .platforms
219- )
193+ eff_platforms = matched .platforms if (matched is not None and matched .platforms is not None ) else license .platforms
220194 if eff_platforms is not None and (platform is None or platform .lower () not in eff_platforms ):
221- raise LicenseOSError (
222- f"Platform '{ platform } ' is not permitted. "
223- f"Allowed platforms: { ', ' .join (eff_platforms )} ."
224- )
195+ raise LicenseOSError (f"Platform '{ platform } ' is not permitted. Allowed platforms: { ', ' .join (eff_platforms )} ." )
225196
226197 # 7. Entitlement version range (per-app, complements the license-level version policy)
227198 if matched is not None :
228199 if app_version is not None :
229200 parsed = _parse_version (app_version )
230201 if matched .min_version is not None and parsed < _parse_version (matched .min_version ):
231- raise LicenseVersionError (
232- f"App version { app_version } is below the minimum "
233- f"required version { matched .min_version } ."
234- )
202+ raise LicenseVersionError (f"App version { app_version } is below the minimum required version { matched .min_version } ." )
235203 if matched .max_version is not None and parsed > _parse_version (matched .max_version ):
236- raise LicenseVersionError (
237- f"App version { app_version } exceeds the maximum "
238- f"covered version { matched .max_version } ."
239- )
204+ raise LicenseVersionError (f"App version { app_version } exceeds the maximum covered version { matched .max_version } ." )
240205 elif matched .min_version is not None or matched .max_version is not None :
241- raise LicenseVersionError (
242- "app_version is required to validate a version-restricted entitlement."
243- )
206+ raise LicenseVersionError ("app_version is required to validate a version-restricted entitlement." )
244207
245208 return matched
0 commit comments