Beispiel #1
0
    def wrap(self, value, force_wrapper=True):  # _wrapobject

        if self.instance_type is None or not isinstance(value, self.instance_type):
            try:
                value = self.normalise_for_wrapping(value)
            except (TypeError, ValueError), error:
                raise_as(error, WrapError)
Beispiel #2
0
    def wrap(self, value, force_wrapper=True):  # _wrapobject

        if self.instance_type is None or not isinstance(
                value, self.instance_type):
            try:
                value = self.normalise_for_wrapping(value)
            except (TypeError, ValueError), error:
                raise_as(error, WrapError)
Beispiel #3
0
    def _send_method_exchange(self, xml_data):  # AzureusLink
        from dopal.debug import ConnectionExchangeDebug, \
            ErrorLinkDebug, OutgoingExchangeDebug

        cgi_path = self.get_cgi_path(auth_details=False)
        printable_path = self.get_cgi_path(auth_details=True,
                                           include_password=False)

        if self.debug is not None:
            debug_data = OutgoingExchangeDebug(printable_path, xml_data)
            self.debug(debug_data)

        import socket, urllib2
        request = urllib2.Request(cgi_path, xml_data)

        # Add User-Agent string.
        from dopal import __user_agent__
        request.add_header("User-agent", __user_agent__)

        # Add authorisation data.
        if self.link_data['user']:
            auth_string = ("%(user)s:%(password)s" % self.link_data)
            base64_string = auth_string.encode('base64').strip()
            request.add_header("Authorization", "Basic " + base64_string)
            del auth_string, base64_string

        try:
            req = self._send_data(request)
            data = req.read()
            req.close()
        except (urllib2.URLError, socket.error, LinkError), error:

            # Log the error, if enabled.
            if self.debug is not None:
                debug_data = ErrorLinkDebug(printable_path, error)
                self.debug(debug_data)

            # Error raised here.
            raise_as(error, LinkError, obj=cgi_path)
Beispiel #4
0
    def _send_method_exchange(self, xml_data): # AzureusLink
        from dopal.debug import ConnectionExchangeDebug, \
            ErrorLinkDebug, OutgoingExchangeDebug

        cgi_path = self.get_cgi_path(auth_details=False)
        printable_path = self.get_cgi_path(auth_details=True, include_password=False)

        if self.debug is not None:
            debug_data = OutgoingExchangeDebug(printable_path, xml_data)
            self.debug(debug_data)

        import socket, urllib2
        request = urllib2.Request(cgi_path, xml_data)

        # Add User-Agent string.
        from dopal import __user_agent__
        request.add_header("User-agent", __user_agent__)

        # Add authorisation data.
        if self.link_data['user']:
            auth_string = ("%(user)s:%(password)s" % self.link_data)
            base64_string = auth_string.encode('base64').strip()
            request.add_header("Authorization", "Basic " + base64_string)
            del auth_string, base64_string

        try:
            req = self._send_data(request)
            data = req.read()
            req.close()
        except (urllib2.URLError, socket.error, LinkError), error:

            # Log the error, if enabled.
            if self.debug is not None:
                debug_data = ErrorLinkDebug(printable_path, error)
                self.debug(debug_data)

            # Error raised here.
            raise_as(error, LinkError, obj=cgi_path)