TechDebt - remove Py2 references (#5488)
This commit is contained in:
parent
d8a084b662
commit
72db853d08
@ -44,8 +44,7 @@ RnGfN8j8KLDVmWyTYMk8V+6j0LI4+4zFh2upqGMQHL3VFVFWBek6vCDWhB/b
|
|||||||
|
|
||||||
|
|
||||||
def datetime_to_epoch(date):
|
def datetime_to_epoch(date):
|
||||||
# As only Py3 has datetime.timestamp()
|
return date.timestamp()
|
||||||
return int((date - datetime.datetime(1970, 1, 1)).total_seconds())
|
|
||||||
|
|
||||||
|
|
||||||
class AWSValidationException(AWSError):
|
class AWSValidationException(AWSError):
|
||||||
@ -295,14 +294,11 @@ class CertBundle(BaseModel):
|
|||||||
self._chain = []
|
self._chain = []
|
||||||
|
|
||||||
for cert_armored in self.chain.split(b"-\n-"):
|
for cert_armored in self.chain.split(b"-\n-"):
|
||||||
# Would leave encoded but Py2 does not have raw binary strings
|
|
||||||
cert_armored = cert_armored.decode()
|
|
||||||
|
|
||||||
# Fix missing -'s on split
|
# Fix missing -'s on split
|
||||||
cert_armored = re.sub(r"^----B", "-----B", cert_armored)
|
cert_armored = re.sub(b"^----B", b"-----B", cert_armored)
|
||||||
cert_armored = re.sub(r"E----$", "E-----", cert_armored)
|
cert_armored = re.sub(b"E----$", b"E-----", cert_armored)
|
||||||
cert = cryptography.x509.load_pem_x509_certificate(
|
cert = cryptography.x509.load_pem_x509_certificate(
|
||||||
cert_armored.encode(), default_backend()
|
cert_armored, default_backend()
|
||||||
)
|
)
|
||||||
self._chain.append(cert)
|
self._chain.append(cert)
|
||||||
|
|
||||||
|
@ -159,8 +159,6 @@ class _DockerDataVolumeContext:
|
|||||||
|
|
||||||
|
|
||||||
def _zipfile_content(zipfile):
|
def _zipfile_content(zipfile):
|
||||||
# more hackery to handle unicode/bytes/str in python3 and python2 -
|
|
||||||
# argh!
|
|
||||||
try:
|
try:
|
||||||
to_unzip_code = base64.b64decode(bytes(zipfile, "utf-8"))
|
to_unzip_code = base64.b64decode(bytes(zipfile, "utf-8"))
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -37,9 +37,6 @@ class Dimension(object):
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __ne__(self, item): # Only needed on Py2; Py3 defines it implicitly
|
|
||||||
return self != item
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return self.name < other.name and self.value < other.name
|
return self.name < other.name and self.value < other.name
|
||||||
|
|
||||||
|
@ -51,8 +51,6 @@ class InvalidResourceTypeException(JsonRESTError):
|
|||||||
"'configurationRecorder.recordingGroup.resourceTypes' failed to satisfy constraint: "
|
"'configurationRecorder.recordingGroup.resourceTypes' failed to satisfy constraint: "
|
||||||
f"Member must satisfy constraint: [Member must satisfy enum value set: {good_list}]"
|
f"Member must satisfy constraint: [Member must satisfy enum value set: {good_list}]"
|
||||||
)
|
)
|
||||||
# For PY2:
|
|
||||||
message = str(message)
|
|
||||||
|
|
||||||
super().__init__("ValidationException", message)
|
super().__init__("ValidationException", message)
|
||||||
|
|
||||||
|
@ -248,11 +248,7 @@ def amz_crc32(f):
|
|||||||
if "status" in headers:
|
if "status" in headers:
|
||||||
headers["status"] = str(headers["status"])
|
headers["status"] = str(headers["status"])
|
||||||
|
|
||||||
try:
|
gen_amz_crc32(body, headers)
|
||||||
# Doesnt work on python2 for some odd unicode strings
|
|
||||||
gen_amz_crc32(body, headers)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return status, headers, body
|
return status, headers, body
|
||||||
|
|
||||||
@ -282,7 +278,7 @@ def amzn_request_id(f):
|
|||||||
# Update request ID in XML
|
# Update request ID in XML
|
||||||
try:
|
try:
|
||||||
body = re.sub(r"(?<=<RequestId>).*(?=<\/RequestId>)", request_id, body)
|
body = re.sub(r"(?<=<RequestId>).*(?=<\/RequestId>)", request_id, body)
|
||||||
except Exception: # Will just ignore if it cant work on bytes (which are str's on python2)
|
except Exception: # Will just ignore if it cant work
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return status, headers, body
|
return status, headers, body
|
||||||
|
@ -7,7 +7,6 @@ import uuid
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
|
|
||||||
from cryptography import x509
|
from cryptography import x509
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
@ -21,6 +20,7 @@ from moto.core.utils import (
|
|||||||
iso_8601_datetime_without_milliseconds,
|
iso_8601_datetime_without_milliseconds,
|
||||||
iso_8601_datetime_with_milliseconds,
|
iso_8601_datetime_with_milliseconds,
|
||||||
BackendDict,
|
BackendDict,
|
||||||
|
unix_time,
|
||||||
)
|
)
|
||||||
from moto.iam.policy_validation import (
|
from moto.iam.policy_validation import (
|
||||||
IAMPolicyDocumentValidator,
|
IAMPolicyDocumentValidator,
|
||||||
@ -329,9 +329,7 @@ class ManagedPolicy(Policy, CloudFormationModel):
|
|||||||
"version": "1.3",
|
"version": "1.3",
|
||||||
"configurationItemCaptureTime": str(self.create_date),
|
"configurationItemCaptureTime": str(self.create_date),
|
||||||
"configurationItemStatus": "OK",
|
"configurationItemStatus": "OK",
|
||||||
"configurationStateId": str(
|
"configurationStateId": str(int(unix_time())),
|
||||||
int(time.mktime(self.create_date.timetuple()))
|
|
||||||
), # PY2 and 3 compatible
|
|
||||||
"arn": "arn:aws:iam::{}:policy/{}".format(self.account_id, self.name),
|
"arn": "arn:aws:iam::{}:policy/{}".format(self.account_id, self.name),
|
||||||
"resourceType": "AWS::IAM::Policy",
|
"resourceType": "AWS::IAM::Policy",
|
||||||
"resourceId": self.id,
|
"resourceId": self.id,
|
||||||
@ -720,9 +718,7 @@ class Role(CloudFormationModel):
|
|||||||
"version": "1.3",
|
"version": "1.3",
|
||||||
"configurationItemCaptureTime": str(self.create_date),
|
"configurationItemCaptureTime": str(self.create_date),
|
||||||
"configurationItemStatus": "ResourceDiscovered",
|
"configurationItemStatus": "ResourceDiscovered",
|
||||||
"configurationStateId": str(
|
"configurationStateId": str(int(unix_time())),
|
||||||
int(time.mktime(self.create_date.timetuple()))
|
|
||||||
), # PY2 and 3 compatible
|
|
||||||
"arn": f"arn:aws:iam::{self.account_id}:role/{self.name}",
|
"arn": f"arn:aws:iam::{self.account_id}:role/{self.name}",
|
||||||
"resourceType": "AWS::IAM::Role",
|
"resourceType": "AWS::IAM::Role",
|
||||||
"resourceId": self.name,
|
"resourceId": self.name,
|
||||||
|
@ -11,7 +11,6 @@ import tempfile
|
|||||||
import threading
|
import threading
|
||||||
import pytz
|
import pytz
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import uuid
|
import uuid
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
@ -23,6 +22,7 @@ from moto.core import CloudWatchMetricProvider
|
|||||||
from moto.core.utils import (
|
from moto.core.utils import (
|
||||||
iso_8601_datetime_without_milliseconds_s3,
|
iso_8601_datetime_without_milliseconds_s3,
|
||||||
rfc_1123_datetime,
|
rfc_1123_datetime,
|
||||||
|
unix_time,
|
||||||
unix_time_millis,
|
unix_time_millis,
|
||||||
BackendDict,
|
BackendDict,
|
||||||
)
|
)
|
||||||
@ -1309,9 +1309,7 @@ class FakeBucket(CloudFormationModel):
|
|||||||
"version": "1.3",
|
"version": "1.3",
|
||||||
"configurationItemCaptureTime": str(self.creation_date),
|
"configurationItemCaptureTime": str(self.creation_date),
|
||||||
"configurationItemStatus": "ResourceDiscovered",
|
"configurationItemStatus": "ResourceDiscovered",
|
||||||
"configurationStateId": str(
|
"configurationStateId": str(int(unix_time())),
|
||||||
int(time.mktime(self.creation_date.timetuple()))
|
|
||||||
), # PY2 and 3 compatible
|
|
||||||
"configurationItemMD5Hash": "",
|
"configurationItemMD5Hash": "",
|
||||||
"arn": self.arn,
|
"arn": self.arn,
|
||||||
"resourceType": "AWS::S3::Bucket",
|
"resourceType": "AWS::S3::Bucket",
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import time
|
|
||||||
|
|
||||||
from boto3 import Session
|
from boto3 import Session
|
||||||
|
|
||||||
from moto.core.exceptions import InvalidNextTokenException
|
from moto.core.exceptions import InvalidNextTokenException
|
||||||
from moto.core.common_models import ConfigQueryModel
|
from moto.core.common_models import ConfigQueryModel
|
||||||
|
from moto.core.utils import unix_time
|
||||||
from moto.s3control import s3control_backends
|
from moto.s3control import s3control_backends
|
||||||
|
|
||||||
|
|
||||||
@ -135,9 +135,7 @@ class S3AccountPublicAccessBlockConfigQuery(ConfigQueryModel):
|
|||||||
"accountId": account_id,
|
"accountId": account_id,
|
||||||
"configurationItemCaptureTime": str(creation_time),
|
"configurationItemCaptureTime": str(creation_time),
|
||||||
"configurationItemStatus": "OK",
|
"configurationItemStatus": "OK",
|
||||||
"configurationStateId": str(
|
"configurationStateId": str(int(unix_time())),
|
||||||
int(time.mktime(creation_time.timetuple()))
|
|
||||||
), # PY2 and 3 compatible
|
|
||||||
"resourceType": "AWS::S3::AccountPublicAccessBlock",
|
"resourceType": "AWS::S3::AccountPublicAccessBlock",
|
||||||
"resourceId": account_id,
|
"resourceId": account_id,
|
||||||
"awsRegion": pab_region,
|
"awsRegion": pab_region,
|
||||||
|
@ -482,11 +482,6 @@ class Document(BaseModel):
|
|||||||
if document_format == "JSON":
|
if document_format == "JSON":
|
||||||
try:
|
try:
|
||||||
content_json = json.loads(content)
|
content_json = json.loads(content)
|
||||||
except ValueError:
|
|
||||||
# Python2
|
|
||||||
raise InvalidDocumentContent(
|
|
||||||
"The content for the document is not valid."
|
|
||||||
)
|
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
raise InvalidDocumentContent(
|
raise InvalidDocumentContent(
|
||||||
"The content for the document is not valid."
|
"The content for the document is not valid."
|
||||||
|
Loading…
Reference in New Issue
Block a user