Return whether an API and profile being generated matches an element's profile - api - string naming the API to match - profile - string naming the profile to match - elem - Element which (may) have 'api' and 'profile' attributes to match to. If a tag is not present in th
(api, profile, elem)
| 33 | return False |
| 34 | |
| 35 | def matchAPIProfile(api, profile, elem): |
| 36 | """Return whether an API and profile |
| 37 | being generated matches an element's profile |
| 38 | |
| 39 | - api - string naming the API to match |
| 40 | - profile - string naming the profile to match |
| 41 | - elem - Element which (may) have 'api' and 'profile' |
| 42 | attributes to match to. |
| 43 | |
| 44 | If a tag is not present in the Element, the corresponding API |
| 45 | or profile always matches. |
| 46 | |
| 47 | Otherwise, the tag must exactly match the API or profile. |
| 48 | |
| 49 | Thus, if 'profile' = core: |
| 50 | |
| 51 | - `<remove>` with no attribute will match |
| 52 | - `<remove profile="core">` will match |
| 53 | - `<remove profile="compatibility">` will not match |
| 54 | |
| 55 | Possible match conditions: |
| 56 | |
| 57 | ``` |
| 58 | Requested Element |
| 59 | Profile Profile |
| 60 | --------- -------- |
| 61 | None None Always matches |
| 62 | 'string' None Always matches |
| 63 | None 'string' Does not match. Cannot generate multiple APIs |
| 64 | or profiles, so if an API/profile constraint |
| 65 | is present, it must be asked for explicitly. |
| 66 | 'string' 'string' Strings must match |
| 67 | ``` |
| 68 | |
| 69 | ** In the future, we will allow regexes for the attributes, |
| 70 | not just strings, so that `api="^(gl|gles2)"` will match. Even |
| 71 | this is not really quite enough, we might prefer something |
| 72 | like `"gl(core)|gles1(common-lite)"`.""" |
| 73 | # Match 'api', if present |
| 74 | elem_api = elem.get('api') |
| 75 | if elem_api: |
| 76 | if api is None: |
| 77 | raise UserWarning("No API requested, but 'api' attribute is present with value '" |
| 78 | + elem_api + "'") |
| 79 | elif api != elem_api: |
| 80 | # Requested API does not match attribute |
| 81 | return False |
| 82 | elem_profile = elem.get('profile') |
| 83 | if elem_profile: |
| 84 | if profile is None: |
| 85 | raise UserWarning("No profile requested, but 'profile' attribute is present with value '" |
| 86 | + elem_profile + "'") |
| 87 | elif profile != elem_profile: |
| 88 | # Requested profile does not match attribute |
| 89 | return False |
| 90 | return True |
| 91 | |
| 92 |
no test coverage detected