Package dopal :: Module core
[show private | hide private]
[frames | no frames]

Module dopal.core

Contains the main objects and functions required for DOPAL to be useful.
Classes
AtomicResponse  
AzureusConnection  
AzureusLink  
AzureusResponse  
ErrorResponse  
ExtendedAzureusConnection  
NullResponse A response class which is used when Azureus returns a response which contains no content at all.
ReusableAzureusConnection  
StructuredResponse  

Function Summary
  generate_remote_error(message)
  process_xml_response(xml_node)
  remote_method_call_as_xml(method_name, method_args, request_id, object_id, connection_id)
Generates an XML block which can be sent to Azureus to invoke a remote method - this is returned as an object which can be turned into a unicode string.
  remote_method_call_to_xml(method_name, method_args, request_id, object_id, connection_id)
Deprecated: Use remote_method_call_as_xml instead.

Function Details

remote_method_call_as_xml(method_name, method_args, request_id, object_id=None, connection_id=None)

Generates an XML block which can be sent to Azureus to invoke a remote method - this is returned as an object which can be turned into a unicode string.

An example of the output generated by this method:
 >>> remote_method_call_as_xml('getDownloads', [True], request_id=123, object_id=456, connection_id=789).encode('UTF-8')

 <?xml version="1.0" encoding="UTF-8"?>
 <REQUEST>
   <OBJECT>
     <_object_id>456</_object_id>
   </OBJECT>
   <METHOD>getDownloads[boolean]</METHOD>
   <PARAMS>
     <ENTRY index="0">true</ENTRY>
   </PARAMS>
   <CONNECTION_ID>789</CONNECTION_ID>
   <REQUEST_ID>123</REQUEST_ID>
 </REQUEST>
The method_args parameter needs to be a sequence of items representing the method you want to invoke. Each argument needs to be one of the following types:
  • boolean (represented in Java as a boolean)
  • int (represented in Java as an int)
  • long (represented in Java as a long)
  • str or unicode (represented in Java as a String)
  • float (represented in Java as a float)
  • An object with a get_xml_type method, which returns a string representing the name of the Java data type that it represents. It needs to also have one other method on it:
    • get_object_id - needs to return the remote ID of the Azureus object it is representing; or
    • as_xml - returns an object which can be converted into a string containing XML representing the value of this object. Several other types are supported using this method, defined in the aztypes module (such as java.net.URL, byte[] etc.)
Parameters:
method_name - A string representing the name of the method you want to invoke (which must either be a method available on the object with the given object ID, or a special global method which Azureus has some special case behaviour for).
           (type=str / unicode)
method_args - A sequence of items representing the arguments you want to pass to the method (definition of what types are accepted are explained above).
request_id - The unique ID to be given to this invocation request (each invocation on a connection must be unique).
           (type=str / unicode / int / long)
object_id - The object on which to invoke the method on. There are some methods which are special cased which don't require an object ID - in these cases, this can be left as None.
           (type=str / unicode / int / long / None)
connection_id - The ID of the connection you are using - this value is given to you once you have initiated a connection with Azureus - this can be left blank if you haven't yet initiated the connection.
           (type=str / unicode / int / long / None)
Returns:
An object which has an encode method (to convert the XML into the specified bytestring representation. The object can also be converted into a unicode string via the unicode function. Currently, this object will be an instance of UXMLObject, but this behaviour may change in future - the only guarantees this function makes is the fact that the resulting object can be converted into unicode, and that it will have an encode method on it.
Raises:
InvalidWrapTypeError - Raised if one of the items in the method_args sequence does not match one of the accepted types.

Attention: Any byte strings passed to this function will be treated as if they are text strings, and they can be converted to unicode using the default system encoding. If the strings represented encoded content, you must decode them to unicode strings before passing to this function.

Note: This function will return an object which has an encode method (to convert the XML into the specified bytestring representation. The object can also be converted into a unicode string via the unicode function. Currently, this object will be an instance of UXMLObject, but this behaviour may change in future - the only guarantees this function makes is the fact that the resulting object can be converted into unicode, and that it will have an encode method on it.

See Also:
aztypes, InvalidWrapTypeError, UXMLObject

remote_method_call_to_xml(method_name, method_args, request_id, object_id=None, connection_id=None)

Generates an XML block which can be sent to Azureus to invoke a remote method.

An example of the output generated by this method:
 >>> remote_method_call_to_xml('getDownloads', [True], request_id=123, object_id=456, connection_id=789)

 <REQUEST>
   <OBJECT>
     <_object_id>456</_object_id>
   </OBJECT>
   <METHOD>getDownloads[boolean]</METHOD>
   <PARAMS>
     <ENTRY index="0">true</ENTRY>
   </PARAMS>
   <CONNECTION_ID>789</CONNECTION_ID>
   <REQUEST_ID>123</REQUEST_ID>
 </REQUEST>
The method_args parameter needs to be a sequence of items representing the method you want to invoke. Each argument needs to be one of the following types:
  • boolean (represented in Java as a boolean)
  • int (represented in Java as an int)
  • long (represented in Java as a long)
  • str or unicode (represented in Java as a String)
  • float (represented in Java as a float)
  • An object with a get_xml_type method, which returns a string representing the name of the Java data type that it represents. It needs to also have one other method on it:
    • get_object_id - needs to return the remote ID of the Azureus object it is representing; or
    • as_xml - returns an object which can be converted into a string containing XML representing the value of this object. Several other types are supported using this method, defined in the aztypes module (such as java.net.URL, byte[] etc.)
Parameters:
method_name - A string representing the name of the method you want to invoke (which must either be a method available on the object with the given object ID, or a special global method which Azureus has some special case behaviour for).
           (type=str)
method_args - A sequence of items representing the arguments you want to pass to the method (definition of what types are accepted are explained above).
request_id - The unique ID to be given to this invocation request (each invocation on a connection must be unique).
           (type=str / int / long)
object_id - The object on which to invoke the method on. There are some methods which are special cased which don't require an object ID - in these cases, this can be left as None.
           (type=str / int / long / None)
connection_id - The ID of the connection you are using - this value is given to you once you have initiated a connection with Azureus - this can be left blank if you haven't yet initiated the connection.
           (type=str / int / long / None)
Returns:
A string representing the XML block to send.
Raises:
InvalidWrapTypeError - Raised if one of the items in the method_args sequence does not match one of the accepted types.

Attention: Deprecated: This method is not unicode-safe, nor does it define what happens when dealing with unicode data. Use remote_method_call_as_xml instead.

See Also:
aztypes, InvalidWrapTypeError

Generated by Epydoc 2.1 on Wed May 03 14:22:33 2006 http://epydoc.sf.net