Tizen 2.1 base
[platform/upstream/hplip.git] / fax / ledmsoapfax.py
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2003-2007 Hewlett-Packard 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 from __future__ import division
23
24 # Std Lib
25 import sys
26 import os
27 import time
28 import cStringIO
29 import urllib # TODO: Replace with urllib2 (urllib is deprecated in Python 3.0)
30 import re
31
32 # Local
33 from base.g import *
34 from base.codes import *
35 from base import device, utils, codes, dime
36 from fax import *
37 from ledmfax import *
38 from soapfax import SOAPFaxSendThread
39 from soapfax import SOAPFaxDevice
40
41
42 # **************************************************************************** #
43 class LEDMSOAPFaxDevice(SOAPFaxDevice):
44
45
46     def __init__(self, device_uri=None, printer_name=None,
47                  callback=None,
48                  fax_type=FAX_TYPE_NONE,
49                  disable_dbus=False):
50
51         SOAPFaxDevice.__init__(self, device_uri,
52                            printer_name,
53                            callback, fax_type,
54                            disable_dbus)
55
56     #LEDM Specific functions
57     def put(self, url, post):
58         data = """PUT %s HTTP/1.1\r
59 Connection: Keep-alive\r
60 User-agent: hplip/2.0\r
61 Host: %s\r
62 Content-length: %d\r
63 \r
64 %s""" % (url, self.http_host, len(post), post)
65         log.log_data(data)
66         self.writeEWS_LEDM(data)
67         response = cStringIO.StringIO()
68
69         while self.readEWS_LEDM(4096, response, timeout=5):
70             pass
71
72         response = response.getvalue()
73         log.log_data(response)
74         self.closeEWS_LEDM()        
75         
76         match = http_result_pat.match(response)
77         if match is None: return HTTP_OK
78         try:
79             code = int(match.group(1))
80         except (ValueError, TypeError):
81             code = HTTP_ERROR
82
83         return code == HTTP_OK
84
85
86     def setPhoneNum(self, num):
87         xml = setPhoneNumXML %(num)
88         log.debug("SetPhoneNum:xml Value:%s" %xml)
89         return self.put("/DevMgmt/FaxConfigDyn.xml", xml)
90
91
92     def getPhoneNum(self):
93         return self.readAttributeFromXml_EWS("/DevMgmt/FaxConfigDyn.xml",'faxcfgdyn:faxconfigdyn-faxcfgdyn:systemsettings-dd:phonenumber')
94
95     phone_num = property(getPhoneNum, setPhoneNum)
96
97
98     def setStationName(self, name):
99         xml = setStationNameXML %(name)
100         return self.put("/DevMgmt/FaxConfigDyn.xml", xml)
101
102
103     def getStationName(self):
104         return self.readAttributeFromXml_EWS("/DevMgmt/FaxConfigDyn.xml",'faxcfgdyn:faxconfigdyn-faxcfgdyn:systemsettings-dd:companyname')
105
106     station_name = property(getStationName, setStationName)