1# -*- coding: utf-8 -*- 2# 3# (c) Copyright 2003-2015 HP Development Company, L.P. 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write to the Free Software 17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18# 19# Author: Don Welch 20# 21 22 23 24# Std Lib 25import sys 26import os 27import time 28from base.sixext import BytesIO 29import re 30 31# Local 32from base.g import * 33from base.codes import * 34from base import device, utils, codes, dime 35from .fax import * 36from .ledmfax import * 37from .soapfax import SOAPFaxSendThread 38from .soapfax import SOAPFaxDevice 39 40 41# **************************************************************************** # 42class LEDMSOAPFaxDevice(SOAPFaxDevice): 43 44 45 def __init__(self, device_uri=None, printer_name=None, 46 callback=None, 47 fax_type=FAX_TYPE_NONE, 48 disable_dbus=False): 49 50 SOAPFaxDevice.__init__(self, device_uri, 51 printer_name, 52 callback, fax_type, 53 disable_dbus) 54 55 #LEDM Specific functions 56 def put(self, url, post): 57 data = """PUT %s HTTP/1.1\r 58Connection: Keep-alive\r 59User-agent: hplip/2.0\r 60Host: %s\r 61Content-length: %d\r 62\r 63%s""" % (url, self.http_host, len(post), post) 64 log.log_data(data) 65 self.writeEWS_LEDM(data.encode('utf-8')) 66 response = BytesIO() 67 68 while self.readEWS_LEDM(4096, response, timeout=5): 69 pass 70 71 response = response.getvalue() 72 log.log_data(response.decode('utf-8')) 73 self.closeEWS_LEDM() 74 75 match = http_result_pat.match(response) 76 if match is None: return HTTP_OK 77 try: 78 code = int(match.group(1)) 79 except (ValueError, TypeError): 80 code = HTTP_ERROR 81 82 return code == HTTP_OK 83 84 85 def setPhoneNum(self, num): 86 xml = setPhoneNumXML %(num) 87 log.debug("SetPhoneNum:xml Value:%s" %xml) 88 return self.put("/DevMgmt/FaxConfigDyn.xml", xml) 89 90 91 def getPhoneNum(self): 92 return self.readAttributeFromXml_EWS("/DevMgmt/FaxConfigDyn.xml",'faxcfgdyn:faxconfigdyn-faxcfgdyn:systemsettings-dd:phonenumber') 93 94 phone_num = property(getPhoneNum, setPhoneNum) 95 96 97 def setStationName(self, name): 98 try: 99 xml = setStationNameXML %name 100 except(UnicodeEncodeError, UnicodeDecodeError): 101 log.error("Unicode Error") 102 103 return self.put("/DevMgmt/FaxConfigDyn.xml", xml) 104 105 106 def getStationName(self): 107 return self.readAttributeFromXml_EWS("/DevMgmt/FaxConfigDyn.xml",'faxcfgdyn:faxconfigdyn-faxcfgdyn:systemsettings-dd:companyname') 108 109 station_name = property(getStationName, setStationName) 110 111 112 def setDateAndTime(self): 113 t = time.localtime() 114 date_buf = "%4d-%02d-%02dT%02d:%02d:%02d" % (t[0], t[1], t[2], t[3], t[4], t[5]) 115 xml = setDateTimeXML %(date_buf) 116 log.debug("setDateTimeXML Value:%s" %xml) 117 118 if self.put("/DevMgmt/ProductConfigDyn.xml", xml): 119 return True 120 else: 121 log.debug ("Failed to set date and time. Set date and time using front panel.") 122 return False 123