Example #1
0
    def add_with_url(self, url, content=None, img_filename=None):
        """
        Add (POST) a resource

        @param url: A full URL which for the resource type to create
        @param content: a string containing the full XML of new resource or an image encoded in base64.
        @param img_filename: a string containing the filename of the image.
        @return: an ElementTree of the response from the web service
        """
        if not img_filename:
            headers = {'Content-Type': 'application/x-www-form-urlencoded'}
            if self.debug and content:
                try:
                    xml = parseString(content)
                    pretty_body = xml.toprettyxml(indent="  ")
                except:
                    pretty_body = content
                print "Execute url: %s / method: POST\nbody: %s" % (url, pretty_body)

            r = self._execute(
                unicode_encode.encode(url),
                'POST',
                data=urllib.urlencode({'xml': unicode_encode.encode(content)}),
                add_headers=headers)
        else:
            img_binary = base64.decodestring(content)
            img_file = StringIO(img_binary)
            r = self._execute(url, 'POST', files={'image': (img_filename, img_file)})
        if r.headers.get('content-type') and r.headers.get('content-type').startswith('image'):
            return True
        else:
            return self._parse(r.content)
Example #2
0
    def edit_with_url(self, url, content):
        """
        Edit (PUT) a resource from a full URL

        @param url: an full url to edit a resource
        @param content: modified XML as string of the resource.
        @return: an ElementTree of the Webservice's response
        """
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        r = self._execute(unicode_encode.encode(url), 'PUT', data=unicode_encode.encode(content), add_headers=headers)
        return self._parse(r.content)
Example #3
0
    def edit_with_url(self, url, content):
        """
		Edit (PUT) a resource from a full URL

		@param url: an full url to edit a resource
		@param content: modified XML as string of the resource.
		@return: an ElementTree of the Webservice's response
		"""
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        r = self._execute(unicode_encode.encode(url),
                          'PUT',
                          data=unicode_encode.encode(content),
                          add_headers=headers)
        return self._parse(r.content)
Example #4
0
    def add_with_url(self, url, content=None, img_filename=None):
        """
        Add (POST) a resource

        @param url: A full URL which for the resource type to create
        @param content: a string containing the full XML of new resource or an image encoded in base64.
        @param img_filename: a string containing the filename of the image.
        @return: an ElementTree of the response from the web service
        """
        if not img_filename:
            headers = {'Content-Type': 'application/x-www-form-urlencoded'}
            if self.debug and content:
                try:
                    xml = parseString(content)
                    pretty_body = xml.toprettyxml(indent="  ")
                except:
                    pretty_body = content
                print "Execute url: %s / method: POST\nbody: %s" % (
                    url, pretty_body)

            r = self._execute(unicode_encode.encode(url),
                              'POST',
                              data=urllib.urlencode(
                                  {'xml': unicode_encode.encode(content)}),
                              add_headers=headers)
        else:
            img_binary = base64.decodestring(content)
            img_file = StringIO(img_binary)
            r = self._execute(url,
                              'POST',
                              files={'image': (img_filename, img_file)})
        if r.headers.get('content-type') and r.headers.get(
                'content-type').startswith('image'):
            return True
        else:
            return self._parse(r.content)