byteplus-sdk 1.0.62__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- byteplus_sdk/ApiInfo.py +13 -0
- byteplus_sdk/Credentials.py +15 -0
- byteplus_sdk/Policy.py +91 -0
- byteplus_sdk/ServiceInfo.py +11 -0
- byteplus_sdk/ServiceInfoHttps.py +11 -0
- byteplus_sdk/__init__.py +2 -0
- byteplus_sdk/auth/MetaData.py +29 -0
- byteplus_sdk/auth/SignerV4.py +145 -0
- byteplus_sdk/auth/__init__.py +0 -0
- byteplus_sdk/base/Request.py +51 -0
- byteplus_sdk/base/Service.py +227 -0
- byteplus_sdk/base/__init__.py +0 -0
- byteplus_sdk/base/models/__init__.py +0 -0
- byteplus_sdk/base/models/base/__init__.py +0 -0
- byteplus_sdk/base/models/base/base_pb2.py +46 -0
- byteplus_sdk/cdn/__init__.py +0 -0
- byteplus_sdk/cdn/service.py +1203 -0
- byteplus_sdk/const/Const.py +66 -0
- byteplus_sdk/const/__init__.py +0 -0
- byteplus_sdk/example/__init__.py +1 -0
- byteplus_sdk/example/cdn/__init__.py +3 -0
- byteplus_sdk/example/cdn/add_cdn_certificate.py +27 -0
- byteplus_sdk/example/cdn/add_cdn_domain.py +35 -0
- byteplus_sdk/example/cdn/add_template_domain.py +26 -0
- byteplus_sdk/example/cdn/create_cipher_template.py +25 -0
- byteplus_sdk/example/cdn/create_rule_engine_template.py +161 -0
- byteplus_sdk/example/cdn/create_service_template.py +41 -0
- byteplus_sdk/example/cdn/delete_cdn_domain.py +19 -0
- byteplus_sdk/example/cdn/delete_template.py +20 -0
- byteplus_sdk/example/cdn/describe_accounting_data.py +24 -0
- byteplus_sdk/example/cdn/describe_cdn_access_log.py +23 -0
- byteplus_sdk/example/cdn/describe_cdn_config.py +19 -0
- byteplus_sdk/example/cdn/describe_cdn_data.py +29 -0
- byteplus_sdk/example/cdn/describe_cdn_data_detail.py +25 -0
- byteplus_sdk/example/cdn/describe_cdn_detail.py +26 -0
- byteplus_sdk/example/cdn/describe_cdn_origin_data.py +24 -0
- byteplus_sdk/example/cdn/describe_cdn_region_and_isp.py +19 -0
- byteplus_sdk/example/cdn/describe_cdn_service.py +15 -0
- byteplus_sdk/example/cdn/describe_cdn_upper_ip.py +19 -0
- byteplus_sdk/example/cdn/describe_cipher_template.py +20 -0
- byteplus_sdk/example/cdn/describe_content_block_tasks.py +23 -0
- byteplus_sdk/example/cdn/describe_content_quota.py +14 -0
- byteplus_sdk/example/cdn/describe_content_tasks.py +21 -0
- byteplus_sdk/example/cdn/describe_edge_nrt_data_summary.py +23 -0
- byteplus_sdk/example/cdn/describe_edge_statistical_data.py +24 -0
- byteplus_sdk/example/cdn/describe_edge_top_nrt_data.py +25 -0
- byteplus_sdk/example/cdn/describe_edge_top_statistical_data.py +25 -0
- byteplus_sdk/example/cdn/describe_edge_top_status_code.py +22 -0
- byteplus_sdk/example/cdn/describe_ip_info.py +19 -0
- byteplus_sdk/example/cdn/describe_ip_list_info.py +20 -0
- byteplus_sdk/example/cdn/describe_origin_nrt_data_summary.py +23 -0
- byteplus_sdk/example/cdn/describe_origin_top_nrt_data.py +24 -0
- byteplus_sdk/example/cdn/describe_origin_top_status_code.py +22 -0
- byteplus_sdk/example/cdn/describe_rule_engine_template.py +23 -0
- byteplus_sdk/example/cdn/describe_service_template.py +20 -0
- byteplus_sdk/example/cdn/describe_template_domains.py +22 -0
- byteplus_sdk/example/cdn/describe_templates.py +30 -0
- byteplus_sdk/example/cdn/duplicate_template.py +23 -0
- byteplus_sdk/example/cdn/list_cdn_cert_info.py +19 -0
- byteplus_sdk/example/cdn/list_cdn_domains.py +19 -0
- byteplus_sdk/example/cdn/list_cert_info.py +20 -0
- byteplus_sdk/example/cdn/lock_template.py +20 -0
- byteplus_sdk/example/cdn/release_template.py +23 -0
- byteplus_sdk/example/cdn/start_cdn_domain.py +19 -0
- byteplus_sdk/example/cdn/stop_cdn_domain.py +19 -0
- byteplus_sdk/example/cdn/submit_block_task.py +18 -0
- byteplus_sdk/example/cdn/submit_preload_task.py +18 -0
- byteplus_sdk/example/cdn/submit_refresh_task.py +19 -0
- byteplus_sdk/example/cdn/submit_unblock_task.py +18 -0
- byteplus_sdk/example/cdn/update_cdn_config.py +34 -0
- byteplus_sdk/example/cdn/update_cipher_template.py +48 -0
- byteplus_sdk/example/cdn/update_rule_engine_template.py +62 -0
- byteplus_sdk/example/cdn/update_service_template.py +42 -0
- byteplus_sdk/example/cdn/update_template_domain.py +29 -0
- byteplus_sdk/example/live/__init__.py +0 -0
- byteplus_sdk/example/rtc/RtcService.py +53 -0
- byteplus_sdk/example/rtc/__init__.py +0 -0
- byteplus_sdk/example/rtc/example_get_record_task.py +25 -0
- byteplus_sdk/example/rtc/example_start_record.py +86 -0
- byteplus_sdk/example/visual/__init__.py +0 -0
- byteplus_sdk/example/visual/cv_cancel_task.py +19 -0
- byteplus_sdk/example/visual/cv_get_result.py +19 -0
- byteplus_sdk/example/visual/cv_process.py +20 -0
- byteplus_sdk/example/visual/cv_submit_task.py +19 -0
- byteplus_sdk/example/visual/cv_sync2async_get_result.py +20 -0
- byteplus_sdk/example/visual/cv_sync2async_submit_task.py +20 -0
- byteplus_sdk/example/visual/example_common.py +32 -0
- byteplus_sdk/iam/IamService.py +42 -0
- byteplus_sdk/iam/__init__.py +0 -0
- byteplus_sdk/live/LiveService.py +571 -0
- byteplus_sdk/live/__init__.py +1 -0
- byteplus_sdk/live/v20200801/__init__.py +1 -0
- byteplus_sdk/live/v20200801/live_config.py +18 -0
- byteplus_sdk/live/v20200801/live_service.py +12 -0
- byteplus_sdk/live/v20200801/live_trait.py +62 -0
- byteplus_sdk/live/v20230101/__init__.py +1 -0
- byteplus_sdk/live/v20230101/live_config.py +171 -0
- byteplus_sdk/live/v20230101/live_service.py +12 -0
- byteplus_sdk/live/v20230101/live_trait.py +1133 -0
- byteplus_sdk/sms/SmsService.py +158 -0
- byteplus_sdk/sms/__init__.py +0 -0
- byteplus_sdk/util/Functions.py +37 -0
- byteplus_sdk/util/Util.py +116 -0
- byteplus_sdk/util/__init__.py +0 -0
- byteplus_sdk/visual/VisualService.py +142 -0
- byteplus_sdk/visual/__init__.py +0 -0
- byteplus_sdk/vod/VodService.py +2941 -0
- byteplus_sdk/vod/VodServiceConfig.py +134 -0
- byteplus_sdk/vod/__init__.py +0 -0
- byteplus_sdk/vod/models/__init__.py +0 -0
- byteplus_sdk/vod/models/business/__init__.py +0 -0
- byteplus_sdk/vod/models/business/vod_apps_manage_pb2.py +35 -0
- byteplus_sdk/vod/models/business/vod_callback_pb2.py +32 -0
- byteplus_sdk/vod/models/business/vod_cdn_pb2.py +434 -0
- byteplus_sdk/vod/models/business/vod_common_pb2.py +342 -0
- byteplus_sdk/vod/models/business/vod_edit_pb2.py +55 -0
- byteplus_sdk/vod/models/business/vod_measure_pb2.py +395 -0
- byteplus_sdk/vod/models/business/vod_media_pb2.py +547 -0
- byteplus_sdk/vod/models/business/vod_play_pb2.py +95 -0
- byteplus_sdk/vod/models/business/vod_project_pb2.py +45 -0
- byteplus_sdk/vod/models/business/vod_quality_platform_pb2.py +46 -0
- byteplus_sdk/vod/models/business/vod_smart_strategy_pb2.py +53 -0
- byteplus_sdk/vod/models/business/vod_space_pb2.py +63 -0
- byteplus_sdk/vod/models/business/vod_upload_pb2.py +344 -0
- byteplus_sdk/vod/models/business/vod_workflow_pb2.py +389 -0
- byteplus_sdk/vod/models/request/__init__.py +0 -0
- byteplus_sdk/vod/models/request/request_vod_pb2.py +1250 -0
- byteplus_sdk/vod/models/response/__init__.py +0 -0
- byteplus_sdk/vod/models/response/response_vod_pb2.py +1199 -0
- byteplus_sdk-1.0.62.dist-info/METADATA +24 -0
- byteplus_sdk-1.0.62.dist-info/RECORD +134 -0
- byteplus_sdk-1.0.62.dist-info/WHEEL +5 -0
- byteplus_sdk-1.0.62.dist-info/licenses/LICENSE +201 -0
- byteplus_sdk-1.0.62.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# coding:utf-8
|
|
2
|
+
import json
|
|
3
|
+
import threading
|
|
4
|
+
|
|
5
|
+
from byteplus_sdk.ApiInfo import ApiInfo
|
|
6
|
+
from byteplus_sdk.Credentials import Credentials
|
|
7
|
+
from byteplus_sdk.base.Service import Service
|
|
8
|
+
from byteplus_sdk.ServiceInfoHttps import ServiceInfoHttps
|
|
9
|
+
from byteplus_sdk.const.Const import *
|
|
10
|
+
from retry import retry
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SmsService(Service):
|
|
14
|
+
_instance_lock = threading.Lock()
|
|
15
|
+
|
|
16
|
+
def __new__(cls, *args, **kwargs):
|
|
17
|
+
if not hasattr(SmsService, "_instance"):
|
|
18
|
+
with SmsService._instance_lock:
|
|
19
|
+
if not hasattr(SmsService, "_instance"):
|
|
20
|
+
SmsService._instance = object.__new__(cls)
|
|
21
|
+
return SmsService._instance
|
|
22
|
+
|
|
23
|
+
def __init__(self, region=REGION_CN_NORTH1):
|
|
24
|
+
self.service_info = SmsService.get_service_info(self, region)
|
|
25
|
+
self.api_info = SmsService.get_api_info()
|
|
26
|
+
super(SmsService, self).__init__(self.service_info, self.api_info)
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def get_service_info(self, region):
|
|
30
|
+
if region == REGION_AP_SINGAPORE1:
|
|
31
|
+
service_info = ServiceInfoHttps("sms.byteplusapi.com", {'Accept': 'application/json'},
|
|
32
|
+
Credentials('', '', 'volcSMS', region), 5, 5)
|
|
33
|
+
else:
|
|
34
|
+
service_info = ServiceInfoHttps("sms.volcengineapi.com", {'Accept': 'application/json'},
|
|
35
|
+
Credentials('', '', 'volcSMS', region), 5, 5)
|
|
36
|
+
return service_info
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def get_api_info():
|
|
40
|
+
api_info = {
|
|
41
|
+
"SendSms": ApiInfo("POST", "/", {"Action": "SendSms", "Version": "2020-01-01"}, {}, {}),
|
|
42
|
+
"SendSmsVerifyCode": ApiInfo("POST", "/", {"Action": "SendSmsVerifyCode", "Version": "2020-01-01"}, {}, {}),
|
|
43
|
+
"CheckSmsVerifyCode": ApiInfo("POST", "/", {"Action": "CheckSmsVerifyCode", "Version": "2020-01-01"}, {},
|
|
44
|
+
{}),
|
|
45
|
+
"SendBatchSms": ApiInfo("POST", "/", {"Action": "SendBatchSms", "Version": "2021-01-01"}, {}, {}),
|
|
46
|
+
"Conversion": ApiInfo("POST", "/", {"Action": "Conversion", "Version": "2020-01-01"}, {}, {}),
|
|
47
|
+
"GetSmsTemplateAndOrderList": ApiInfo("GET", "/",
|
|
48
|
+
{"Action": "GetSmsTemplateAndOrderList", "Version": "2021-01-11"}, {},
|
|
49
|
+
{}),
|
|
50
|
+
"ApplySmsTemplate": ApiInfo("POST", "/", {"Action": "ApplySmsTemplate", "Version": "2021-01-11"}, {}, {}),
|
|
51
|
+
"DeleteSmsTemplate": ApiInfo("POST", "/", {"Action": "DeleteSmsTemplate", "Version": "2021-01-11"}, {}, {}),
|
|
52
|
+
"GetSubAccountList": ApiInfo("GET", "/", {"Action": "GetSubAccountList", "Version": "2021-01-11"}, {}, {}),
|
|
53
|
+
"GetSubAccountDetail": ApiInfo("GET", "/", {"Action": "GetSubAccountDetail", "Version": "2021-01-11"}, {},
|
|
54
|
+
{}),
|
|
55
|
+
"InsertSubAccount": ApiInfo("POST", "/", {"Action": "InsertSubAccount", "Version": "2021-01-11"},
|
|
56
|
+
{},
|
|
57
|
+
{}),
|
|
58
|
+
}
|
|
59
|
+
return api_info
|
|
60
|
+
|
|
61
|
+
@retry(tries=2, delay=0)
|
|
62
|
+
def send_sms(self, body):
|
|
63
|
+
res = self.json('SendSms', {}, body)
|
|
64
|
+
if res == '':
|
|
65
|
+
raise Exception("empty response")
|
|
66
|
+
res_json = json.loads(res)
|
|
67
|
+
|
|
68
|
+
return res_json
|
|
69
|
+
|
|
70
|
+
@retry(tries=2, delay=0)
|
|
71
|
+
def send_batch_sms(self, body):
|
|
72
|
+
res = self.json('SendBatchSms', {}, body)
|
|
73
|
+
if res == '':
|
|
74
|
+
raise Exception("empty response")
|
|
75
|
+
res_json = json.loads(res)
|
|
76
|
+
|
|
77
|
+
return res_json
|
|
78
|
+
|
|
79
|
+
@retry(tries=2, delay=0)
|
|
80
|
+
def conversion(self, body):
|
|
81
|
+
res = self.json('Conversion', {}, body)
|
|
82
|
+
if res == '':
|
|
83
|
+
raise Exception("empty response")
|
|
84
|
+
res_json = json.loads(res)
|
|
85
|
+
|
|
86
|
+
return res_json
|
|
87
|
+
|
|
88
|
+
@retry(tries=2, delay=0)
|
|
89
|
+
def send_sms_verify_code(self, body):
|
|
90
|
+
res = self.json('SendSmsVerifyCode', {}, body)
|
|
91
|
+
if res == '':
|
|
92
|
+
raise Exception("empty response")
|
|
93
|
+
res_json = json.loads(res)
|
|
94
|
+
|
|
95
|
+
return res_json
|
|
96
|
+
|
|
97
|
+
@retry(tries=2, delay=0)
|
|
98
|
+
def check_sms_verify_code(self, body):
|
|
99
|
+
res = self.json('CheckSmsVerifyCode', {}, body)
|
|
100
|
+
if res == '':
|
|
101
|
+
raise Exception("empty response")
|
|
102
|
+
res_json = json.loads(res)
|
|
103
|
+
|
|
104
|
+
return res_json
|
|
105
|
+
|
|
106
|
+
@retry(tries=2, delay=0)
|
|
107
|
+
def get_sms_template_and_order_list(self, body):
|
|
108
|
+
res = self.json('GetSmsTemplateAndOrderList', {}, body)
|
|
109
|
+
if res == '':
|
|
110
|
+
raise Exception("empty response")
|
|
111
|
+
res_json = json.loads(res)
|
|
112
|
+
|
|
113
|
+
return res_json
|
|
114
|
+
|
|
115
|
+
@retry(tries=2, delay=0)
|
|
116
|
+
def apply_sms_template(self, body):
|
|
117
|
+
res = self.json('ApplySmsTemplate', {}, body)
|
|
118
|
+
if res == '':
|
|
119
|
+
raise Exception("empty response")
|
|
120
|
+
res_json = json.loads(res)
|
|
121
|
+
|
|
122
|
+
return res_json
|
|
123
|
+
|
|
124
|
+
@retry(tries=2, delay=0)
|
|
125
|
+
def delete_sms_template(self, body):
|
|
126
|
+
res = self.json('DeleteSmsTemplate', {}, body)
|
|
127
|
+
if res == '':
|
|
128
|
+
raise Exception("empty response")
|
|
129
|
+
res_json = json.loads(res)
|
|
130
|
+
|
|
131
|
+
return res_json
|
|
132
|
+
|
|
133
|
+
@retry(tries=2, delay=0)
|
|
134
|
+
def get_sub_account_list(self, param):
|
|
135
|
+
res = self.json('GetSubAccountList', param, {})
|
|
136
|
+
if res == '':
|
|
137
|
+
raise Exception("empty response")
|
|
138
|
+
res_json = json.loads(res)
|
|
139
|
+
|
|
140
|
+
return res_json
|
|
141
|
+
|
|
142
|
+
@retry(tries=2, delay=0)
|
|
143
|
+
def get_sub_account_detail(self, param):
|
|
144
|
+
res = self.json('GetSubAccountDetail', param, {})
|
|
145
|
+
if res == '':
|
|
146
|
+
raise Exception("empty response")
|
|
147
|
+
res_json = json.loads(res)
|
|
148
|
+
|
|
149
|
+
return res_json
|
|
150
|
+
|
|
151
|
+
@retry(tries=2, delay=0)
|
|
152
|
+
def insert_sms_sub_account(self, body):
|
|
153
|
+
res = self.json('InsertSubAccount', {}, body)
|
|
154
|
+
if res == '':
|
|
155
|
+
raise Exception("empty response")
|
|
156
|
+
res_json = json.loads(res)
|
|
157
|
+
|
|
158
|
+
return res_json
|
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class Function:
|
|
2
|
+
@staticmethod
|
|
3
|
+
def get_meta_func():
|
|
4
|
+
return {'Name': 'GetMeta'}
|
|
5
|
+
|
|
6
|
+
@staticmethod
|
|
7
|
+
def get_snapshot_func(snapshot_time):
|
|
8
|
+
return {'Name': 'Snapshot', 'Input': {'SnapshotTime': snapshot_time}}
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
def get_add_option_info_func(title, tags, description):
|
|
12
|
+
return {'Name': 'AddOptionInfo', 'Input': {'Title': title, 'Tags': tags, 'Description': description}}
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def get_add_material_option_info_func(title, tags, description, category, record_type, format_input):
|
|
16
|
+
return {'Name': 'AddOptionInfo',
|
|
17
|
+
'Input': {'Title': title, 'Tags': tags, 'Description': description, 'Category': category,
|
|
18
|
+
'RecordType': record_type, 'Format': format_input}}
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def get_start_workflow_func(template_id):
|
|
22
|
+
return {'Name': 'StartWorkflow', 'Input': {'TemplateId': template_id}}
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def get_caption_func(title, format, vid, fid, language, source, tag, action_type, store_uri, auto_publish=False):
|
|
26
|
+
return {'Name': 'CaptionUpload',
|
|
27
|
+
'Input': {'Title': title, 'Format': format, 'Vid': vid, 'Fid': fid, 'Language': language,
|
|
28
|
+
'Source': source, 'Tag': tag, 'ActionType': action_type, 'StoreUri': store_uri,
|
|
29
|
+
'AutoPublish': auto_publish}}
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def get_start_batch_workflow_func(template_ids):
|
|
33
|
+
return {'Name': 'StartWorkflow', 'Input': {'TemplateIds': template_ids}}
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def get_encryption_func(conf, policy):
|
|
37
|
+
return {'Name': 'Encryption', 'Input': {'Config': conf, 'PolicyParams': policy}}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# coding:utf-8
|
|
2
|
+
import base64
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
import random
|
|
6
|
+
import sys
|
|
7
|
+
import uuid
|
|
8
|
+
from functools import reduce
|
|
9
|
+
|
|
10
|
+
from Crypto.Cipher import AES
|
|
11
|
+
|
|
12
|
+
from byteplus_sdk.const.Const import LETTER_RUNES
|
|
13
|
+
from zlib import crc32
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from urllib import quote
|
|
17
|
+
except:
|
|
18
|
+
from urllib.parse import quote
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Util(object):
|
|
22
|
+
@staticmethod
|
|
23
|
+
def norm_uri(path):
|
|
24
|
+
return quote(path).replace('%2F', '/').replace('+', '%20')
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def norm_query(params):
|
|
28
|
+
query = ''
|
|
29
|
+
for key in sorted(params.keys()):
|
|
30
|
+
if type(params[key]) == list:
|
|
31
|
+
for k in params[key]:
|
|
32
|
+
query = query + quote(str(key), safe='-_.~') + '=' + quote(str(k), safe='-_.~') + '&'
|
|
33
|
+
else:
|
|
34
|
+
query = query + quote(str(key), safe='-_.~') + '=' + quote(str(params[key]), safe='-_.~') + '&'
|
|
35
|
+
query = query[:-1]
|
|
36
|
+
return query.replace('+', '%20')
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def hmac_sha256(key, content):
|
|
40
|
+
# type(key) == <class 'bytes'>
|
|
41
|
+
if sys.version_info[0] == 3:
|
|
42
|
+
return hmac.new(key, bytes(content, encoding='utf-8'), hashlib.sha256).digest()
|
|
43
|
+
else:
|
|
44
|
+
return hmac.new(key, content, hashlib.sha256).digest()
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def hmac_sha1(key, content):
|
|
48
|
+
# type(key) == <class 'bytes'>
|
|
49
|
+
if sys.version_info[0] == 3:
|
|
50
|
+
return hmac.new(key, bytes(content, encoding='utf-8'), hashlib.sha1).digest()
|
|
51
|
+
else:
|
|
52
|
+
return hmac.new(key, content, hashlib.sha1).digest()
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def sha256(content):
|
|
56
|
+
# type(content) == <class 'str'>
|
|
57
|
+
return hashlib.sha256(content.encode('utf-8')).hexdigest()
|
|
58
|
+
|
|
59
|
+
@staticmethod
|
|
60
|
+
def to_hex(content):
|
|
61
|
+
lst = []
|
|
62
|
+
for ch in content:
|
|
63
|
+
if sys.version_info[0] == 3:
|
|
64
|
+
hv = hex(ch).replace('0x', '')
|
|
65
|
+
else:
|
|
66
|
+
hv = hex(ord(ch)).replace('0x', '')
|
|
67
|
+
if len(hv) == 1:
|
|
68
|
+
hv = '0' + hv
|
|
69
|
+
lst.append(hv)
|
|
70
|
+
return reduce(lambda x, y: x + y, lst)
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def pad(plain_text):
|
|
74
|
+
block_size = AES.block_size
|
|
75
|
+
|
|
76
|
+
number_of_bytes_to_pad = block_size - len(plain_text) % block_size
|
|
77
|
+
ascii_string = chr(0)
|
|
78
|
+
padding_str = number_of_bytes_to_pad * ascii_string
|
|
79
|
+
padded_plain_text = plain_text + padding_str
|
|
80
|
+
return padded_plain_text
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def generate_access_key_id(prefix):
|
|
84
|
+
uid = str(uuid.uuid4())
|
|
85
|
+
uid_base64 = base64.b64encode(uid.replace('-', '').encode(encoding='utf-8'))
|
|
86
|
+
|
|
87
|
+
s = uid_base64.decode().replace('=', '').replace('/', '').replace('+', '').replace('-', '')
|
|
88
|
+
return prefix + s
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def rand_string_runes(length):
|
|
92
|
+
return ''.join(random.sample(list(LETTER_RUNES), length))
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def aes_encrypt_cbc_with_base64(orig_data, key):
|
|
96
|
+
# type(orig_data) == <class 'str'>
|
|
97
|
+
# type(key) == <class 'bytes'>
|
|
98
|
+
generator = AES.new(key, AES.MODE_CBC, key)
|
|
99
|
+
if sys.version_info[0] == 3:
|
|
100
|
+
crypt = generator.encrypt(Util.pad(orig_data).encode('utf-8'))
|
|
101
|
+
return base64.b64encode(crypt).decode()
|
|
102
|
+
else:
|
|
103
|
+
crypt = generator.encrypt(Util.pad(orig_data))
|
|
104
|
+
return base64.b64encode(crypt)
|
|
105
|
+
|
|
106
|
+
@staticmethod
|
|
107
|
+
def generate_secret_key():
|
|
108
|
+
rand_str = Util.rand_string_runes(32)
|
|
109
|
+
return Util.aes_encrypt_cbc_with_base64(rand_str, 'bytedance-isgood'.encode('utf-8'))
|
|
110
|
+
|
|
111
|
+
@staticmethod
|
|
112
|
+
def crc32(file_path):
|
|
113
|
+
prev = 0
|
|
114
|
+
for eachLine in open(file_path, "rb"):
|
|
115
|
+
prev = crc32(eachLine, prev)
|
|
116
|
+
return prev & 0xFFFFFFFF
|
|
File without changes
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# coding:utf-8
|
|
2
|
+
import json
|
|
3
|
+
import threading
|
|
4
|
+
|
|
5
|
+
from byteplus_sdk.ApiInfo import ApiInfo
|
|
6
|
+
from byteplus_sdk.Credentials import Credentials
|
|
7
|
+
from byteplus_sdk.base.Service import Service
|
|
8
|
+
from byteplus_sdk.ServiceInfo import ServiceInfo
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class VisualService(Service):
|
|
12
|
+
_instance_lock = threading.Lock()
|
|
13
|
+
|
|
14
|
+
def __new__(cls, *args, **kwargs):
|
|
15
|
+
if not hasattr(VisualService, "_instance"):
|
|
16
|
+
with VisualService._instance_lock:
|
|
17
|
+
if not hasattr(VisualService, "_instance"):
|
|
18
|
+
VisualService._instance = object.__new__(cls)
|
|
19
|
+
return VisualService._instance
|
|
20
|
+
|
|
21
|
+
def __init__(self):
|
|
22
|
+
self.service_info = VisualService.get_service_info()
|
|
23
|
+
self.api_info = VisualService.get_api_info()
|
|
24
|
+
super(VisualService, self).__init__(self.service_info, self.api_info)
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def get_service_info():
|
|
28
|
+
service_info = ServiceInfo("cv.byteplusapi.com", {'Accept': 'application/json'},
|
|
29
|
+
Credentials('', '', 'cv', 'ap-singapore-1'), 30, 30, "https")
|
|
30
|
+
return service_info
|
|
31
|
+
|
|
32
|
+
@staticmethod
|
|
33
|
+
def get_api_info():
|
|
34
|
+
api_info = {
|
|
35
|
+
"ComicPortrait": ApiInfo("POST", "/", {"Action": "ComicPortrait", "Version": "2022-08-24"}, {}, {}),
|
|
36
|
+
"PortraitFusion": ApiInfo("POST", "/", {"Action": "PortraitFusion", "Version": "2022-08-24"}, {}, {}),
|
|
37
|
+
"CVProcess": ApiInfo("POST", "/", {"Action": "CVProcess", "Version": "2024-06-06"}, {}, {}),
|
|
38
|
+
"CVSubmitTask": ApiInfo("POST", "/", {"Action": "CVSubmitTask", "Version": "2024-06-06"}, {}, {}),
|
|
39
|
+
"CVGetResult": ApiInfo("POST", "/", {"Action": "CVGetResult", "Version": "2024-06-06"}, {}, {}),
|
|
40
|
+
"CVSync2AsyncSubmitTask": ApiInfo("POST", "/",{"Action": "CVSync2AsyncSubmitTask", "Version": "2024-06-06"}, {}, {}),
|
|
41
|
+
"CVSync2AsyncGetResult": ApiInfo("POST", "/", {"Action": "CVSync2AsyncGetResult", "Version": "2024-06-06"},{}, {}),
|
|
42
|
+
"CVCancelTask": ApiInfo("POST", "/", {"Action": "CVCancelTask", "Version": "2024-06-06"}, {}, {}),
|
|
43
|
+
}
|
|
44
|
+
return api_info
|
|
45
|
+
|
|
46
|
+
def common_handler(self, api, form):
|
|
47
|
+
params = dict()
|
|
48
|
+
try:
|
|
49
|
+
res = self.post(api, params, form)
|
|
50
|
+
res_json = json.loads(res)
|
|
51
|
+
return res_json
|
|
52
|
+
except Exception as e:
|
|
53
|
+
res = str(e)
|
|
54
|
+
try:
|
|
55
|
+
res_json = json.loads(res)
|
|
56
|
+
return res_json
|
|
57
|
+
except:
|
|
58
|
+
raise Exception(str(e))
|
|
59
|
+
|
|
60
|
+
def common_get_handler(self, api, params):
|
|
61
|
+
try:
|
|
62
|
+
res = self.get(api, params)
|
|
63
|
+
res_json = json.loads(res)
|
|
64
|
+
return res_json
|
|
65
|
+
except Exception as e:
|
|
66
|
+
res = str(e)
|
|
67
|
+
try:
|
|
68
|
+
res_json = json.loads(res)
|
|
69
|
+
return res_json
|
|
70
|
+
except:
|
|
71
|
+
raise Exception(str(e))
|
|
72
|
+
|
|
73
|
+
def common_json_handler(self, api, body):
|
|
74
|
+
params = dict()
|
|
75
|
+
try:
|
|
76
|
+
res = self.json(api, params, body)
|
|
77
|
+
res_json = json.loads(res)
|
|
78
|
+
|
|
79
|
+
return res_json
|
|
80
|
+
except Exception as e:
|
|
81
|
+
res = str(e)
|
|
82
|
+
try:
|
|
83
|
+
res_json = json.loads(res)
|
|
84
|
+
return res_json
|
|
85
|
+
except:
|
|
86
|
+
raise Exception(str(e))
|
|
87
|
+
|
|
88
|
+
def cv_process(self, body):
|
|
89
|
+
try:
|
|
90
|
+
res_json = self.common_json_handler("CVProcess", body)
|
|
91
|
+
return res_json
|
|
92
|
+
except Exception as e:
|
|
93
|
+
raise Exception(str(e))
|
|
94
|
+
|
|
95
|
+
def cv_submit_task(self, body):
|
|
96
|
+
try:
|
|
97
|
+
res_json = self.common_json_handler("CVSubmitTask", body)
|
|
98
|
+
return res_json
|
|
99
|
+
except Exception as e:
|
|
100
|
+
raise Exception(str(e))
|
|
101
|
+
|
|
102
|
+
def cv_get_result(self, body):
|
|
103
|
+
try:
|
|
104
|
+
res_json = self.common_json_handler("CVGetResult", body)
|
|
105
|
+
return res_json
|
|
106
|
+
except Exception as e:
|
|
107
|
+
raise Exception(str(e))
|
|
108
|
+
|
|
109
|
+
def cv_cancel_task(self, body):
|
|
110
|
+
try:
|
|
111
|
+
res_json = self.common_json_handler("CVCancelTask", body)
|
|
112
|
+
return res_json
|
|
113
|
+
except Exception as e:
|
|
114
|
+
raise Exception(str(e))
|
|
115
|
+
|
|
116
|
+
def cv_sync2async_submit_task(self, body):
|
|
117
|
+
try:
|
|
118
|
+
res_json = self.common_json_handler("CVSync2AsyncSubmitTask", body)
|
|
119
|
+
return res_json
|
|
120
|
+
except Exception as e:
|
|
121
|
+
raise Exception(str(e))
|
|
122
|
+
|
|
123
|
+
def cv_sync2async_get_result(self, body):
|
|
124
|
+
try:
|
|
125
|
+
res_json = self.common_json_handler("CVSync2AsyncGetResult", body)
|
|
126
|
+
return res_json
|
|
127
|
+
except Exception as e:
|
|
128
|
+
raise Exception(str(e))
|
|
129
|
+
|
|
130
|
+
def comic_portrait(self, form):
|
|
131
|
+
try:
|
|
132
|
+
res_json = self.common_handler("ComicPortrait", form)
|
|
133
|
+
return res_json
|
|
134
|
+
except Exception as e:
|
|
135
|
+
raise Exception(str(e))
|
|
136
|
+
|
|
137
|
+
def portrait_fusion(self, form):
|
|
138
|
+
try:
|
|
139
|
+
res_json = self.common_handler("PortraitFusion", form)
|
|
140
|
+
return res_json
|
|
141
|
+
except Exception as e:
|
|
142
|
+
raise Exception(str(e))
|
|
File without changes
|