#
# Copyright (c) 2010 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#


import urllib
import urllib2
import urlparse

class Client(object):
    def __init__(self, url):
        self.url = url

    def request(self, data=None):
        print data
        return
        self.response = urllib.urlopen(self.url, data)
        self.responseBody = self.response.read()
        return self.responseBody

class ActivationClient(Client):
    def activate(self, data):
        print data
        # return None
        return data
        return self.request(data)

@@ -572,17 +572,31 @@
 ils.%0A#%0A%0A
+import logging
 %0A
-
 import u
@@ -633,16 +633,58 @@
 lparse%0A%0A
+logger = logging.getLogger('activation')%0A%0A
 class Cl
@@ -796,33 +796,52 @@
     
-print data%0A        return
+logger.debug(%22POSTing XML data:%5Cn%25s%22 %25 data)
 %0A   
@@ -941,38 +941,34 @@
 .read()%0A        
-return
+if
  self.responseBo
@@ -965,20 +965,106 @@
 response
-Body
+.code == self.SUCCESS_CODE:%0A            return True%0A        else:%0A            return False
 %0A%0Aclass 
@@ -1085,24 +1085,49 @@
 nt(Client):%0A
+%0A    SUCCESS_CODE = 201%0A%0A
     def acti
@@ -1156,91 +1156,282 @@
     
-print data%0A        # return None%0A        return data%0A        return self.request(data)
+activated = self.request(data)%0A%0A        if not activated:%0A            logger.error(%22Failed activation with %25s.%22 %25 self.url)%0A            logger.error(%22Response code: %25s%22 %25 self.response.code)%0A            logger.error(%22Response: %25s%22 %25 self.responseBody)%0A%0A        return activated
 %0A

Make ActivationClient look for correct return code