[IronPython] Using ruby module from python.
Pavel Suhotyuk
pavel.suhotjuk at gmail.com
Tue Dec 1 14:26:46 CET 2009
I try your example. It's really work, but have some problem with ruby
objects:
1) Can't call RubyObject methods.
>>> import clr
>>> wsdl = clr.Use('wsdl.rb', 'rb')
>>> factory = wsdl.get_factory()
>>> client =
factory('http://localhost/PaymentsBroker/Manager/ProviderService.asmx?WSDL').create_rpc_drive()
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'RubyObject' object has no attribute 'create_rpc_drive'
>>> client =
getattr(factory('http://localhost/PaymentsBroker/Manager/ProviderService.asmx?WSDL'),
'create_rpc_driver')()
>>>
2) Calling methods without parameters possible.
>>> client.GetProviders(None)
<IronRuby.Builtins.RubyObject object at 0x000000000000002F
[#<SOAP::Mapping::Object:0x0006dd2>]>
But I don't understand how call methods with parameters. In ruby I can
call like this:
>>> print client.GetBalance(:providerId => 3).getBalanceResult().balance
60663.89=> nil
In python it's not work:
>>> client.GetBalance(3)
Traceback (most recent call last):
File "<string>", line 1, in <module>
SystemError: SOAP::Mapping::MappingError
>>> client.GetBalance(provider=3)
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: RubyMethod is not callable
>>> getattr(client, 'GetBalance')(3)
Traceback (most recent call last):
File "<string>", line 1, in <module>
SystemError: SOAP::Mapping::MappingError
>>> getattr(client, 'GetBalance')(provider=3)
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: RubyMethod is not callable
>>> getattr(client, 'GetBalance')({'providerId':3})
Traceback (most recent call last):
File "<string>", line 1, in <module>
SystemError: SOAP::Mapping::MappingError
>>> getattr(client, 'GetBalance')({'providerId':3})
Traceback (most recent call last):
File "<string>", line 1, in <module>
SystemError: SOAP::Mapping::MappingError
>>> getattr(client, 'GetBalance')({':providerId':3})
Traceback (most recent call last):
File "<string>", line 1, in <module>
SystemError: SOAP::Mapping::MappingError
Tomas Matousek wrote:
> Our Python-Ruby interop is not quite done yet so you need to use some workarounds.
>
> The easiest way how to get WSDL factory instance would be to write a simple Ruby script that loads it:
>
> == wsdl.rb ==
>
> require 'soap/wsdlDriver'
>
> def get_factory
> SOAP::WSDLDriverFactory
> end
>
> ===
>
> And then you can do:
>>>> import clr
>>>> wsdl = clr.Use('wsdl.rb', 'rb')
>>>> factory = wsdl.get_factory()
>>>> print factory("x.wsdl")
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> SystemError: Cannot connect to x.wsdl (Not HTTP.)
>
>
> get_factory method is exposed on the "wsdl" module so that Python can call it. IronRuby doesn't yet implement dynamic protocols for constant access so you need the get_factory helper for accessing Ruby constants.
> Also we have some work to do to make clr.Use work better with libraries of other DLR languages.
> Let us know if you hit some other issues.
>
> Tomas
>
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pavel Suhotyuk
> Sent: Monday, November 30, 2009 2:38 AM
> To: Discussion of IronPython
> Subject: [IronPython] Using ruby module from python.
>
> Hello.
>
> I want try to use ruby library (soap) in python code.
> I found method Use(str) in clr module for load the specified module searching all languages in the loaded ScriptRuntime, but don't understand how to used it.
>
> I try to call this method in any variants, but nothing happends.
>
> >>> import clr
> >>> clr.Use('soap/wsdlDriver')
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> ValueError: couldn't find module soap/wsdlDriver to use >>> clr.Use('soap.wsdlDriver') Traceback (most recent call last):
> File "<string>", line 1, in <module>
> ValueError: couldn't find module soap.wsdlDriver to use >>> clr.Use('soap/wsdlDriver.rb') Traceback (most recent call last):
> File "<string>", line 1, in <module>
> ValueError: couldn't find module soap/wsdlDriver.rb to use >>> clr.Use(r'''C:\usr\env\IronRuby\lib\ruby\1.8\soap\wsdlDriver.rb''',
> 'rb')
> <module '?' (built-in)>
> >>> m =
> clr.Use(r'''C:\usr\env\IronRuby\lib\ruby\1.8\soap\wsdlDriver.rb''', 'rb') >>> m <module '?' (built-in)> >>> dir(m) ['__builtins__']
>
>
> Thanks.
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list