Re: [IronPython] Using ruby module from python.

2009-12-01 Thread Pavel Suhotyuk
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 "", line 1, in 
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)
[#]>


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 "", line 1, in 
SystemError: SOAP::Mapping::MappingError
>>> client.GetBalance(provider=3)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: RubyMethod is not callable
>>> getattr(client, 'GetBalance')(3)
Traceback (most recent call last):
  File "", line 1, in 
SystemError: SOAP::Mapping::MappingError
>>> getattr(client, 'GetBalance')(provider=3)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: RubyMethod is not callable
>>> getattr(client, 'GetBalance')({'providerId':3})
Traceback (most recent call last):
  File "", line 1, in 
SystemError: SOAP::Mapping::MappingError
>>> getattr(client, 'GetBalance')({'providerId':3})
Traceback (most recent call last):
  File "", line 1, in 
SystemError: SOAP::Mapping::MappingError
>>> getattr(client, 'GetBalance')({':providerId':3})
Traceback (most recent call last):
  File "", line 1, in 
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 "", line 1, in 
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-boun...@lists.ironpython.com 
[mailto:users-boun...@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 "", line 1, in 
ValueError: couldn't find module soap/wsdlDriver to use  >>> 
clr.Use('soap.wsdlDriver') Traceback (most recent call last):
   File "", line 1, in 
ValueError: couldn't find module soap.wsdlDriver to use  >>> 
clr.Use('soap/wsdlDriver.rb') Traceback (most recent call last):
   File "", line 1, in 
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')

 >>> m =
clr.Use(r'''C:\usr\env\IronRuby\lib\ruby\1.8\soap\wsdlDriver.rb''', 'rb')  >>> m   >>> dir(m) ['__builtins__']


Thanks.
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Using ruby module from python.

2009-12-01 Thread Pavel Suhotyuk

Thank you for replay.

I will try to use this way.

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 "", line 1, in 
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-boun...@lists.ironpython.com 
[mailto:users-boun...@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 "", line 1, in 
ValueError: couldn't find module soap/wsdlDriver to use  >>> 
clr.Use('soap.wsdlDriver') Traceback (most recent call last):
   File "", line 1, in 
ValueError: couldn't find module soap.wsdlDriver to use  >>> 
clr.Use('soap/wsdlDriver.rb') Traceback (most recent call last):
   File "", line 1, in 
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')

 >>> m =
clr.Use(r'''C:\usr\env\IronRuby\lib\ruby\1.8\soap\wsdlDriver.rb''', 'rb')  >>> m   >>> dir(m) ['__builtins__']


Thanks.
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Web Services library

2009-11-30 Thread Pavel Suhotyuk

Thank you for the answer.

Yes, I know about this way, but we have a part of processing system. 
This component compile and run many scripts and we want to have dynamic 
way to construct/destruct SOAP classes.


David Escobar wrote:
One way to do it is to use the /wsdl.exe/ tool to generate a proxy 
class. The tool will generate the proxy class in C# (it can't do 
IronPython code), but you can then take the resulting .cs file and 
compile it to a .dll (using the C# compiler - /csc.exe/). Place the .dll 
into the same folder as your IronPython program and add a reference to 
it from your IronPython code using the *clr.AddReference* method. 
Something like this:


*import clr
clr.AddReference("MyServiceProxyClass.dll")
*
There may be other methods as well, which I'm not aware of, but this is 
the way I would do it. The easiest way to get to /wsdl.exe/ and 
/csc.exe/ is to open up the Visual Studio command prompt, which puts all 
of these tools in your path - that way, you don't have to go hunting for 
the tools yourself.




On Fri, Nov 27, 2009 at 3:09 AM, Pavel Suhotyuk 
mailto:pavel.suhot...@gmail.com>> wrote:


Hello.

What a client library you recomend for using WebServices with
IronPython ( something like SOAP.PY ) ?
___
Users mailing list
Users@lists.ironpython.com <mailto:Users@lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com





___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Using ruby module from python.

2009-11-30 Thread Pavel Suhotyuk

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 "", line 1, in 
ValueError: couldn't find module soap/wsdlDriver to use
>>> clr.Use('soap.wsdlDriver')
Traceback (most recent call last):
  File "", line 1, in 
ValueError: couldn't find module soap.wsdlDriver to use
>>> clr.Use('soap/wsdlDriver.rb')
Traceback (most recent call last):
  File "", line 1, in 
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')


>>> m = 
clr.Use(r'''C:\usr\env\IronRuby\lib\ruby\1.8\soap\wsdlDriver.rb''', 'rb')

>>> m

>>> dir(m)
['__builtins__']


Thanks.
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Web Services library

2009-11-27 Thread Pavel Suhotyuk

Hello.

What a client library you recomend for using WebServices with IronPython 
( something like SOAP.PY ) ?

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] IPY and multitasking

2009-11-13 Thread Pavel Suhotyuk
I'm prepare simple test for problem demonstration. 
http://files.roinet.net/DLRTest.zip


Module utils imported 6-7 times on 2x Dual-Core Opteron 2216 machine, 
but method IronPythonHelper.CreateScript() called one time. On Core 2 
Quad this problem has detected 4 times. On Core 2 Duo problem has not 
detected.


In file out.txt console output with exceptions and logging information.

Dino Viehland wrote:
You're only using 1 ScriptEngine class?  That should be fine based upon 
the code below but I just want to make sure I understand the scenario.


Is citypay.utils being ran multiple times when you run the code in the
multi-threaded scenario?  If you have a console app you could put a 
print statement in utils.py to see if it's getting executed multiple

times.  If it's not a console app you could put some other logging
into it.  Executing Struct's definition multiple times might cause 
the exceptions you're seeing but I don't know why it would get executed

multiple times.

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] IPY and multitasking

2009-11-12 Thread Pavel Suhotyuk

I have this collection of methods:
--
public static class IronPythonHelper
{
public static ScriptEngine 
CreateScriptEngine(IEnumerable paths)

{
var langSetup = ScriptRuntimeSetup.ReadConfiguration();
var engine = new 
ScriptRuntime(langSetup).GetEngine("IronPython");

var path = engine.GetSearchPaths();
path.Extend(paths);
engine.SetSearchPaths(path);
engine.Execute("import citypay", engine.Runtime.Globals);
engine.Execute("import cPickle", engine.Runtime.Globals);
engine.Execute("from citypay.utils import Struct", 
engine.Runtime.Globals);

return engine;
}

public static object PackParams(ScriptEngine engine, 
IDictionary param)

{
var scope = engine.CreateScope();
engine.Execute("from citypay.utils import Struct", scope);
engine.Execute("def pack( params ) : return 
Struct(**dict(params))", scope);
var pack = scope.GetVariableobject>, object>>("pack");

return pack(param);
}

public static byte[] CPickleSerialize(ScriptEngine engine, 
object obj)

{
var scope = engine.CreateScope();
engine.Execute("import cPickle", scope);
engine.Execute("def serialize( obj ) : return 
cPickle.dumps( obj )", scope);
var serialize = scope.GetVariablestring>>("serialize");

return Encoding.Unicode.GetBytes(serialize(obj));
}
}
--
I have base class used for create needed Engine and Scope as:
--
public absract class SripterBase {
private static readonly ScriptEngine engine = 
IronPythonHelper.CreateScriptEngine(Settings.Default.PythonLibPaths.Cast());


...
}
--
My problem in next: Scripter based classes can be created in many 
threads in one time.
Scripter class used for get pickle'd data by CPickleSerialize(), from 
something like:

--
class Struct ( object ) :

def __init__ ( self, **kwds ) :
for name, val in kwds.iteritems() :
setattr( self, name, val )

def _update ( self, **kwds ) :
for name, val in kwds.iteritems() :
setattr( self, name, val )

def _enum ( self ) :
return [( a, getattr( self, a ) ) for a in dir( self ) if 
a.find( '__' ) == -1 and not a.startswith( '_' )]


def __repr__ ( self ) :
return '' % ' '.join( [ '%s=%s' % ( str( n 
), repr( v ) ) for n, v in self._enum() ] )


def __eq__ ( self, other ) :
if not isinstance( other, type( self ) ) :
return NotImplemented
return self._enum() == other._enum()
--

Multithread code in some (not stable) cases throws 'strange' exceptions.
This problem exists only in multithreaded environment and not exist in 
single thread.


How I can fix or avoid this problem ?


usmpsrv1 :: FATAL :: CityPay.Core.Utils.RecursiveException: Recursive 
ended. ---> IronPython.Runtime.Exceptions.ImportException: Cannot import 
name Struct
   in IronPython.Runtime.Importer.ImportFrom(CodeContext context, 
Object from, String name)
   in Microsoft.Scripting.Utils.InvokeHelper`4.Invoke(Object arg0, 
Object arg1, Object arg2)
   in 
Microsoft.Scripting.Interpreter.CallInstruction.Run(InterpretedFrame frame)
   in 
Microsoft.Scripting.Interpreter.Interpreter.RunInstructions(InterpretedFrame 
frame)
   in Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame 
frame)
   in Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 
arg0, T1 arg1)

   in IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   in 
IronPython.Compiler.RuntimeScriptCode.InvokeTarget(LambdaExpression 
code, Scope scope)

   in Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   in CityPay.Core.Utils.IronPythonHelper.PackParams(ScriptEngine 
engine, IDictionary`2 param)
   in 
CityPay.Providers.Helpers.Beeline.PaymentInfo.Serialize(ScriptEngine engine)
   in CityPay.Providers.Helpers.PaymentInfoBase.ToString(ScriptEngine 
engine)
   in 
CityPay.PaymentsBroker.Bridge.WinService.Workers.ProcessWorker.Request(Payment 
payment)

   in CityPay.Core.Utils.Util.Recursive[TResult](Func`1 func, Int32 count)
   in CityPay.Core.Utils.Util.Recursive[TResult](Func`1 func, Int32 count)
   in CityPay.Core.Utils.Util.Recursive[TResult](Func`1 func, Int32 count)
   in CityPay.Core.Utils.Util.Recursive[TResult](Func`1 func, I

Re: [IronPython] InvokeMember with three or more parameters.

2009-08-19 Thread Pavel Suhotyuk

Hello.

Thank you for answer.

How can I create script object without code generation same like:

scriptEngine.Execute(string.Format("{0}()","Broker"),scriptScope);

?

Dino Viehland wrote:

We haven't implemented support for more than 3 parameters :)

In 2.6 I just fixed > 3 params for the Invoke case (not InvokeMember)
and I can fix > 3 for InvokeMember/CreateInstance as well before
2.6 ships.

The preferred way to do this though is to do a GetMember where
T is a delegate type with > 3 paraemters.  Then you can just invoke
the delegate.


-Original Message-
From: users-boun...@lists.ironpython.com [mailto:users-
boun...@lists.ironpython.com] On Behalf Of Pavel Suhotyuk
Sent: Monday, August 17, 2009 1:19 AM
To: Discussion of IronPython
Subject: [IronPython] InvokeMember with three or more parameters.

Hello.

I have Python code:

class Broker ( object ) :

 def validation( self, info, provider_manager ):
 pass

 def check( self, payment, payment_manager, provider_manager ):
 pass

and try to call methods by this c# code:

operations = scriptEngine.CreateOperations();
var scriptSource =
scriptEngine.CreateScriptSourceFromString(script,SourceCodeKind.Stateme
nts);
scriptCode = scriptSource.Compile();
scriptCode.Execute();
scriptScope = scriptCode.DefaultScope;
broker =
scriptEngine.Execute(string.Format("{0}()","Broker"),scriptScope);

bool validationResult = operations.InvokeMember(broker, "validation",
paymentInfo, providerManager);

operations.InvokeMember(broker, "check", payment, paymentManager,
providerManager);


Invoke validation method is success, but invoke check method throws
NotImplementedException with stack trace:

System.NotImplementedException: Method or operation not implemented.
в Microsoft.Scripting.Runtime.DynamicOperations.InvokeMember(Object
obj, String memberName, Boolean ignoreCase, Object[] parameters)
в Microsoft.Scripting.Hosting.ObjectOperations.InvokeMember(Object
obj, String memberName, Object[] parameters)

Looks like 2 paramters called correct, but more than 2 throws exception
in all cases.

Why it happens?

--
Best regards,
  Suhotjuk Pavel Sergeevich
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] InvokeMember with three or more parameters.

2009-08-17 Thread Pavel Suhotyuk

Hello.

I have Python code:

class Broker ( object ) :

def validation( self, info, provider_manager ):
pass

def check( self, payment, payment_manager, provider_manager ):
pass

and try to call methods by this c# code:

operations = scriptEngine.CreateOperations();
var scriptSource = 
scriptEngine.CreateScriptSourceFromString(script,SourceCodeKind.Statements);

scriptCode = scriptSource.Compile();
scriptCode.Execute();
scriptScope = scriptCode.DefaultScope;
broker = scriptEngine.Execute(string.Format("{0}()","Broker"),scriptScope);

bool validationResult = operations.InvokeMember(broker, "validation", 
paymentInfo, providerManager);


operations.InvokeMember(broker, "check", payment, paymentManager, 
providerManager);



Invoke validation method is success, but invoke check method throws 
NotImplementedException with stack trace:


System.NotImplementedException: Method or operation not implemented.
   в Microsoft.Scripting.Runtime.DynamicOperations.InvokeMember(Object 
obj, String memberName, Boolean ignoreCase, Object[] parameters)
   в Microsoft.Scripting.Hosting.ObjectOperations.InvokeMember(Object 
obj, String memberName, Object[] parameters)


Looks like 2 paramters called correct, but more than 2 throws exception 
in all cases.


Why it happens?

--
Best regards,
 Suhotjuk Pavel Sergeevich
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] turn on -X:Frames option in DLR

2009-07-31 Thread Pavel Suhotyuk

It works. Thank you.
Curt Hagenlocher wrote:

var opts = new Dictionary();
opts["Frames"] = ScriptingRuntimeHelpers.True;
var engine = Python.CreateEngine(opts);


On Fri, Jul 31, 2009 at 1:11 AM, Pavel Suhotyuk 
mailto:pavel.suhot...@gmail.com>> wrote:


Hello.

I need to use "inspect" module, that require sys._getframe()
function. But I'm use embedded IPY through calling:

var engine = Python.CreateEngine();
ScriptSource py = engine.CreateScriptSourceFromFile(fileName);
CompiledCode code = py.Compile();
code.Execute();

At this point for ScriptScope in 'code' object not available
sys._getframe() function. In console this resolved by -X:Frames option.

How I can enable this option for embedded Engine?

--
Best regards,
 Suhotjuk Pavel Sergeevich
___
Users mailing list
Users@lists.ironpython.com <mailto:Users@lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com





___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] turn on -X:Frames option in DLR

2009-07-31 Thread Pavel Suhotyuk

Hello.

I need to use "inspect" module, that require sys._getframe() function. 
But I'm use embedded IPY through calling:


var engine = Python.CreateEngine();
ScriptSource py = engine.CreateScriptSourceFromFile(fileName);
CompiledCode code = py.Compile();
code.Execute();

At this point for ScriptScope in 'code' object not available 
sys._getframe() function. In console this resolved by -X:Frames option.


How I can enable this option for embedded Engine?

--
Best regards,
 Suhotjuk Pavel Sergeevich
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com