Skip to content

Commit a27e665

Browse files
committed
Initial commit
1 parent 46d7820 commit a27e665

12 files changed

+15099
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# boto3-type
1+
# boto3-type [WIP]
22
Pseudo type check for boto3 service resource instances

boto3_type/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
__author__ = "Jeremy Jacobs"
5+
__version__ = "0.0.1"
6+
7+
8+
from boto3_type import client
9+
from boto3_type import resource
10+
from boto3_type import s3

boto3_type/client.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import botocore
5+
6+
from .util import compare
7+
8+
9+
def istype(client, service_name):
10+
"""Return whether a client is an instance of the reference service name.
11+
12+
An iterable may be provided to check against multiple services. This is equivalent
13+
to ``istype(x, A) or istype(x, B)``.
14+
15+
Args:
16+
client: botocore.client.BaseClient
17+
service_name: str | iterable
18+
- the service client name(s)
19+
20+
Returns:
21+
bool
22+
"""
23+
24+
if isinstance(client, botocore.client.BaseClient):
25+
return compare(client.meta.service_model.service_name, service_name)
26+
return False

boto3_type/resource.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import boto3
5+
6+
from .util import compare
7+
8+
9+
def istype(resource, service_name):
10+
"""Return whether a resource service is an instance of the reference service name.
11+
12+
An iterable may be provided to check against multiple services. This is equivalent
13+
to ``istype(x, A) or istype(x, B)``.
14+
15+
Args:
16+
client: boto3.resources.base.ServiceResource
17+
service_name: str | iterable
18+
- the service client name(s)
19+
20+
Returns:
21+
bool
22+
"""
23+
24+
if isinstance(resource, boto3.resources.base.ServiceResource):
25+
return compare(resource.meta.service_name, service_name)
26+
return False

boto3_type/s3.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import boto3
5+
6+
from .util import compare
7+
8+
9+
def istype(subresource, name):
10+
"""Return whether an S3 subresource is an instance of the reference name.
11+
12+
An iterable may be provided to check against multiple services. This is equivalent
13+
to ``istype(x, A) or istype(x, B)``.
14+
15+
Args:
16+
client: boto3.resources.base.ServiceResource
17+
service_name: str | iterable
18+
- the subresource name(s)
19+
20+
Returns:
21+
bool
22+
"""
23+
if isinstance(subresource, boto3.resources.base.ServiceResource):
24+
return compare(subresource.meta.resource_model.name, name)
25+
return False

boto3_type/util.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
def compare(resource_service, service_names):
5+
6+
resource_service = resource_service.lower()
7+
8+
if isinstance(service_names, str):
9+
service_names = [service_names]
10+
11+
return any((resource_service == name.lower() for name in service_names))

0 commit comments

Comments
 (0)