Changeset 126
- Timestamp:
- 12/27/05 05:22:24
- Files:
-
- PloneSMSCommunicator/trunk/Extensions/Install.py (modified) (5 diffs)
- PloneSMSCommunicator/trunk/HISTORY.txt (modified) (1 diff)
- PloneSMSCommunicator/trunk/PloneSMSCommunicator.py (modified) (8 diffs)
- PloneSMSCommunicator/trunk/README.txt (modified) (1 diff)
- PloneSMSCommunicator/trunk/__init__.py (modified) (1 diff)
- PloneSMSCommunicator/trunk/config.py (modified) (1 diff)
- PloneSMSCommunicator/trunk/pyXIAM.py (modified) (4 diffs)
- PloneSMSCommunicator/trunk/skins/portal_smsCommunicator/prefs_smsCommunicator_properties.cpt (modified) (3 diffs)
- PloneSMSCommunicator/trunk/tests/test_Communicator.py (modified) (1 diff)
- PloneSMSCommunicator/trunk/tests/testpyXIAM.py (modified) (1 diff)
- PloneSMSCommunicator/trunk/version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
PloneSMSCommunicator/trunk/Extensions/Install.py
r125 r126 1 # Author: Melnychuk Taras 2 # Contact: fenix@quintagroup.com 3 # Date: $Date: 2005-12-23 11:42:10 4 # Copyright: quintagroup.com 5 6 """ 7 This module is created for installing PloneSMSCommunicator tool to Plone site. It has such functions: 8 9 - `install`: this function sets all types in PloneSMSCommunicator tool, also install skin directory and other 10 - `install_configlet`: install configlet to portal control panel 11 - `remove_configlet`: remove configlet from portal control panel 12 - `uninstall`: uninstall all needed things 13 14 """ 15 __docformat__ = 'restructuredtext' 16 17 1 18 from Products.Archetypes.Extensions.utils import installTypes, install_subskin 2 19 from Products.Archetypes.public import listTypes … … 9 26 10 27 def install_configlet(self, out): 28 """ 29 install configlet to portal control panel 30 """ 11 31 control_panel=getToolByName(self,'portal_controlpanel') 12 32 control_panel.registerConfiglet(PROJECTNAME, … … 21 41 22 42 def remove_configlet(self, out): 43 """ 44 remove configlet from portal control panel 45 """ 23 46 control_panel=getToolByName(self,'portal_controlpanel') 24 47 control_panel.unregisterConfiglet(PROJECTNAME) … … 26 49 27 50 def install(self): 28 51 """ 52 this function sets all types in PloneSMSCommunicator tool, also install skin directory and other 53 """ 29 54 out=StringIO(); 30 55 installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME) … … 41 66 42 67 def uninstall(self): 68 """ 69 uninstall all needed things 70 """ 43 71 out = StringIO() 44 72 remove_configlet(self, out) PloneSMSCommunicator/trunk/HISTORY.txt
r125 r126 1 0.1.4 2005-12-27 2 ================ 3 4 - add docstring to all classes and functions 5 1 6 0.1.3 2005-11-14 2 7 ================ PloneSMSCommunicator/trunk/PloneSMSCommunicator.py
r125 r126 1 # Author: Melnychuk Taras 2 # Contact: fenix@quintagroup.com 3 # Date: $Date: 2005-11-23 11:05:50 +0200 (Thu, 23 Nov 2005) $ 4 # Copyright: quintagroup.com 5 6 """ 7 This tool talks to XIAM gateway at cellphone operator 8 via XIAM-XML protocol. You'd have to set XIAM gateway properties 9 in the tool' configlet before you are able to send SMSes. 10 This module defines the following classes: 11 12 - `PloneSMSCommunicator`, this is the tool that carries responsibility for 13 connection with server (message center) and sending via XIAM-XML protocol 14 requests(short message) to server and get responses from it 15 16 Methods: 17 18 - `PloneSMSCommunicator.setProperties`: set PloneSMSCommunicator properties 19 - `PloneSMSCommunicator.getProperties`: return all properties if ids == None, else return properties that in ids list 20 - `PloneSMSCommunicator.LOG`: write all needed data to log file 21 - `PloneSMSCommunicator.write_sms`: write sms 'in' and sms 'out' files to sms directory 22 - `PloneSMSCommunicator.send_Request`: this function will send message to destination 23 - `PloneSMSCommunicator.Response`: write all data from response to xiam.log file 24 - `PloneSMSCommunicator.getAvailableSMSPolicies`: return sms policies 25 - `PloneSMSCommunicator.getServerInfo`: return dictionary that contains host name and ip address 26 - `PloneSMSCommunicator.getLogs`: return records from log file 27 28 29 Exception classes: 30 31 - `SendMessageError` 32 33 """ 34 __docformat__ = 'restructuredtext' 35 1 36 from Products.PloneSMSCommunicator.Utils import getHostName 2 37 from urllib2 import urlopen, Request, HTTPError, URLError … … 43 78 44 79 def setProperties(self, **properties): 45 '''Set properties''' 80 """ 81 set PloneSMSCommunicator properties 82 Parameters: 83 84 -**properties: this is the dictionary that contains pair(property_name: value) 85 """ 46 86 for property in properties.keys(): 47 87 setattr(self, property, properties[property]) 48 88 49 89 def getProperties(self, ids = []): 90 """ 91 return all properties if ids == None, else return properties that in ids list 92 """ 50 93 props = {} 51 94 if ids: … … 60 103 61 104 def LOG(self, INFO, data): 62 105 """ 106 write all needed data to log file 107 Parameters: 108 109 - INFO: this is the parameter that defines priority of log data 110 - data: all needed data to write 111 """ 63 112 if self.log_flag: 64 113 log_time = DateTime().strftime("%Y/%m/%d %H:%M:%S") … … 68 117 69 118 def write_sms(self, sms_id, request = None, response = None): 119 """ 120 write sms 'in' and sms 'out' files to sms directory 121 Parameters: 122 123 - sms_id: id of your short message 124 - request: this is the data that was sent 125 - response: this is the data that was received from server 126 """ 70 127 if self.log_flag: 71 128 #create sms directory … … 84 141 85 142 def send_Request(self, originator, destination, body): 86 """Send message""" 143 """ 144 This function will send message to destination. 145 Parameters: 146 147 - originator: contains phone number of message originator 148 - destination: contains phone number of destination 149 - body: this is the text of your message 150 """ 87 151 response = StringIO() 88 152 request=SMSsubmitRequest(originator, destination, body) … … 111 175 112 176 def Response(self, REQUEST = None): 113 """write all data from response to xiam.log file""" 177 """ 178 write all data from response to xiam.log file 179 """ 114 180 stream = REQUEST.stdin 115 181 stream.seek(0) … … 119 185 120 186 def getAvailableSMSPolicies(self): 187 """ 188 return sms policies 189 """ 121 190 return ['free', 'enforceOriginator'] 122 191 123 192 def getServerInfo(self, server_url): 193 """ 194 return dictionary that contains host name and ip address 195 Parameters: 196 197 - server_url: url address of server 198 """ 124 199 info = {} 125 200 info['host_name'] = getHostName(server_url) … … 128 203 129 204 def getLogs(self, size): 205 """ 206 return records from log file 207 Parameters: 208 209 - size: number of needed records 210 """ 130 211 line = '' 131 212 result = [] PloneSMSCommunicator/trunk/README.txt
r125 r126 1 This product is one of SMSBundle poroducts. It responses for2 sending requests and for geting responses from provider.3 1 2 PloneSMSCommunicator/trunk/__init__.py
r125 r126 1 # Author: Melnychuk Taras 2 # Contact: fenix@quintagroup.com 3 # Date: $Date: 2005-12-23 11:54:22 4 # Copyright: quintagroup.com 5 6 """ 7 This is the init module for PloneSMSCommunicator that will initialize all 8 types in tool. 9 """ 10 __docformat__ = 'restructuredtext' 11 1 12 from Products.CMFCore.DirectoryView import registerDirectory 2 13 from Products.Archetypes.public import * PloneSMSCommunicator/trunk/config.py
r125 r126 8 8 COMMUNICATORID="portal_smsCommunicator" 9 9 PROVIDER='172' 10 SERVER_URL='http:// localhost:10010/'#'http://193.95.160.218:8080/smsxml/collector'10 SERVER_URL='http://193.95.160.218:8080/smsxml/collector' 11 11 CLIENT_HOME = os.environ.get("CLIENT_HOME") 12 12 XIAM_LOG = CLIENT_HOME + '/xiam.log' PloneSMSCommunicator/trunk/pyXIAM.py
r125 r126 1 # Author: Melnychuk Taras 2 # Contact: fenix@quintagroup.com 3 # Date: $Date: 2005-12-23 11:56:23 +0200 (Fri, 23 Dec 2005) $ 4 # Copyright: quintagroup.com 5 6 """ 7 pyXIAM is module that defines such classes and functions: 8 9 - `SMSsubmitRequest`, this class define SMSsubmitRepuest type and takes responsibility 10 for creating instance of this class and converting it to xml format. 11 12 Methods: 13 14 - `SMSsubmitRequest.genSMS_id`: generate id for message 15 - `SMSsubmitRequest.toXML`: convert SMSsubmitRequest instance to xml format 16 Functions: 17 18 - `getAllTextFromTag`: return list of text elements that is nested in 'tag_name' 19 20 Exception classes: 21 22 - `DestinatioNumberError` 23 - `NoOriginatorError` 24 25 """ 26 27 __docformat__ = 'restructuredtext' 28 1 29 from DateTime import DateTime 2 30 from xml.dom.minidom import * 3 31 4 32 def getAllTextFromTag(doc, tag_name): 33 """ 34 return list of text elements that is nested in 'tag_name' 35 Parameters: 36 37 - `doc`: this parameter must contain xml document 38 - `tag_name`: this is the name of needed tag 39 """ 5 40 text = '' 6 41 result = [] … … 93 128 94 129 class SMSsubmitRequest: 130 """ 131 This class define SMSsubmitRepuest type and takes responsibility 132 for creating instance of this class and converting it to xml format. 133 134 Fields: 135 136 - id: sms id 137 - originator: contains phone number of message originator 138 - destination: contains phone number of destination 139 - body: this is the text of your message 140 """ 95 141 def __init__(self, originator, destination, body): 96 142 self.id = self.genSMS_id() … … 100 146 101 147 def genSMS_id(self): 148 """ 149 generate id for message 150 """ 102 151 sms_id = "quinta%s" % DateTime().strftime("%Y%m%d%H%M%S") 103 152 return sms_id 104 153 105 154 def toXML(self): 106 """convert SMSsubmitRequest to XML format""" 155 """ 156 convert SMSsubmitRequest instance to xml format 157 """ 107 158 if not self.id: 108 159 id = "quinta5" … … 127 178 originator_element=doc.createElement("from") 128 179 number=doc.createTextNode(str(self.originator)) 129 originator_element.appendChild(number)180 originator_element.appendChild(number) 130 181 request_element.appendChild(originator_element) 131 182 PloneSMSCommunicator/trunk/skins/portal_smsCommunicator/prefs_smsCommunicator_properties.cpt
r125 r126 53 53 <dl class="serverInfo" 54 54 style="float: right;"> 55 <dt>Server IP :</dt>55 <dt>Server IP Address:</dt> 56 56 <dd tal:content = "info/ip_addr"/> 57 57 <dt>Server Name:</dt> 58 58 <dd tal:content = "info/host_name"/> 59 <dt> Response function:</dt>59 <dt>Address of responce function:</dt> 60 60 <dd tal:content = "python: '/'+context['id']+'/portal_smsCommunicator/Response' "/> 61 61 </dl> 62 62 <div class="field"> 63 <label i18n:translate="label_server_url"> XIAM server requestURL</label>63 <label i18n:translate="label_server_url">Server URL</label> 64 64 65 65 <div></div> … … 70 70 tal:attributes="value request/server_url|props/server_url" /> 71 71 </div> 72 <div class="field">73 <label i18n:translate="label_provider_id">Provider ID</label>74 75 <div></div>76 77 <input type="text"78 name="provider_id"79 size="20"80 tal:attributes="value props/provider_id" />81 </div>82 72 <div class="field"> 83 73 <label i18n:translate="label_policy">SMS Policy</label> … … 102 92 </div> 103 93 <div class="field"> 104 <label i18n:translate="label_log_flag">Logging enabled</label> 94 <label i18n:translate="label_provider_id">Providr ID</label> 95 96 <div></div> 97 98 <input type="text" 99 name="provider_id" 100 size="20" 101 tal:attributes="value props/provider_id" /> 102 </div> 103 <div class="field"> 104 <label i18n:translate="label_log_flag">Log Flag</label> 105 105 106 106 <div></div> PloneSMSCommunicator/trunk/tests/test_Communicator.py
r125 r126 71 71 72 72 communicator = portal.portal_smsCommunicator 73 communicator.set LogFlag(False)74 communicator.set Server('http://localhost:10010/')73 communicator.setProperties(log_flag = None) 74 communicator.setProperties(server_url = 'http://localhost:10010/') 75 75 communicator.send_Request(originator = '+380979312198', destination = ['+380979987348'], body = 'hello how are you?') 76 76 #destroy thread 77 77 del th 78 78 79 def test_Response(self): 80 portal = self.portal 81 communicator = portal.portal_smsCommunicator 82 communicator.setLogFlag(False) 83 response = """<?xml version="1.0" encoding="UTF-8"?> 84 <!DOCTYPE xiamSMS SYSTEM "xiamSMSMessage.dtd"> 85 <xiamSMS status="OK" statusText="XML contained 1 xir messages"> 86 <submitResponse id="betye54"> 87 <result status="OK" statusText="">+380979987348</result> 88 </submitResponse> 89 </xiamSMS>""" 90 out = StringIO() 91 out.write(response) 92 communicator = portal.portal_smsCommunicator 93 data = self.publish(portal.id+'/portal_smsCommunicator/Response', 'mgr:mgrpw', env=None, extra=None, request_method='POST', stdin = out) 94 response = data.getBody() 95 self.assertEqual(response, """<?xml version="1.0" ?>\n<!DOCTYPE xiamSMS SYSTEM "xiamSMSMessage.dtd" >\n<xiamSMS status="OK"><submitRsponse id="betye54">XML contained your response messages</submitRsponse></xiamSMS>""") 96 79 #def test_Response(self): 80 # portal = self.portal 81 # communicator = portal.portal_smsCommunicator 82 # communicator.setProperties(log_flag = 'False') 83 # response = """<?xml version="1.0" encoding="UTF-8"?> 84 # <!DOCTYPE xiamSMS SYSTEM "xiamSMSMessage.dtd"> 85 # <xiamSMS status="OK" statusText="XML contained 1 xir messages"> 86 # <submitResponse id="betye54"> 87 # <result status="OK" statusText="">+380979987348</result> 88 # </submitResponse> 89 # </xiamSMS>""" 90 # out = StringIO() 91 # out.write(response) 92 # communicator = portal.portal_smsCommunicator 93 # data = self.publish(portal.id+'/portal_smsCommunicator/Response', 'mgr:mgrpw', env=None, extra=None, request_method='POST', stdin = out) 94 # response = data.getBody() 95 # self.assertEqual(response, """<?xml version="1.0" ?>\n<!DOCTYPE xiamSMS SYSTEM "xiamSMSMessage.dtd" >\n<xiamSMS status="OK"><submitRsponse id="betye54">XML contained your response messages</submitRsponse></xiamSMS>""") 97 96 98 97 tests.append(TestPloneSMSCommunicator) PloneSMSCommunicator/trunk/tests/testpyXIAM.py
r125 r126 16 16 def afterSetUp(self): 17 17 portal = self.portal 18 sms=S mSsubmitRequest(originator = '+380979312198', destination = ['+380979987348'], body = 'hello how are you?')18 sms=SMSsubmitRequest(originator = '+380979312198', destination = ['+380979987348'], body = 'hello how are you?') 19 19 self.doc = sms.toXML() 20 20 self.doc = parseString(self.doc) PloneSMSCommunicator/trunk/version.txt
r125 r126 1 0.1. 31 0.1.4
