-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileProtocol.py
More file actions
37 lines (30 loc) · 1.02 KB
/
FileProtocol.py
File metadata and controls
37 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import json
import logging
import shlex
from FileInterface import FileInterface
"""
* class FileProtocol bertugas untuk memproses
data yang masuk, dan menerjemahkannya apakah sesuai dengan
protokol/aturan yang dibuat
* data yang masuk dari client adalah dalam bentuk bytes yang
pada akhirnya akan diproses dalam bentuk string
* class FileProtocol akan memproses data yang masuk dalam bentuk
string
"""
class FileProtocol:
def __init__(self):
self.file = FileInterface()
def proses_string(self,string_datamasuk=''):
c = shlex.split(string_datamasuk)
try:
c_request = c[0].strip().lower()
logging.warning(f"memproses request: {c_request}")
params = [x for x in c[1:]]
cl = getattr(self.file,c_request)(params)
return json.dumps(cl)
except Exception:
return json.dumps(dict(status='ERROR',data='request tidak dikenali'))
if __name__=='__main__':
#contoh pemakaian
fp = FileProtocol()
print(fp.proses_string("LIST"))