home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnb101.zip / Lib / site-packages / Fnorb / orb / IOP.py < prev    next >
Text File  |  1999-06-28  |  13KB  |  301 lines

  1. #!/usr/bin/env python
  2. #############################################################################
  3. # Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 1997, 1998, 1999
  4. # All Rights Reserved.
  5. #
  6. # The software contained on this media is the property of the DSTC Pty
  7. # Ltd.  Use of this software is strictly in accordance with the
  8. # license agreement in the accompanying LICENSE.HTML file.  If your
  9. # distribution of this software does not contain a LICENSE.HTML file
  10. # then you have no rights to use this software in any manner and
  11. # should contact DSTC at the address below to determine an appropriate
  12. # licensing arrangement.
  13. #      DSTC Pty Ltd
  14. #      Level 7, GP South
  15. #      Staff House Road
  16. #      University of Queensland
  17. #      St Lucia, 4072
  18. #      Australia
  19. #      Tel: +61 7 3365 4310
  20. #      Fax: +61 7 3365 4311
  21. #      Email: enquiries@dstc.edu.au
  22. # This software is being provided "AS IS" without warranty of any
  23. # kind.  In no event shall DSTC Pty Ltd be liable for damage of any
  24. # kind arising out of or in connection with the use or performance of
  25. # this software.
  26. #
  27. # Project:      Fnorb
  28. # File:         $Source: /units/arch/src/Fnorb-1.0/orb/RCS/IOP.py,v $
  29. # Version:      @(#)$RCSfile: IOP.py,v $ $Revision: 1.18 $
  30. #
  31. #############################################################################
  32. """ CORBA Interoperability (IOP) module. """
  33.  
  34.  
  35. _FNORB_ID = "IDL:omg.org/IOP:1.0"
  36.  
  37.  
  38. # Standard/built-in modules.
  39. import new, string
  40.  
  41. # Fnorb modules.
  42. import CORBA, IIOP, OctetStream, TypeManager
  43.  
  44. # Fnorb extension modules.
  45. import cdr
  46.  
  47.  
  48. # Alias: IDL:omg.org/IOP/ProfileId:1.0
  49. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/ProfileId:1.0", "0000000000000005", None)
  50.  
  51. # Constant: IDL:omg.org/IOP/TAG_INTERNET_IOP:1.0
  52. TAG_INTERNET_IOP = 0L
  53.  
  54. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/TAG_INTERNET_IOP:1.0", "0000000000000005", TAG_INTERNET_IOP)
  55.  
  56. # Constant: IDL:omg.org/IOP/TAG_MULTIPLE_COMPONENTS:1.0
  57. TAG_MULTIPLE_COMPONENTS = 1L
  58.  
  59. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/TAG_MULTIPLE_COMPONENTS:1.0", "0000000000000005", TAG_MULTIPLE_COMPONENTS)
  60.  
  61.  
  62. class TaggedProfile:
  63.     """ Struct: IDL:omg.org/IOP/TaggedProfile:1.0 """
  64.  
  65.     _FNORB_ID = "IDL:omg.org/IOP/TaggedProfile:1.0"
  66.  
  67.     def __init__(self, _tag, _profile_data):
  68.         """ Constructor. """
  69.  
  70.         self.tag = _tag
  71.         self.profile_data = _profile_data
  72.         return
  73.  
  74.     def __getinitargs__(self):
  75.         """ Return the constructor arguments for unpickling. """
  76.  
  77.         return (self.tag, self.profile_data)
  78.  
  79.     def _fnorb_marshal(self, cursor):
  80.     """ Marshal the structure onto an octet stream. """
  81.  
  82.     cursor.marshal('L', self.tag)
  83.  
  84.     # The profile data is an encapsulation.
  85.     encapsulation = OctetStream.Encapsulation()
  86.     encapsulation_cursor = encapsulation.cursor()
  87.  
  88.     if self.tag == TAG_INTERNET_IOP:
  89.         tc = CORBA.typecode('IDL:omg.org/IIOP/ProfileBody:1.0')
  90.         tc._fnorb_marshal_value(encapsulation_cursor, self.profile_data)
  91.         
  92.     elif self.tag == TAG_MULTIPLE_COMPONENTS:
  93.          tc = CORBA.typecode('IDL:omg.org/IOP/TaggedComponent:1.0')
  94.         encapsulation_cursor.marshal('L', len(self.profile_data))
  95.         for component in self.profile_data:
  96.         tc._fnorb_marshal_value(encapsulation_cursor, component)
  97.  
  98.     else:
  99.         # Unknown profile
  100.         encapsulation = self.profile_data
  101.  
  102.     cursor.marshal('O', encapsulation.data())
  103.     return
  104.  
  105.     def _fnorb_unmarshal(self, cursor):
  106.     """ Unmarshal the structure from an octet stream. """
  107.  
  108.     self.tag = cursor.unmarshal('L')
  109.  
  110.     # The profile data is an encapsulation.
  111.     encapsulation = OctetStream.Encapsulation(cursor.unmarshal('O'))
  112.     encapsulation_cursor = encapsulation.cursor()
  113.  
  114.     if self.tag == TAG_INTERNET_IOP:
  115.         tc = CORBA.typecode('IDL:omg.org/IIOP/ProfileBody:1.0')
  116.         self.profile_data = tc._fnorb_unmarshal_value(encapsulation_cursor)
  117.         
  118.     elif self.tag == TAG_MULTIPLE_COMPONENTS:
  119.         tc = CORBA.typecode('IDL:omg.org/IOP/TaggedComponent:1.0')
  120.         self.profile_data = [] # [TaggedComponent]
  121.         for i in range(encapsulation_cursor.unmarshal('L')):
  122.         component = tc._fnorb_unmarshal_value(encapsulation_cursor)
  123.         self.profile_data.append(component)
  124.  
  125.     else:
  126.         # Unknown profile, simply store it
  127.         self.profile_data = encapsulation
  128.  
  129.     return
  130.  
  131. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/TaggedProfile:1.0", "000000000000000F000000B8000000000000002249444C3A6F6D672E6F72672F494F502F54616767656450726F66696C653A312E300000000000000E54616767656450726F66696C65000000000000020000000474616700000000150000003C000000000000001E49444C3A6F6D672E6F72672F494F502F50726F66696C6549643A312E300000000000000A50726F66696C654964000000000000050000000D70726F66696C655F6461746100000000000000130000000C000000000000000A00000000", TaggedProfile)
  132.  
  133. class IOR:
  134.     """ Struct: IDL:omg.org/IOP/IOR:1.0 """
  135.  
  136.     _FNORB_ID = "IDL:omg.org/IOP/IOR:1.0"
  137.  
  138.     # Custom default parameters used to create a 'nil' object reference.
  139.     def __init__(self, _type_id='', _profiles=[]):
  140.         """ Constructor. """
  141.  
  142.         self.type_id = _type_id
  143.         self.profiles = _profiles
  144.  
  145.         return
  146.  
  147.     def __getinitargs__(self):
  148.         """ Return the constructor arguments for unpickling. """
  149.  
  150.         return (self.type_id, self.profiles)
  151.  
  152.     def _fnorb_from_string(self, stringified_ior):
  153.     """ Initialise the IOR instance from the stringified IOR. """
  154.  
  155.     # Get rid of any dubious (and technically illegal) characters at the
  156.     # start of the IOR (apparently some Java ORBs do this 8^()
  157.     stringified_ior = stringified_ior[string.find(stringified_ior,"IOR:"):]
  158.  
  159.     # Get rid of any whitespace around the IOR (we're a pretty tolerant
  160.     # bunch round here ;^).
  161.     stringified_ior = string.strip(stringified_ior)
  162.  
  163.     # The first four characters MUST be 'IOR:'!
  164.     if stringified_ior[:4] != 'IOR:':
  165.         raise CORBA.INV_OBJREF() # System exception.
  166.  
  167.     # Convert the rest of the stringified IOR from ASCII into an octet
  168.     # stream (ie. a sequence of octets). Each pair of ASCII characters
  169.     # makes a single octet.
  170.     octets = cdr.ASCII_to_octet(stringified_ior[4:])
  171.  
  172.     # The IOR is contained in a CORBA 'encapsulation'.
  173.     octet_stream = OctetStream.Encapsulation(octets)
  174.     cursor = octet_stream.cursor()
  175.  
  176.     # Unmarshal the IOR from the encapsulation.
  177.     self._fnorb_unmarshal(cursor)
  178.     
  179.     return
  180.  
  181.     def _fnorb_to_string(self):
  182.     """ Convert the IOR instance into a stringified object reference. """
  183.  
  184.     # The IOR is marshalled into a CORBA 'encapsulation'.
  185.     encapsulation = OctetStream.Encapsulation()
  186.     cursor = encapsulation.cursor()
  187.  
  188.     # Marshal the IOR into the encapsulation.
  189.     self._fnorb_marshal(cursor)
  190.  
  191.     # Convert the octet stream into an ASCII string.  Each octet is
  192.     # represented by a pair of ASCII characters.
  193.     stringified_ior = cdr.octet_to_ASCII(encapsulation.data())
  194.  
  195.     return 'IOR:' + stringified_ior
  196.  
  197.     def _fnorb_iiop_profile(self):
  198.     """ Return the IOR's IIOP profile. """
  199.  
  200.     # Fnorb can only deal with IOR's that come from ORB's that support
  201.     # IIOP!  If the IOR does NOT contain an IIOP profile, then raise an
  202.     # appropriate system exception.
  203.     for p in self.profiles:
  204.         if p.tag == TAG_INTERNET_IOP:
  205.         break
  206.     else:
  207.         raise CORBA.INV_OBJREF() # System exception.
  208.  
  209.     return p.profile_data
  210.  
  211.     def _fnorb_marshal(self, cursor):
  212.         """ Marshal the structure onto an octet stream. """
  213.  
  214.         cursor.marshal('s', self.type_id)
  215.         cursor.marshal('L', len(self.profiles))
  216.         for i0 in range(len(self.profiles)):
  217.             self.profiles[i0]._fnorb_marshal(cursor)
  218.  
  219.         return
  220.  
  221.     def _fnorb_unmarshal(self, cursor):
  222.         """ Unmarshal the structure from an octet stream. """
  223.  
  224.         self.type_id = cursor.unmarshal('s')
  225.         self.profiles = []
  226.         for i0 in range(cursor.unmarshal('L')):
  227.             self.profiles_i0 = new.instance(TaggedProfile, {})
  228.         self.profiles_i0._fnorb_unmarshal(cursor)
  229.         self.profiles.append(self.profiles_i0)
  230.  
  231.     return
  232.  
  233. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/IOR:1.0", "000000000000000F00000120000000000000001849444C3A6F6D672E6F72672F494F502F494F523A312E300000000004494F52000000000200000008747970655F69640000000012000000000000000970726F66696C65730000000000000013000000C8000000000000000F000000B8000000000000002249444C3A6F6D672E6F72672F494F502F54616767656450726F66696C653A312E300000000000000E54616767656450726F66696C65000000000000020000000474616700000000150000003C000000000000001E49444C3A6F6D672E6F72672F494F502F50726F66696C6549643A312E300000000000000A50726F66696C654964000000000000050000000D70726F66696C655F6461746100000000000000130000000C000000000000000A0000000000000000", IOR)
  234.  
  235. # Alias: IDL:omg.org/IOP/ComponentId:1.0
  236. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/ComponentId:1.0", "0000000000000005", None)
  237.  
  238.  
  239. class TaggedComponent:
  240.     """ Struct: IDL:omg.org/IOP/TaggedComponent:1.0 """
  241.  
  242.     _FNORB_ID = "IDL:omg.org/IOP/TaggedComponent:1.0"
  243.  
  244.     def __init__(self, _tag, _component_data):
  245.         """ Constructor. """
  246.  
  247.         self.tag = _tag
  248.         self.component_data = _component_data
  249.         return
  250.  
  251.     def __getinitargs__(self):
  252.         """ Return the constructor arguments for unpickling. """
  253.  
  254.         return (self.tag, self.component_data)
  255.  
  256.  
  257. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/TaggedComponent:1.0", "000000000000000F000000B8000000000000002449444C3A6F6D672E6F72672F494F502F546167676564436F6D706F6E656E743A312E300000000010546167676564436F6D706F6E656E7400000000020000000474616700000000150000003C000000000000002049444C3A6F6D672E6F72672F494F502F436F6D706F6E656E7449643A312E30000000000C436F6D706F6E656E74496400000000050000000F636F6D706F6E656E745F646174610000000000130000000C000000000000000A00000000", TaggedComponent)
  258.  
  259. # Alias: IDL:omg.org/IOP/MultipleComponentProfile:1.0
  260. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/MultipleComponentProfile:1.0", "0000000000000013000000C8000000000000000F000000B8000000000000002449444C3A6F6D672E6F72672F494F502F546167676564436F6D706F6E656E743A312E300000000010546167676564436F6D706F6E656E7400000000020000000474616700000000150000003C000000000000002049444C3A6F6D672E6F72672F494F502F436F6D706F6E656E7449643A312E30000000000C436F6D706F6E656E74496400000000050000000F636F6D706F6E656E745F646174610000000000130000000C000000000000000A0000000000000000", None)
  261.  
  262. # Alias: IDL:omg.org/IOP/ServiceId:1.0
  263. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/ServiceId:1.0", "0000000000000005", None)
  264.  
  265.  
  266. class ServiceContext:
  267.     """ Struct: IDL:omg.org/IOP/ServiceContext:1.0 """
  268.  
  269.     _FNORB_ID = "IDL:omg.org/IOP/ServiceContext:1.0"
  270.  
  271.     def __init__(self, _context_id, _context_data):
  272.         """ Constructor. """
  273.  
  274.         self.context_id = _context_id
  275.         self.context_data = _context_data
  276.         return
  277.  
  278.     def __getinitargs__(self):
  279.         """ Return the constructor arguments for unpickling. """
  280.  
  281.         return (self.context_id, self.context_data)
  282.  
  283. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/ServiceContext:1.0", "000000000000000F000000C0000000000000002349444C3A6F6D672E6F72672F494F502F53657276696365436F6E746578743A312E3000000000000F53657276696365436F6E746578740000000000020000000B636F6E746578745F69640000000000150000003C000000000000001E49444C3A6F6D672E6F72672F494F502F5365727669636549643A312E300000000000000A536572766963654964000000000000050000000D636F6E746578745F6461746100000000000000130000000C000000000000000A00000000", ServiceContext)
  284.  
  285. # Alias: IDL:omg.org/IOP/ServiceContextList:1.0
  286. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/ServiceContextList:1.0", "0000000000000013000000D0000000000000000F000000C0000000000000002349444C3A6F6D672E6F72672F494F502F53657276696365436F6E746578743A312E3000000000000F53657276696365436F6E746578740000000000020000000B636F6E746578745F69640000000000150000003C000000000000001E49444C3A6F6D672E6F72672F494F502F5365727669636549643A312E300000000000000A536572766963654964000000000000050000000D636F6E746578745F6461746100000000000000130000000C000000000000000A0000000000000000", None)
  287.  
  288. # Constant: IDL:omg.org/IOP/TransactionService:1.0
  289. TransactionService = 0L
  290.  
  291. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/TransactionService:1.0", "0000000000000005", TransactionService)
  292.  
  293. # Constant: IDL:omg.org/IOP/CodeSets:1.0
  294. CodeSets = 1L
  295.  
  296. TypeManager.TypeManager_init().add_type("IDL:omg.org/IOP/CodeSets:1.0", "0000000000000005", CodeSets)
  297.  
  298. #############################################################################
  299.