; Z @c@sdkZdkZdkZdkZdkZdkZdkZdkZdkZdZ dZ da da dfdYZ de fdYZd fd YZdS( Nserl_nodes0.9iisErlMBoxcBshtZdZdZdZdZdZdZdZdZ dZ d Z d Z RS( sThis class provides an mbox, which is equivalent to an erlang-process. It is intenteded to be used in a single-threaded application. You must provide a callback routine for incoming messages.cCsB||_|tjo |i}n||_||_h|_ dS(sOThe recommended way to create mboxes is through the method CreateMBox in the ErlNode class. NODE = The node to which this mbox belongs. PID = The pid for this mbox MSG-CALLBACK = A callback to call for incoming messages to this mbox. The callback should take one argument: the message. Its return value is ignored. N( snodesselfs_nodes msgCallbacksNones_Sinks _msgCallbackspids_pids _pendingRPCs(sselfsnodespids msgCallback((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys__init__6s      cCs |iSdS(sfReturn the pid for this mbox. Returns: Throws: nothing N(sselfs_pid(sself((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysSelfKscCs|ii|||dS(saSend, to DEST, the message MSG. DEST = | string | | tuple(NODE, PROC-NAME) NODE = PROC-NAME = string | The destination to which the message is to be sent. This can is either a pid for an mbox (on the same node or on a different node), or a registered name (as string or atom) on the same node, or a tuple specifying a node and a registered name on that node. MSG = The message to be sent. Returns: void Throws: <> Send a message. There is no result indicating whether the delivery of the message was successful or not. If the DEST is located on another node, a connection to that node is automatically set up and maintained, unless already connected. This method returns immediately. Any necessarry queuing, possibly due to network traffic congestion, is handled automatically by the node. N(sselfs_nodesSendMsgFromMBoxsdestsmsg(sselfsdestsmsg((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysSendSscCs|ii||dS(sRegister a NAME for this mbox. NAME = string | The name to register this mbox as. Returns: void Throws: <> Only on name can be registered for each mbox. N(sselfs_nodesRegisterNameForMBoxsname(sselfsname((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys RegisterNameps cCs|ii|dS(s{Unregister the name that was registered for this mbox. Returns: void Throws: <> N(sselfs_nodesUnregisterNameForMBox(sself((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysUnregisterName}scCsdS(sOLink this mbox to another pid/mbox. Currently, this is not implemented.N((sselfsotherEnd((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysLinkscCsdS(sDUnlink another pid/mbox. Currently, this is not implemented.N((sselfsotherEnd((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysUnlinkscCs/|iid}|i|||||dS(sTSend an rpc to REMOTE-NODE, MOD, FUN, ARGS. Call CB for the answer. REMOTE-NODE = string | The node to send the call to MOD = string | The module FUN = string | The name of the function to call ARGS = list() The argument list CB = REMOTE-NODE = string RESULT = A callback function to be called when the answer to the rpc callback receives. The callback is called with one arg: the result. Its return value is ignored. If the remote node goes down during execution, the callback is called with this value: tuple(, tuple(, )>)) Returns: void Throws: <> Send an request to execute a function in a module on a remote node. As for the Send method, this method returns immediately. srexN( sselfs_nodes WhereisMBoxsrexMBoxsSendRPCs remoteNodesmodsfunsargsscb(sselfs remoteNodesmodsfunsargsscbsrexMBox((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysSendRPCscCs|i|dS(sThis routine is intended to be called only from mbox's node. SOURCE-NODE-NAME = string MSG = Returns: void Throws: nothing An incoming message N(sselfs _msgCallbacksmsg(sselfssourceNodeNamesmsg((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysMsgs cOsdS(s Message sink.N((sselfsaskw((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys_Sinks( s__name__s __module__s__doc__s__init__sSelfsSends RegisterNamesUnregisterNamesLinksUnlinksSendRPCsMsgs_Sink(((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysErlMBox0s        # s _ErlRexMBoxcBsDtZdZdZdZdZdZdZdZRS(sThis class implements what's needed for the rpc (remote procedure call) functionality. It is an mbox that registers itself as "rex". cCs#ti|||th|_dS(N(sErlMBoxs__init__sselfsnodespidsNones_nodeDownSubscriptions(sselfsnodespid((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys__init__scCs|iddS(Nsrex(sselfs RegisterName(sself((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysStartsc CsKt|tijoti|}nt|tijoti|}nt|tijo |}nti |o |i }n|i i |o|i |i|n|g|i |<|ii | o&|ii|i}||i| The node to send the call to MOD = string | The module FUN = string | The name of the function to call ARGS = list() The argument list CB = REMOTE-NODE = string RESULT = A callback function to be called when the answer to the rpc callback receives. The callback is called with one arg: the result. Its return value is ignored. If the remote node goes down during execution, the callback is called with this value: tuple(, tuple(, )>)) Returns: void Throws: <> Send an request to execute a function in a module on a remote node. As for the Send method, this method returns immediately. srexscallsuserN(stypesmodstypess StringTypeserl_termsErlAtomsfuns remoteNodesremoteNodeNames IsErlAtomsatomTextsselfs _pendingRPCsshas_keysappendscbs_nodeDownSubscriptionss_nodesNodeDownSubscribes _NodeDownsidsSendsSelfsargs(sselfs remoteNodesmodsfunsargsscbsidsremoteNodeName((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysSendRPCs"  cCst|tijoNt|djo;ti|do'|didjot|i djo|i ||dnt i d| dS(sThis routine is intended to be called only from mbox's node. SOURCE-NODE-NAME = string MSG = Returns: void Throws: nothing An incoming message iisrexisREX: Unexpected msg: %sN(stypesmsgstypess TupleTypeslenserl_terms IsErlAtomsatomTextsselfs _pendingRPCss _RPCAnswerssourceNodeNames erl_commonsDebug(sselfssourceNodeNamesmsg((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysMsg s gcCsM|ii|o6|i|}|d}|d|i|<||ndS(Nii(sselfs _pendingRPCsshas_keyssourceNodeNames pendingRPCsscbsanswer(sselfssourceNodeNamesanswerscbs pendingRPCs((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys _RPCAnswer s   cCsw|ii|o`|i|}g|i| Creates an ErlNode. The name of the node is determined by NODE-NAME as described below. A node-name consists of two parts: an alive-name and a host-name, separated by an `@'. The host-name can be short (not including the domain) or long (including the domain). Short and long node-names must not be mixed among the nodes in a system, see the erlang documentation for further details. 1. If the NODE-NAME contains an `@', then NODE-NAME is used unchanged as name for the node. 2. If the NODE-NAME does not contain an `@', then the node's name is constructed as NODE-NAME + "@" + host-name, where host-name is either on short or long form, depending on what is specified in the OPTS. iN("soptssGetShortNodeNamessshortNodeNamess erl_commons AlignNodeNamesnodeNamesselfs _nodeNames_optss _creations _connectionsserl_epmdsErlEpmds_epmds _ongoingPingss_isServerPublisheds_pidss_mboxess_registeredNamess_registeredPidss _nodeUpCbs _nodeDownCbs_cbIds erl_node_connsErlNodeServerSockets_serversStarts_NodeUps _NodeDowns_PassThroughMsgs_portNums SetOwnPortNumsSetOwnNodeNames _CreateRex(sselfsnodeNamesoptssshortNodeNames((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys__init__Ps.              cCs@|i}t|||}||i|<||i|<|SdS(sCreates an mbox, which is equivalent to an erlang process. MSG-CALLBACK = A callback function to call for incoming messages. Returns: Throws: nothing This creates an mbox, which is equivalent to an erlang process. Messages to the mbox are delivered as callbacks to the callback function. N(sselfs _CreatePidsmboxPidsErlMBoxs msgCallbacksmboxs_pidss_mboxes(sselfs msgCallbacksmboxPidsmbox((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys CreateMBoxs    cCsd|j od|n|ii|o%|i|}||g|i| The node to ping PING-CALLBACK = A callback to call for deliverance of the ping result. RESULT = "pong" | "pang". Returns: void Throws: <> Try to ping a remote node. A connection to that node is established unless already connected. Whether or not the remote node is up or down is indicated as by the argument to the callback function: "pong": the remote node is alive and there is a connection to it "pang": the remote node is down. s@s"Bad node name for remote node "%s"N(sremoteNodeNamesselfs _ongoingPingsshas_keys pingCallbackss pingCallbacksstringssplitsnodeNameshostNameserl_epmdsErlEpmdses erl_commonsCallbacks_PingEpmdResponsescbsPortPlease2Req(sselfsremoteNodeNames pingCallbacksesnodeNamescbshostNames pingCallbacks((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysPings cCs,|i o|ii|i|indS(sPublish this node to the EPMD, the Erlang Portmapper Daemon. Returns: void Throws: nothing. Publishing must be done for mboxes/processes on other nodes to be able to establish contact with mboxes on this node. The node is published automatically when it tries to contact another node, for example due to a message to send or an rpc call. N(sselfs_isServerPublisheds_epmdsConnects_EpmdConnectedOks_EpmdConnectFailed(sself((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysPublishs  cCs(|io|iid|_ndS(siRemoves the publication of this node to the EPMD. Returns: void Throws: nothing iN(sselfs_isServerPublisheds_epmdsClose(sself((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys Unpublishs  cCs7|i}|id|_|ii||f|SdS(s/Subscribe to nodeup-information CB = Returns: ID = Throws: nothing Subscribe to nodeup-information, that is, to connections to new nodes. The new connections may initiated by, for example, a messages begin sent from this node to another one (a new connection is automatically set up), or by another node connection to this. The ID returned can be used to unsubscribe the callback from further nodeup-informations. iN(sselfs_cbIdsids _nodeUpCbsappendscb(sselfscbsid((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysNodeUpSubscribes  cCsa|i}xQtttt||D]1\}\}}||jo|i|=dSq(q(WdS(sUnsubscribe to nodeup-information ID = Returns: void Throws: nothing Unsubscribes to nodeup-information. N( sselfs _nodeUpCbscbssmapsNonesrangeslensindexscbidscbsid(sselfsidsindexscbscbsscbid((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysNodeUpUnsubscribes    cCs7|i}|id|_|ii||f|SdS(sSubscribe to nodedown-information for a certain node CB = Returns: ID = Throws: nothing Subscribe to nodedown-information, that is, to broken connections to other nodes. The ID returned can be used to unsubscribe the callback from further nodedown-informations. iN(sselfs_cbIdsids _nodeDownCbsappendscb(sselfscbsid((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysNodeDownSubscribes  cCsa|i}xQtttt||D]1\}\}}||jo|i|=dSq(q(WdS(sUnsubscribe to nodedown-information ID = Returns: void Throws: nothing Unsubscribes to nodedown-information. N( sselfs _nodeDownCbscbssmapsNonesrangeslensindexscbidscbsid(sselfsidsindexscbscbsscbid((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysNodeDownUnsubscribes    cCs@dGHx/|iiD]}d| |i| fGHqWdGHdS(syDump connections. This method is intended for debugging purposes. Returns: void Throws: nothing s Connections:s %s --> %ss--N(sselfs _connectionsskeyssk(sselfsk((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysDumpConnectionss cCsd|i}|ii|o dn|ii|o dn||i|<||i| NAME = string Returns: void Throws: <> s IsRegisteredN(smboxsSelfsmboxPidsselfs_registeredNamesshas_keysnames_registeredPids(sselfsmboxsnamesmboxPid((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysRegisterNameForMBox s    cCsO|i}|ii| o dn|i|}|i|=|i|=dS(sThis routine is intended to be called from an ErlMBox instance MBOX = Returns: void Throws: <> s NotRegisteredN(smboxsSelfsmboxPidsselfs_registeredPidsshas_keysnames_registeredNames(sselfsmboxsmboxPidsname((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysUnregisterNameForMBox/s    cCsO|i|}|tjotSn|ii| otSn|i|SdS(sLookup an mbox that is registered under a name. NAME = string Returns: Throws: nothing N(sselfs WhereisPidsnamesmboxPidsNones_pidsshas_key(sselfsnamesmboxPid((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys WhereisMBox=s cCs+|ii| otSn|i|SdS(sLookup an mbox that is registered under a name. NAME = string Returns: Throws: nothing N(sselfs_registeredNamesshas_keysnamesNone(sselfsname((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys WhereisPidJsc Cs)|i|}t|tijoti |}nt|ti jov|d}|d}t|tijoti |}nt|tijoti |}n||f}nt|ti jo|d}|d}ntti|o<|}|i} |ii|  odSn|i| }n(ti|o|}|i}ndS||jo:|ii| odSn|i|} | i|n||i|i}|ii| o;ti|i||||} |i}|i!|| n|id||||dS(sThis routine is intended to be called from an ErlMBox instance SOURCE-MBOX = DEST = | string | | tuple(DEST-NODE, DEST-REGNAME) DEST-NODE = DEST-REGNAME = string | MSG = Returns: void THrows: <> iiNspong("sselfs_mboxess sourceMBoxs sourcePidstypesdeststypess StringTypeserl_termsErlAtoms TupleTypes destPidNamesdestNodesdestPids IsErlAtomsatomTextsnames_registeredNamesshas_keysIsErlPidsnodes_registeredPidss_registredPidssmboxsMsgsmsgsPublishs destNodeNames _connectionss erl_commonsCallbacks_SendMsgToRemoteNodescbsPing( sselfs sourceMBoxsdestsmsgsdestNodes destPidNamesdestPids destNodeNames sourcePidscbsmboxsname((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pysSendMsgFromMBoxUsN              cCsC|i}t||}||i|<||i|<|idS(N(sselfs _CreatePidsmboxPids _ErlRexMBoxsmboxs_pidss_mboxessStart(sselfsmboxPidsmbox((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys _CreateRexs    cCsqtiti|itt|i}tdatdjo+datdatdjo daqin|SdS(sReturns: iiiiN( serl_termsErlPidsErlAtomsselfs _nodeNames _pidCounts_serials _creationsnewPid(sselfsnewPid((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys _CreatePids    cCsd|_||_dS(sTThis callback is called when the publish to EPMD has successfully completed.iN(sselfs_isServerPublishedscreations _creation(sselfscreation((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys_EpmdConnectedOks cCsd|dS(NsFailed to connect to epmd (%d)(s errorResult(sselfs errorResult((sL/mnt/gmirror/ports/devel/py_otp_interface/work/py_interface-0.93/erl_node.pys_EpmdConnectFailedscCsRtitd||f||i|