📄 client.py
字号:
'''This file is part of PypMsg.PypMsg is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.PypMsg is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with PypMsg. If not, see <http://www.gnu.org/licenses/>.'''import confimport socket as skimport pickle as pkimport osclass Client: def __init__(self, server1): self.attachments = {'fils':[], 'dirs':[]} self.server = server1 def sendMsg(self, host, message): self.clientSocket = sk.socket(sk.AF_INET, sk.SOCK_STREAM) print 'host:',host print 'port:',conf.PORT self.clientSocket.connect((str(host), conf.PORT)) dict = {} dict['__MODE__'] = '__MESSAGE__' dict['Message'] = message dict['AuthToken']='' dict['OSep'] = os.sep dict['fils'] = [(i, atch) for i, atch in self.attachments['fils'] if os.path.exists(atch) and not os.path.isdir(atch)] dict['dirs'] = [(i, atch) for i, atch in self.attachments['dirs'] if os.path.exists(atch) and os.path.isdir(atch)] self.server.sentAttachments.append({ 'Address' : host, 'fils' : dict['fils'], 'dirs' : dict['dirs'], 'AuthToken' : 'NOT_IMPLEMENTED' }) data = pk.dumps(dict) self.clientSocket.send(data) res = self.clientSocket.recv(conf.BULK_METADATA) if res == 'RECIEVED': pass else: print 'PypMsg Error: "', res, '"' self.clientSocket.close() del self.clientSocket def addAttachment(self, attachmentPath): if not attachmentPath: #wx.MessageDialog(None, 'Please enter a valid path of the attachment.', 'Attachment', wx.OK | wx.ICON_EXCLAMATION | wx.CENTRE).ShowModal() return 'Please enter a valid path of the attachment.' if not os.path.exists(attachmentPath): #wx.MessageDialog(None, 'The path entered does not exist.', 'Attachment', wx.OK | wx.ICON_ERROR | wx.CENTRE).ShowModal() return 'The path entered does not exist.' if os.path.isdir(attachmentPath): #self.atchList.InsertStringItem(len(self.attachments['dirs']), attachmentPath) if attachmentPath in [fn for i, fn in self.attachments['dirs']]: return 'The specified folder is already attached.' self.attachments['dirs'].append(tuple([len(self.attachments['dirs']), attachmentPath])) return 'Success: Attached Folder.' else: #self.atchList.InsertStringItem(len(self.attachments['fils']) + len(self.attachments['dirs']), attachmentPath) if attachmentPath in [fn for i, fn in self.attachments['fils']]: return 'The specified file is already attached' self.attachments['fils'].append(tuple([len(self.attachments['fils']) + len(self.attachments['dirs']), attachmentPath])) return 'Success: Attached File.' def remAttachment(self, attachmentPath): for p in [(i, fn) for i, fn in self.attachments['dirs'] if fn == attachmentPath]: self.attachments['dirs'].remove(p) return 'Success: Removed Folder' for p in [(i, fn) for i, fn in self.attachments['fils'] if fn == attachmentPath]: self.attachments['fils'].remove(p) return 'Success: Removed File' return 'There is no such attachment.'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -