re-common 0.2.53__py3-none-any.whl → 2.0.0__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.
@@ -1,62 +1,62 @@
1
- # coding = UTF-8
2
-
3
-
4
- # 导入Python标准库
5
- import os
6
- from io import BytesIO
7
-
8
- # 导入第三方库
9
- from PIL import Image
10
-
11
- # 防止中文乱码
12
- os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
13
-
14
- # 支持的图片文件格式
15
- SUPPORT_SUFFIX = ["jpg", "jpeg", "png"]
16
-
17
-
18
- def pic_to_pdf(image_bytes: bytes) -> bytes:
19
- """将单个图片转换为单张PDF
20
-
21
- :param image_bytes: 图片的bytes对象
22
- :return: PDF的bytes对象
23
- """
24
- # 将bytes对象转换为BytesIO对象
25
- image_bytes_io = BytesIO(image_bytes)
26
- # 从内存中读取图片
27
- image_object = Image.open(image_bytes_io)
28
- # 打开内存中的文件用于保存PDF
29
- with BytesIO() as result_bytes_io:
30
- # 将图片保存为单张PDF
31
- image_object.save(result_bytes_io, "PDF", resolution=100.0)
32
- # 获取内存中的文件
33
- data = result_bytes_io.getvalue()
34
- # 返回PDF的bytes对象
35
- return data
36
-
37
-
38
- def batch_convert(image_path: str, pdf_path: str) -> None:
39
- """批量将图片转换为单张PDF
40
-
41
- :param image_path: 图片的文件夹
42
- :param pdf_path: PDF文件保存的文件夹
43
- """
44
- # 遍历文件夹下所有文件
45
- for root, dirs, files in os.walk(image_path, topdown=False):
46
- for name in files:
47
- # 提取文件的后缀名
48
- file_suffix = os.path.splitext(name)[-1].lstrip(".").lower()
49
- # 检测该文件格式是否受到支持
50
- if file_suffix not in SUPPORT_SUFFIX:
51
- continue
52
- # 拼接出图片文件的绝对路径
53
- source_file_path = os.path.join(root, name)
54
- # 拼接出PDF文件的绝对路径
55
- target_file_path = os.path.join(pdf_path, f"{os.path.splitext(name)[0]}.pdf")
56
- # 将图片文件转换为PDF文件
57
- with open(source_file_path, "rb") as source:
58
- with open(target_file_path, "wb") as target:
59
- target.write(pic_to_pdf(source.read()))
60
-
61
-
1
+ # coding = UTF-8
2
+
3
+
4
+ # 导入Python标准库
5
+ import os
6
+ from io import BytesIO
7
+
8
+ # 导入第三方库
9
+ from PIL import Image
10
+
11
+ # 防止中文乱码
12
+ os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
13
+
14
+ # 支持的图片文件格式
15
+ SUPPORT_SUFFIX = ["jpg", "jpeg", "png"]
16
+
17
+
18
+ def pic_to_pdf(image_bytes: bytes) -> bytes:
19
+ """将单个图片转换为单张PDF
20
+
21
+ :param image_bytes: 图片的bytes对象
22
+ :return: PDF的bytes对象
23
+ """
24
+ # 将bytes对象转换为BytesIO对象
25
+ image_bytes_io = BytesIO(image_bytes)
26
+ # 从内存中读取图片
27
+ image_object = Image.open(image_bytes_io)
28
+ # 打开内存中的文件用于保存PDF
29
+ with BytesIO() as result_bytes_io:
30
+ # 将图片保存为单张PDF
31
+ image_object.save(result_bytes_io, "PDF", resolution=100.0)
32
+ # 获取内存中的文件
33
+ data = result_bytes_io.getvalue()
34
+ # 返回PDF的bytes对象
35
+ return data
36
+
37
+
38
+ def batch_convert(image_path: str, pdf_path: str) -> None:
39
+ """批量将图片转换为单张PDF
40
+
41
+ :param image_path: 图片的文件夹
42
+ :param pdf_path: PDF文件保存的文件夹
43
+ """
44
+ # 遍历文件夹下所有文件
45
+ for root, dirs, files in os.walk(image_path, topdown=False):
46
+ for name in files:
47
+ # 提取文件的后缀名
48
+ file_suffix = os.path.splitext(name)[-1].lstrip(".").lower()
49
+ # 检测该文件格式是否受到支持
50
+ if file_suffix not in SUPPORT_SUFFIX:
51
+ continue
52
+ # 拼接出图片文件的绝对路径
53
+ source_file_path = os.path.join(root, name)
54
+ # 拼接出PDF文件的绝对路径
55
+ target_file_path = os.path.join(pdf_path, f"{os.path.splitext(name)[0]}.pdf")
56
+ # 将图片文件转换为PDF文件
57
+ with open(source_file_path, "rb") as source:
58
+ with open(target_file_path, "wb") as target:
59
+ target.write(pic_to_pdf(source.read()))
60
+
61
+
62
62
  batch_convert(r"C:\Users\Administrator\Desktop\上传\zhuanhuan\20230404\新建文件夹 (5)",r"C:\Users\Administrator\Desktop\上传\zhuanhuan\20230404\pdf")
@@ -70,6 +70,7 @@ class BaseBoto3(object):
70
70
  # 按名称创建资源服务客户端
71
71
  self.client = self.session.resource('s3', endpoint_url=self.endpoint_url)
72
72
  print(type(self.client))
73
+ return self
73
74
 
74
75
  def get_all_buckets(self):
75
76
  """
@@ -116,6 +117,8 @@ class BaseBoto3(object):
116
117
  if self.is_low_level is False:
117
118
  self.bucket = self.client.Bucket(bucket_name)
118
119
  return self.bucket
120
+ else:
121
+ raise Exception("无实现方法")
119
122
 
120
123
  def get_all_obs_filter(self, Prefix):
121
124
  """
@@ -182,16 +185,107 @@ class BaseBoto3(object):
182
185
 
183
186
  def check_exist(self, bucket_name, key):
184
187
  """
188
+ if self.is_low_level:
189
+ {'ResponseMetadata': {'RequestId': '17E6A65A2B299D3B', 'HostId': '', 'HTTPStatusCode': 200, 'HTTPHeaders': {'accept-ranges': 'bytes', 'content-length': '117', 'content-security-policy': 'block-all-mixed-content', 'content-type': 'binary/octet-stream', 'etag': '"2237a934f176003e41abf3d733291079"', 'last-modified': 'Thu, 25 Jul 2024 05:49:43 GMT', 'server': 'MinIO', 'strict-transport-security': 'max-age=31536000; includeSubDomains', 'vary': 'Origin, Accept-Encoding', 'x-amz-request-id': '17E6A65A2B299D3B', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'date': 'Mon, 29 Jul 2024 09:53:33 GMT'}, 'RetryAttempts': 0}, 'AcceptRanges': 'bytes', 'LastModified': datetime.datetime(2024, 7, 25, 5, 49, 43, tzinfo=tzutc()), 'ContentLength': 117, 'ETag': '"2237a934f176003e41abf3d733291079"', 'ContentType': 'binary/octet-stream', 'Metadata': {}}
185
190
  判定文件是否存在,
186
191
  :param bucket_name: 桶名
187
192
  :param key: 文件key
188
193
  :return:
189
194
  """
190
- try:
191
- obj_info = self.client.head_object(
192
- Bucket=bucket_name,
193
- Key=key
194
- )
195
- return obj_info
196
- except:
197
- return None
195
+
196
+ if self.is_low_level:
197
+ try:
198
+ obj_info = self.client.head_object(
199
+ Bucket=bucket_name,
200
+ Key=key
201
+ )
202
+ return obj_info
203
+ except:
204
+ return None
205
+ else:
206
+ # 获取指定存储桶
207
+ bucket = self.client.Bucket(bucket_name)
208
+ # 检查 key 是否存在
209
+ objs = list(bucket.objects.filter(Prefix=key))
210
+ if len(objs) > 0 and objs[0].key == key:
211
+ # [s3.ObjectSummary(bucket_name='crawl.dc.cqvip.com', key='foreign/organ/parsel_organ_log.txt')]
212
+ return objs[0]
213
+ else:
214
+ return None
215
+
216
+ def get_prefix_obj(self, bucket, prefix, delimiter):
217
+ """
218
+ Bucket="crawl.dc.cqvip.com",
219
+ Prefix="foreign/organ/ei/",
220
+ Delimiter='/'
221
+
222
+ Returns:
223
+
224
+ """
225
+ if self.is_low_level:
226
+ # for common_prefix in response.get('CommonPrefixes', []): 获取子目录
227
+ return self.client.list_objects_v2(Bucket=bucket,
228
+ Prefix=prefix,
229
+ Delimiter=delimiter) # 设置 Delimiter='/' 可以确保只列出目录而不是所有对象。
230
+ else:
231
+ # 该方法只能列出文件 没办法列出目录
232
+ # bucket_resource = self.client.Bucket(bucket)
233
+ # objects = bucket_resource.objects.filter(Prefix=prefix, Delimiter=delimiter)
234
+ # return list(objects)
235
+
236
+ bucket_resource = self.client.Bucket(bucket)
237
+ return bucket_resource.meta.client.list_objects_v2(Bucket=bucket,
238
+ Prefix=prefix,
239
+ Delimiter=delimiter)
240
+
241
+ def get_object_value(self, bucket_name, file_key, encoding='utf-8'):
242
+ """
243
+ 读取文本数据
244
+ Returns:
245
+
246
+ """
247
+ if self.is_low_level:
248
+ obj = self.client.get_object(Bucket=bucket_name, Key=file_key)
249
+ body = obj['Body'].read().decode(encoding)
250
+ return body
251
+ else:
252
+ bucket_resource = self.client.Bucket(bucket_name)
253
+ obj = bucket_resource.Object(file_key)
254
+ body = obj.get()['Body'].read().decode(encoding)
255
+ return body
256
+
257
+ def put_object(self, bucket_name, key, body):
258
+ """
259
+ 直接写内容到文件
260
+ Args:
261
+ bucket_name:
262
+ key:
263
+ body: 需要 编码 .encode('utf-8')
264
+
265
+ Returns:
266
+
267
+ """
268
+ if self.is_low_level:
269
+ self.client.put_object(Bucket=bucket_name,
270
+ Key=key,
271
+ Body=body)
272
+ else:
273
+ # 获取 Bucket 对象
274
+ bucket_resource = self.client.Bucket(bucket_name)
275
+
276
+ # 将内容写入文件
277
+ bucket_resource.put_object(Key=key, Body=body)
278
+
279
+
280
+ bb = BaseBoto3(aws_access_key_id="UM51J2G5ZG0FE5CCERB9",
281
+ aws_secret_access_key="u+OEmhE2fahF2L+oXB+HXe8IJs22Lo38icvlF+Yq",
282
+ endpoint_url="http://192.168.31.135:9000"
283
+ )
284
+ bb.conn_session()
285
+ bb.set_is_low_level(False)
286
+ bb.get_client()
287
+
288
+ result = bb.check_exist("crawl.dc.cqvip.com",
289
+ "foreign/organ/parsel_organ_log.txt")
290
+
291
+ print(result)
@@ -1,103 +1,103 @@
1
- USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36'
2
-
3
- USER_AGENTS = [
4
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36",
5
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
6
- "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
7
- "Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
8
- "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)",
9
- "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)",
10
- "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)",
11
- "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)",
12
- "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)",
13
- "Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6",
14
- "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1",
15
- "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0",
16
- "Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5",
17
- "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6",
18
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
19
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20",
20
- "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52",
21
- ]
22
-
23
- INSIDE_HEADERS = {
24
- "accept": "application/json",
25
- "content-type": "application/json"
26
- }
27
-
28
-
29
- def set_proxy(proxy):
30
- Proxiesss = {
31
- 'http': proxy,
32
- 'https': proxy
33
- }
34
- return Proxiesss
35
-
36
-
37
- def set_proxy_aio(proxy):
38
- if proxy:
39
- return r"http://" + proxy
40
- return None
41
-
42
-
43
- def set_proxy_httpx(proxy):
44
- if proxy.find("socks") > -1:
45
- return proxy
46
- if proxy:
47
- Proxiesss = {
48
- 'http://': "http://" + proxy,
49
- 'https://': "http://" + proxy
50
- }
51
- return Proxiesss
52
- else:
53
- return None
54
-
55
-
56
- class MsgCode(object):
57
- SUCCESS_CODE: int = 200 # 成功状态码
58
-
59
- NO_RESOURCE: int = 421 # 网页明确表明无资源
60
- PAGE_BLANK: int = 420 # 网页空白页
61
- END_STRING_ERROR: int = 210 # html结尾验证错误
62
- MARK_ERROR: int = 211 # 验证html错误,验证没有通过
63
- NOT_IS_JSON: int = 212 # 验证返回是否是json
64
- VER_CODE: int = 213 # 需要验证码
65
- NONE_HTML: int = 214 # html为空 空的html 在使用某些代理时 如果https 写成了http,会有这种情况
66
- STATUS_ERROR: int = 215 # API接口内部执行错误
67
- CODE_ERROR: int = 216 # data 状态码错误
68
- URL_TIMEOUT: int = 217
69
-
70
- SETTING_CONFIG_ERROR: int = 251 # 特定错误 更新taskinfo_save_setting的任务控制配置失败(switch参数错误,只能为0或1)
71
-
72
- API_FAIL_CODE: int = 400 # api失败,但具体原因未知的状态码
73
- TIME_OUT_ERROR: int = 408 # 超时错误
74
- PROXY_ERROR: int = 422 # 代理错误
75
- PAYLOAD_ERROR: int = 423 # 非法的压缩格式,错误的chunk编码,数据不足Content-length的大小。通常为Accept-Encoding:gzip, deflate, br ,也就是三种编码格式。但其实,aiohttp默认没有br解码,或者html编码格式错误
76
- SERVER_ERROR: int = 530 # 服务器异常错误,被捕获发送
77
- CHAOXIN_COOKIE_ERROR: int = 556 # 超星期刊获取cookie失败
78
-
79
- DATABASE_CONFIG_IN_CODE: int = 998 # 在代码中配置数据库无对应错误码
80
-
81
- ON_KNOW: int = 1000 # 未知错误
82
-
83
- MONGO_ERROR: int = 1001 # mongodb 錯誤系列由1000 到 1100
84
- MONGO_NO_ID: int = 1002 # 操作时由于没有该id的状态码,比如更新时ID不存在
85
-
86
- PARE_STRUCTURE_ERROR: int = 1101 # 解析系列由1100 到 1200,解析结构错误
87
- PARE_NO_DATA: int = 1102 # 没有数据,且认为是正常的没有数据的标识
88
- PARE_NO_DATA_ERR: int = 1103 # 没有数据,且认为是非正常的没有数据的标识
89
- PARE_NO_DATA_1: int = 1104 # 预留几个无数据,在不同库不同意义
90
- PARE_NO_DATA_2: int = 1105 # 预留几个无数据,在不同库不同意义
91
- PARE_NO_DATA_3: int = 1106 # 预留几个无数据,在不同库不同意义
92
- SQL_INSERT_ERROR: int = 1201 # sql错误 由 1200 到 1300 insert 错误
93
- SQL_UPDATE_ERROR: int = 1202 # update 错误
94
- SQL_SELECT_ALL_ERROR: int = 1203 # 执行fetchall 错误
95
- SQL_EXECUTEMANY_ERROR: int = 1204 # executemany 执行错误
96
- SQL_EXECUTE_ERROR: int = 1205 # execute 执行错误
97
- SQL_REPLACE_ERROR: int = 1206 # replace 执行错误
98
-
99
- GRPC_MESSAGE_DECODEERROR: int = 1301 # grpc服务编码错误
100
-
101
-
102
- SUCCESS = "SUCCESS"
103
- FAILED = "FAILED"
1
+ USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36'
2
+
3
+ USER_AGENTS = [
4
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36",
5
+ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
6
+ "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
7
+ "Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
8
+ "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)",
9
+ "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)",
10
+ "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)",
11
+ "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)",
12
+ "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)",
13
+ "Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6",
14
+ "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1",
15
+ "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0",
16
+ "Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5",
17
+ "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6",
18
+ "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
19
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20",
20
+ "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52",
21
+ ]
22
+
23
+ INSIDE_HEADERS = {
24
+ "accept": "application/json",
25
+ "content-type": "application/json"
26
+ }
27
+
28
+
29
+ def set_proxy(proxy):
30
+ Proxiesss = {
31
+ 'http': proxy,
32
+ 'https': proxy
33
+ }
34
+ return Proxiesss
35
+
36
+
37
+ def set_proxy_aio(proxy):
38
+ if proxy:
39
+ return r"http://" + proxy
40
+ return None
41
+
42
+
43
+ def set_proxy_httpx(proxy):
44
+ if proxy.find("socks") > -1:
45
+ return proxy
46
+ if proxy:
47
+ Proxiesss = {
48
+ 'http://': "http://" + proxy,
49
+ 'https://': "http://" + proxy
50
+ }
51
+ return Proxiesss
52
+ else:
53
+ return None
54
+
55
+
56
+ class MsgCode(object):
57
+ SUCCESS_CODE: int = 200 # 成功状态码
58
+
59
+ NO_RESOURCE: int = 421 # 网页明确表明无资源
60
+ PAGE_BLANK: int = 420 # 网页空白页
61
+ END_STRING_ERROR: int = 210 # html结尾验证错误
62
+ MARK_ERROR: int = 211 # 验证html错误,验证没有通过
63
+ NOT_IS_JSON: int = 212 # 验证返回是否是json
64
+ VER_CODE: int = 213 # 需要验证码
65
+ NONE_HTML: int = 214 # html为空 空的html 在使用某些代理时 如果https 写成了http,会有这种情况
66
+ STATUS_ERROR: int = 215 # API接口内部执行错误
67
+ CODE_ERROR: int = 216 # data 状态码错误
68
+ URL_TIMEOUT: int = 217
69
+
70
+ SETTING_CONFIG_ERROR: int = 251 # 特定错误 更新taskinfo_save_setting的任务控制配置失败(switch参数错误,只能为0或1)
71
+
72
+ API_FAIL_CODE: int = 400 # api失败,但具体原因未知的状态码
73
+ TIME_OUT_ERROR: int = 408 # 超时错误
74
+ PROXY_ERROR: int = 422 # 代理错误
75
+ PAYLOAD_ERROR: int = 423 # 非法的压缩格式,错误的chunk编码,数据不足Content-length的大小。通常为Accept-Encoding:gzip, deflate, br ,也就是三种编码格式。但其实,aiohttp默认没有br解码,或者html编码格式错误
76
+ SERVER_ERROR: int = 530 # 服务器异常错误,被捕获发送
77
+ CHAOXIN_COOKIE_ERROR: int = 556 # 超星期刊获取cookie失败
78
+
79
+ DATABASE_CONFIG_IN_CODE: int = 998 # 在代码中配置数据库无对应错误码
80
+
81
+ ON_KNOW: int = 1000 # 未知错误
82
+
83
+ MONGO_ERROR: int = 1001 # mongodb 錯誤系列由1000 到 1100
84
+ MONGO_NO_ID: int = 1002 # 操作时由于没有该id的状态码,比如更新时ID不存在
85
+
86
+ PARE_STRUCTURE_ERROR: int = 1101 # 解析系列由1100 到 1200,解析结构错误
87
+ PARE_NO_DATA: int = 1102 # 没有数据,且认为是正常的没有数据的标识
88
+ PARE_NO_DATA_ERR: int = 1103 # 没有数据,且认为是非正常的没有数据的标识
89
+ PARE_NO_DATA_1: int = 1104 # 数据不全,但可以接受
90
+ PARE_NO_DATA_2: int = 1105 # 预留几个无数据,在不同库不同意义
91
+ PARE_NO_DATA_3: int = 1106 # 预留几个无数据,在不同库不同意义
92
+ SQL_INSERT_ERROR: int = 1201 # sql错误 由 1200 到 1300 insert 错误
93
+ SQL_UPDATE_ERROR: int = 1202 # update 错误
94
+ SQL_SELECT_ALL_ERROR: int = 1203 # 执行fetchall 错误
95
+ SQL_EXECUTEMANY_ERROR: int = 1204 # executemany 执行错误
96
+ SQL_EXECUTE_ERROR: int = 1205 # execute 执行错误
97
+ SQL_REPLACE_ERROR: int = 1206 # replace 执行错误
98
+
99
+ GRPC_MESSAGE_DECODEERROR: int = 1301 # grpc服务编码错误
100
+
101
+
102
+ SUCCESS = "SUCCESS"
103
+ FAILED = "FAILED"
@@ -1,32 +1,32 @@
1
- from abc import ABCMeta as NativeABCMeta
2
-
3
-
4
- class DummyAttribute:
5
- pass
6
-
7
-
8
- def abstract_attribute(obj=None):
9
- if obj is None:
10
- obj = DummyAttribute()
11
- obj.__is_abstract_attribute__ = True
12
- return obj
13
-
14
-
15
- class ABCMeta(NativeABCMeta):
16
-
17
- def __call__(cls, *args, **kwargs):
18
- instance = NativeABCMeta.__call__(cls, *args, **kwargs)
19
- abstract_attributes = {
20
- name
21
- for name in dir(instance)
22
- if getattr(getattr(instance, name), '__is_abstract_attribute__', False)
23
- }
24
- if abstract_attributes:
25
- raise NotImplementedError(
26
- "Can't instantiate abstract class {} with"
27
- " abstract attributes: {}".format(
28
- cls.__name__,
29
- ', '.join(abstract_attributes)
30
- )
31
- )
32
- return instance
1
+ from abc import ABCMeta as NativeABCMeta
2
+
3
+
4
+ class DummyAttribute:
5
+ pass
6
+
7
+
8
+ def abstract_attribute(obj=None):
9
+ if obj is None:
10
+ obj = DummyAttribute()
11
+ obj.__is_abstract_attribute__ = True
12
+ return obj
13
+
14
+
15
+ class ABCMeta(NativeABCMeta):
16
+
17
+ def __call__(cls, *args, **kwargs):
18
+ instance = NativeABCMeta.__call__(cls, *args, **kwargs)
19
+ abstract_attributes = {
20
+ name
21
+ for name in dir(instance)
22
+ if getattr(getattr(instance, name), '__is_abstract_attribute__', False)
23
+ }
24
+ if abstract_attributes:
25
+ raise NotImplementedError(
26
+ "Can't instantiate abstract class {} with"
27
+ " abstract attributes: {}".format(
28
+ cls.__name__,
29
+ ', '.join(abstract_attributes)
30
+ )
31
+ )
32
+ return instance
File without changes
File without changes
File without changes