solax-py-library 0.1.0.6__py3-none-any.whl → 0.1.0.8__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.
@@ -14,8 +14,8 @@ class BaseUploadService(metaclass=ABCMeta):
14
14
  def connect(self):
15
15
  ...
16
16
 
17
- def upload(self, data):
18
- upload_data = self._parse(data)
17
+ def upload(self, data: UploadData):
18
+ upload_data = self._parse(data.build_data())
19
19
  return self._upload(upload_data)
20
20
 
21
21
  @abstractmethod
@@ -4,8 +4,17 @@ import os
4
4
  from .base import BaseUploadService
5
5
  from solax_py_library.upload.types.client import UploadType, UploadData
6
6
  from solax_py_library.upload.core.data_adapter import CSVDataAdapter
7
- from solax_py_library.upload.types.ftp import FTPServiceConfig, FTPFileType, FTPData, FTPParsedData
8
- from solax_py_library.upload.errors.upload_error import SendDataError, ConnectError, ConfigurationError
7
+ from solax_py_library.upload.types.ftp import (
8
+ FTPServiceConfig,
9
+ FTPFileType,
10
+ FTPData,
11
+ FTPParsedData,
12
+ )
13
+ from solax_py_library.upload.errors.upload_error import (
14
+ SendDataError,
15
+ ConnectError,
16
+ ConfigurationError,
17
+ )
9
18
 
10
19
 
11
20
  class FTPUploadService(BaseUploadService):
@@ -15,7 +24,7 @@ class FTPUploadService(BaseUploadService):
15
24
  super().__init__(**kwargs)
16
25
  config = self._init_config(**kwargs)
17
26
  self.host = config.host
18
- self.username = config.username
27
+ self.user = config.user
19
28
  self.password = config.password
20
29
  self.remote_path = config.remote_path
21
30
 
@@ -31,7 +40,7 @@ class FTPUploadService(BaseUploadService):
31
40
  self.close()
32
41
  try:
33
42
  self._client = ftplib.FTP(self.host)
34
- self._client.login(self.username, self.password)
43
+ self._client.login(self.user, self.password)
35
44
  print(f"Connected to {self.host}")
36
45
  self._is_connect = True
37
46
  except Exception as e:
@@ -45,14 +54,13 @@ class FTPUploadService(BaseUploadService):
45
54
  self._is_connect = False
46
55
  print("Connection closed.")
47
56
 
48
- def _parse(self, upload_data: UploadData) -> FTPParsedData:
49
- data: FTPData = upload_data.ftp_data
50
- if data.file_type == FTPFileType.CSV:
51
- parsed_data = CSVDataAdapter.parse_data(data.data)
57
+ def _parse(self, upload_data: FTPData) -> FTPParsedData:
58
+ if upload_data.file_type == FTPFileType.CSV:
59
+ parsed_data = CSVDataAdapter.parse_data(upload_data.data)
52
60
  else:
53
61
  raise NotImplementedError
54
62
  return FTPParsedData(
55
- file_name=data.build_full_path(self.remote_path), data=parsed_data
63
+ file_name=upload_data.build_full_path(self.remote_path), data=parsed_data
56
64
  )
57
65
 
58
66
  def _upload(self, data: FTPParsedData):
@@ -9,7 +9,7 @@ class FTPTest(unittest.TestCase):
9
9
  def test_ftp_upload(self):
10
10
  ftp_config = {
11
11
  "host": "10.1.31.181", # 测试host
12
- "username": "solax",
12
+ "user": "solax",
13
13
  "password": "sly402",
14
14
  "remote_path": "/xixi",
15
15
  }
@@ -17,7 +17,8 @@ class FTPTest(unittest.TestCase):
17
17
  upload_type=UploadType.FTP,
18
18
  configuration=ftp_config,
19
19
  upload_data=UploadData(
20
- ftp_data=FTPData(
20
+ upload_type=UploadType.FTP,
21
+ data=dict(
21
22
  file_type=FTPFileType.CSV,
22
23
  file_name="new_file.csv",
23
24
  data=[["curry", 37, "男"], ["james", 40, "男"], ["lily", 16, "女"]],
@@ -10,5 +10,10 @@ class UploadType(str, Enum):
10
10
 
11
11
 
12
12
  class UploadData(BaseModel):
13
- data: Optional[Union[FTPData]]
13
+ data: Optional[Union[dict, FTPData]]
14
14
  upload_type: Optional[UploadType]
15
+
16
+ def build_data(self):
17
+ dict_obj_data = self.data if isinstance(self.data, dict) else self.data.dict()
18
+ if self.upload_type == UploadType.FTP:
19
+ return FTPData(**dict_obj_data)
@@ -2,7 +2,7 @@ import os
2
2
  from enum import Enum
3
3
  from typing import Any, Optional
4
4
 
5
- from pydantic import BaseModel, Field
5
+ from pydantic import BaseModel
6
6
 
7
7
 
8
8
  class FTPFileType(str, Enum):
@@ -20,7 +20,7 @@ class FTPData(BaseModel):
20
20
 
21
21
  class FTPServiceConfig(BaseModel):
22
22
  host: str
23
- username: Optional[str]
23
+ user: Optional[str]
24
24
  password: Optional[str]
25
25
  remote_path: str
26
26
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: solax-py-library
3
- Version: 0.1.0.6
3
+ Version: 0.1.0.8
4
4
  Summary: some common tool
5
5
  Author: shenlvyu
6
6
  Author-email: 13296718439@163.com
@@ -7,16 +7,16 @@ solax_py_library/upload/core/data_adapter/__init__.py,sha256=9CXepLZSOjZMfNjyYKA
7
7
  solax_py_library/upload/core/data_adapter/base.py,sha256=Va-SEe0eL3gobhNOnzHGkYBLIwf5RVawQdYRHHXg9g0,170
8
8
  solax_py_library/upload/core/data_adapter/csv.py,sha256=LR-45i1Guihrm_eN2Li9kNoutTAsiPeWQNTUz2HJmok,518
9
9
  solax_py_library/upload/core/upload_service/__init__.py,sha256=uA-UeH31rDNxByeZwvPhNFHPV_-J8JyCev8geuc---k,269
10
- solax_py_library/upload/core/upload_service/base.py,sha256=T6h0ws_bCVRL2AeIXmDpbfPWZzJnUGh5gJKTZoF1CSw,856
11
- solax_py_library/upload/core/upload_service/ftp.py,sha256=Stbqd5SBB0-khAOymTz8w_69IkgGCS4eiowxAfLoaf8,2433
10
+ solax_py_library/upload/core/upload_service/base.py,sha256=vl6QTxcx-QVFv0J1VN7HSgh4opouKfTpmJDkwQYzLVU,881
11
+ solax_py_library/upload/core/upload_service/ftp.py,sha256=EyqaCn6b24rOKDbf-DqZQirq5JuDaVuApsb48RADsfk,2432
12
12
  solax_py_library/upload/errors/__init__.py,sha256=pVAcSOXvlsPJW3PjHLBOdbl7KvntiYmz7TP0XuRwZ_A,243
13
13
  solax_py_library/upload/errors/base.py,sha256=T01ZrZHF25PWgCrOv76Vhg26hds3I1Yy8Kl2LZRKOxo,258
14
14
  solax_py_library/upload/errors/upload_error.py,sha256=9pCZzR_y3-VkBWSs5w7mMHYFRJjzVosIcxi-5SO8N1U,409
15
15
  solax_py_library/upload/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- solax_py_library/upload/test/test_ftp.py,sha256=mJcYdroFLpI82t2-8IVGXNYGWB9TVJK723uaQFcTFr4,856
16
+ solax_py_library/upload/test/test_ftp.py,sha256=a3-jNQVjkoo_gh45yvnicGitIeJX6pco5MiEsDQqr-Q,889
17
17
  solax_py_library/upload/types/__init__.py,sha256=og9KBpYbcs36_S1izURj3vyHeuNOLJQrD9GpxK_JJaw,244
18
- solax_py_library/upload/types/client.py,sha256=PEUG7pulvwEb6NS6yiu5yYHowNI8UrUDygawfAkPIlo,294
19
- solax_py_library/upload/types/ftp.py,sha256=JN2KD2WPZGvPXh30p15rLY9AUzeWUXkeSIdb4CesdAw,544
20
- solax_py_library-0.1.0.6.dist-info/METADATA,sha256=zg5vGI7s2GvmQqJ4BYlfpOE3PoBC0pf5RPyUIzA6bZE,670
21
- solax_py_library-0.1.0.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
22
- solax_py_library-0.1.0.6.dist-info/RECORD,,
18
+ solax_py_library/upload/types/client.py,sha256=IE4tw2KFRmZABptmujB7SXG2-61cW7X7qN9b2IrBF3Y,505
19
+ solax_py_library/upload/types/ftp.py,sha256=RTREbHwvGz6hrz_VUaw8Rx5utB4LQisytcsI2jGT6zc,533
20
+ solax_py_library-0.1.0.8.dist-info/METADATA,sha256=gsU0pqfIGRpQG_33PXXDH-6B3UCKCaydmRL8VX-2bPE,670
21
+ solax_py_library-0.1.0.8.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
22
+ solax_py_library-0.1.0.8.dist-info/RECORD,,