Organisations - Backport re.fullmatch for Py2 (#3990)
This commit is contained in:
parent
9e4972b43f
commit
74559f2a91
@ -657,13 +657,13 @@ class OrganizationsBackend(BaseBackend):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _get_resource_for_tagging(self, resource_id):
|
def _get_resource_for_tagging(self, resource_id):
|
||||||
if re.compile(utils.OU_ID_REGEX).fullmatch(resource_id) or re.fullmatch(
|
if utils.fullmatch(
|
||||||
utils.ROOT_ID_REGEX, resource_id
|
re.compile(utils.OU_ID_REGEX), resource_id
|
||||||
):
|
) or utils.fullmatch(utils.ROOT_ID_REGEX, resource_id):
|
||||||
resource = next((a for a in self.ou if a.id == resource_id), None)
|
resource = next((a for a in self.ou if a.id == resource_id), None)
|
||||||
elif re.compile(utils.ACCOUNT_ID_REGEX).fullmatch(resource_id):
|
elif utils.fullmatch(re.compile(utils.ACCOUNT_ID_REGEX), resource_id):
|
||||||
resource = next((a for a in self.accounts if a.id == resource_id), None)
|
resource = next((a for a in self.accounts if a.id == resource_id), None)
|
||||||
elif re.compile(utils.POLICY_ID_REGEX).fullmatch(resource_id):
|
elif utils.fullmatch(re.compile(utils.POLICY_ID_REGEX), resource_id):
|
||||||
resource = next((a for a in self.policies if a.id == resource_id), None)
|
resource = next((a for a in self.policies if a.id == resource_id), None)
|
||||||
else:
|
else:
|
||||||
raise InvalidInputException(
|
raise InvalidInputException(
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
import string
|
import string
|
||||||
from moto.core import ACCOUNT_ID
|
from moto.core import ACCOUNT_ID
|
||||||
|
|
||||||
@ -84,3 +85,10 @@ def make_random_policy_id():
|
|||||||
# from 8 to 128 lower-case letters or digits.
|
# from 8 to 128 lower-case letters or digits.
|
||||||
# e.g. 'p-k2av4a8a'
|
# e.g. 'p-k2av4a8a'
|
||||||
return "p-" + "".join(random.choice(CHARSET) for x in range(POLICY_ID_SIZE))
|
return "p-" + "".join(random.choice(CHARSET) for x in range(POLICY_ID_SIZE))
|
||||||
|
|
||||||
|
|
||||||
|
def fullmatch(regex, s, flags=0):
|
||||||
|
"""Emulate python-3.4 re.fullmatch()."""
|
||||||
|
m = re.match(regex, s, flags=flags)
|
||||||
|
if m and m.span()[1] == len(s):
|
||||||
|
return m
|
||||||
|
Loading…
Reference in New Issue
Block a user