|
|
@ -20,24 +20,46 @@ |
|
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
|
|
|
|
|
|
from base64 import encodestring |
|
|
|
import string |
|
|
|
from base64 import b64encode |
|
|
|
import httplib |
|
|
|
import xmlrpclib |
|
|
|
|
|
|
|
|
|
|
|
class BasicAuthTransport(xmlrpclib.Transport): |
|
|
|
def __init__(self, username=None, password=None): |
|
|
|
def __init__(self, secure=False, username=None, password=None): |
|
|
|
xmlrpclib.Transport.__init__(self) |
|
|
|
|
|
|
|
self.secure = secure |
|
|
|
|
|
|
|
self.username = username |
|
|
|
self.password = password |
|
|
|
|
|
|
|
def send_auth(self, h): |
|
|
|
if self.username is not None and self.password is not None: |
|
|
|
h.putheader('AUTHORIZATION', "Basic %s" % string.replace( |
|
|
|
encodestring("%s:%s" % (self.username, self.password)), |
|
|
|
"\012", "" |
|
|
|
)) |
|
|
|
if not self.username or not self.password: |
|
|
|
return |
|
|
|
|
|
|
|
auth = b64encode("%s:%s" % (self.username, self.password)) |
|
|
|
|
|
|
|
h.putheader('Authorization', "Basic %s" % auth) |
|
|
|
|
|
|
|
def make_connection(self, host): |
|
|
|
if self._connection and host == self._connection[0]: |
|
|
|
return self._connection[1] |
|
|
|
|
|
|
|
chost, self._extra_headers, x509 = self.get_host_info(host) |
|
|
|
|
|
|
|
if self.secure: |
|
|
|
try: |
|
|
|
self._connection = host, httplib.HTTPSConnection(chost, None, **(x509 or {})) |
|
|
|
except AttributeError: |
|
|
|
raise NotImplementedError( |
|
|
|
"your version of httplib doesn't support HTTPS" |
|
|
|
) |
|
|
|
else: |
|
|
|
self._connection = host, httplib.HTTPConnection(chost) |
|
|
|
|
|
|
|
return self._connection[1] |
|
|
|
|
|
|
|
|
|
|
|
def single_request(self, host, handler, request_body, verbose=0): |
|
|
|
# issue XML-RPC request |
|
|
|