[OpenSIPS-Users] python module

2023-03-30 Thread Alberto
Hi,

I'm curious, since python_exec only accepts one extra parameter, how do you
guys pass multiple variables to a python function?

I personally do this:
$json(args) := "{}";
$json(args/param0) = "sdifuhsidfg";
$json(args/param1) = "asfagfgf";
$json(args/param2) = "asfergerghdf";
python_exec("python_my_fn", $json(args));

and then I restore the json object in the python function and use my
variables..

Thanks
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-25 Thread Gordon Yeong
h Python’s usage of the same
>>>> character for the same purpose in string literals; for example, to match a
>>>> literal backslash, one might have to write '' as the pattern
>>>> string, because the regular expression must be \\, and each backslash
>>>> must be expressed as \\ inside a regular Python string literal. Also,
>>>> please note that any invalid escape sequences in Python’s usage of the
>>>> backslash in string literals now generate a DeprecationWarning
>>>> <https://docs.python.org/3/library/exceptions.html#DeprecationWarning> and
>>>> in the future this will become a SyntaxError
>>>> <https://docs.python.org/3/library/exceptions.html#SyntaxError>. This
>>>> behaviour will happen even if it is a valid escape sequence for a regular
>>>> expression.
>>>>
>>>> The solution is to use Python’s raw string notation for regular
>>>> expression patterns; backslashes are not handled in any special way in a
>>>> string literal prefixed with 'r'. So r"\n" is a two-character string
>>>> containing '\' and 'n', while "\n"is a one-character string containing
>>>> a newline.
>>>>
>>>>
>>>> Tomi
>>>>
>>>> On 16. May 2020, at 1.47, Gordon Yeong  wrote:
>>>>
>>>> 
>>>> It's passed the init. If i did a print (LM_ERR) In the first line of
>>>> init(), it doesn't show that print.
>>>>
>>>> If i  did a print (LM_ERR)a static string   in the get_rn()  before the
>>>> line that calls compile(), i noticed that it does print out.  And if i
>>>> tried to print a static string right after the compile() call,  it doesn't
>>>> print and it calls TypeError.
>>>>
>>>> That's why i suspect something is wrong bit can't tell exactly what
>>>>
>>>>
>>>> On Fri, 15 May 2020, 11:21 pm Ben Newlin, 
>>>> wrote:
>>>>
>>>>> Gordon,
>>>>>
>>>>>
>>>>>
>>>>> Are you sure the TypeError is not occurring in mod_init? It looks like
>>>>> you are trying to do a print on a Class definition.
>>>>>
>>>>>
>>>>>
>>>>> Ben Newlin
>>>>>
>>>>>
>>>>>
>>>>> *From: *Users  on behalf of Gordon
>>>>> Yeong 
>>>>> *Reply-To: *OpenSIPS users mailling list 
>>>>> *Date: *Friday, May 15, 2020 at 1:54 AM
>>>>> *To: *OpenSIPS users mailling list 
>>>>> *Subject: *[OpenSIPS-Users] python module - python_exec() behaviour
>>>>> in opensips
>>>>>
>>>>>
>>>>>
>>>>> hi guys,
>>>>>
>>>>>  Using opensips 3.0 and python3 here.
>>>>>
>>>>>
>>>>>
>>>>>  I have a script which parses a number in a string
>>>>> (r'.*rn=\+6114(\d{2})').
>>>>>
>>>>>
>>>>>
>>>>> Script is as follows:
>>>>>
>>>>> -- start ---
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> #!/usr/bin/python3
>>>>> import re;
>>>>> import pprint;
>>>>>
>>>>>
>>>>> class test:
>>>>>
>>>>> def get_rn():
>>>>> rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
>>>>> doit = rnRegExp.match( str("sip:+61386947785;npdi;rn=+
>>>>> 611...@tipt.ns.zippi.vocus.com;user=phone"));
>>>>>
>>>>> if doit:
>>>>> pp = pprint.PrettyPrinter(indent=4);
>>>>> return doit.group(1);
>>>>> else:
>>>>> return None;
>>>>>
>>>>> result = test.get_rn();
>>>>>
>>>>> if result is None:
>>>>> print("Got no match\n");
>>>>> else:
>>>>> print("Result is " + result);
>>>>>
>>>>>
>>>>>
>>>>> --- end --
>>>>>
>>>>>
>>>>>
>>>>> In my opensips setup, I have the function above looking like this:
>>>>>
>>>&

Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-17 Thread Gordon Yeong
hello Tomi,

yeah , when i test, I
1) put #!/usr/bin/python3 in the script, or
2) run "python3" for the interactive session

 yes, just read the
https://github.com/OpenSIPS/opensips/blob/master/modules/python/Makefile and
yeah, it's an ugly hack to have the system run python3 when python is
referred to.
 I had considered removing python 2.7 to which, after searching, it was not
a good idea for it would break the system.

As a quick work around, I went to the modules/python/Makefile and made the
following change:
-PYTHON=python3
+PYTHON=/usr/bin/python3

Compiled just fine.

Ran opensips with my config and I got more errors with my regexp which
tests out fine on python3's interactive terminal.
The regexp is in " rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');"

Got more error messages:

May 18 11:07:41 [58953] ERROR:python:python_handle_exception:
python_exec("get_rn"): Unhandled exception in the Python code:
May 18 11:07:41 [58953] ERROR:python:python_handle_exception:   TypeError:
an integer is required (got type str)
May 18 11:07:41 [58953] ERROR:python:python_handle_exception:
The above exception was the direct cause of the following exception:

May 18 11:07:41 [58953] ERROR:python:python_handle_exception:   Traceback
(most recent call last):
May 18 11:07:41 [58953] ERROR:python:python_handle_exception: File
"/home/gordon/opensips_proxy_source/modules/python/dumbat.py", line 61, in
get_rn
return re.match(r'.*rn=\+6114(\d{2})', str(raw_enum_result) ).group(1);
May 18 11:07:41 [58953] ERROR:python:python_handle_exception:
SystemError:  returned a result with an error set   <--




I found out why.

 I took of the regexp and only issued a 'return "Hello World"' in my
function,get_rn().
 I kept getting the error, "TypeError: an integer is required (got type
str)".

Looked at
https://github.com/OpenSIPS/opensips/blob/master/modules/python/python_exec.c#L40-L41
and
it seems python_exec() will only ever return integers.
Thus, that's why it was barfing when I return non integer types.


I think we really need a function that executes python code and returns
data from the function just like what we have in the perl module,
perl_exec_func() (
https://opensips.org/html/docs/modules/1.5.x/perl.html#id293498).


So, guys, with this discovery, how do we run a python function  and return
its output to opensips config??
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-17 Thread Tomi Hakkarainen
 
>>> Tomi
>>> 
>>> On 16. May 2020, at 1.47, Gordon Yeong  wrote:
>>> 
>>> 
>>> It's passed the init. If i did a print (LM_ERR) In the first line of 
>>> init(), it doesn't show that print. 
>>> 
>>> If i  did a print (LM_ERR)a static string   in the get_rn()  before the 
>>> line that calls compile(), i noticed that it does print out.  And if i 
>>> tried to print a static string right after the compile() call,  it doesn't 
>>> print and it calls TypeError.
>>> 
>>> That's why i suspect something is wrong bit can't tell exactly what
>>> 
>>> 
>>> On Fri, 15 May 2020, 11:21 pm Ben Newlin,  wrote:
>>>> Gordon,
>>>> 
>>>>  
>>>> 
>>>> Are you sure the TypeError is not occurring in mod_init? It looks like you 
>>>> are trying to do a print on a Class definition.
>>>> 
>>>>  
>>>> 
>>>> Ben Newlin
>>>> 
>>>>  
>>>> 
>>>> From: Users  on behalf of Gordon Yeong 
>>>> 
>>>> Reply-To: OpenSIPS users mailling list 
>>>> Date: Friday, May 15, 2020 at 1:54 AM
>>>> To: OpenSIPS users mailling list 
>>>> Subject: [OpenSIPS-Users] python module - python_exec() behaviour in 
>>>> opensips
>>>> 
>>>>  
>>>> 
>>>> hi guys,
>>>> 
>>>>  Using opensips 3.0 and python3 here.
>>>> 
>>>>  
>>>> 
>>>>  I have a script which parses a number in a string (r'.*rn=\+6114(\d{2})').
>>>> 
>>>>  
>>>> 
>>>> Script is as follows:
>>>> 
>>>> -- start ---
>>>> 
>>>>  
>>>> 
>>>>  
>>>> 
>>>> #!/usr/bin/python3
>>>> import re;
>>>> import pprint;
>>>> 
>>>> 
>>>> class test:
>>>> 
>>>> def get_rn():
>>>> rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
>>>> doit = rnRegExp.match( 
>>>> str("sip:+61386947785;npdi;rn=+611...@tipt.ns.zippi.vocus.com;user=phone"));
>>>> 
>>>> if doit:
>>>> pp = pprint.PrettyPrinter(indent=4);
>>>> return doit.group(1);
>>>> else:
>>>> return None;
>>>> 
>>>> result = test.get_rn();
>>>> 
>>>> if result is None:
>>>> print("Got no match\n");
>>>> else:
>>>> print("Result is " + result);
>>>> 
>>>>  
>>>> 
>>>> --- end --
>>>> 
>>>>  
>>>> 
>>>> In my opensips setup, I have the function above looking like this:
>>>> 
>>>>  
>>>> 
>>>>  start
>>>> 
>>>> 
>>>> from OpenSIPS import LM_ERR
>>>> import re;
>>>> import pprint;
>>>> 
>>>> def mod_init():
>>>> print("In mod_init, SIP MSG is : ");
>>>> pp = pprint.PrettyPrinter(indent=4)
>>>> pp.pprint(SIPMsg);
>>>> return SIPMsg();
>>>> 
>>>> def __init__():
>>>> return 1;
>>>> 
>>>> import re;
>>>> import pprint;
>>>> 
>>>> class SIPMsg:
>>>> 
>>>> def child_init(self, rank):
>>>> return 0
>>>> 
>>>> def get_rn(self, msg, raw_enum_result):
>>>> try:
>>>>  get_rn = re.compile(r'.*rn=\+6114(\d{2})');
>>>> 
>>>>  rn = get_rn.match(str(raw_enum_result));
>>>>  return rn.group(1);
>>>> except AttributeError:
>>>>  # Invalid input string
>>>>  LM_ERR(" attribute ERRor" );
>>>>  return '';
>>>> except TypeError:
>>>>  # Invalid input string
>>>>  LM_ERR(" Type Error" );
>>>>  return '';
>>>> else:
>>>>  LM_ERR(" general ERRor" );
>>>>  return '';
>>>> 
>>>>  
>>>> 
>>>> - end --
>>>> 
>>>>  
>>>> 
>>>>  
>>>> 
>>>>  
>>>> 
>>>> In my opensips config, I call the get_rn() function via python_exec() as 
>>>> below.
>>>> 
>>>>  
>>>> 
>>>> $var(rn_code)=python_exec("get_rn", $var(raw_string));
>>>> 
>>>>  
>>>> 
>>>> I'm facing an issue here because when I run the script by itself in a 
>>>> command line, it works.
>>>> 
>>>>  No "Error: Text Type" but when my opensips run, it keeps hitting a 
>>>> TypeError.
>>>> 
>>>>  I have even explicitly fed the " rn = 
>>>> get_rn.match(str(raw_enum_result));" with an explicit string (ie. I dont 
>>>> send use the value passed in from the argument BUT instead, just feed it 
>>>> an explicit string value) and yet the same issue occurs.
>>>> 
>>>>  
>>>> 
>>>> Does processing control belong directly to python3 when we call 
>>>> python_exec() or is there something funny going on here?
>>>> 
>>>>  
>>>> 
>>>> Thank you
>>>> 
>>>>  
>>>> 
>>>>  
>>>> 
>>>> Regards,
>>>> Gordon 
>>>> 
>>>> ___
>>>> Users mailing list
>>>> Users@lists.opensips.org
>>>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>> ___
>>> Users mailing list
>>> Users@lists.opensips.org
>>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>> ___
>>> Users mailing list
>>> Users@lists.opensips.org
>>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>> ___
>> Users mailing list
>> Users@lists.opensips.org
>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>> 
>> ___
>> Users mailing list
>> Users@lists.opensips.org
>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-16 Thread Gordon Yeong
very interesting.
 I looked at the code in handler.py and adjusted my python class.

I ran opensips  (master branch) and found 2 issues:

1) python3 is not being run. How do i specify to opensips to use python 3?

May 17 15:45:46 [21373] Just done the enum query...The ru value is (
sip:service@192.168.136.133:5060)
Calling get_rn...
May 17 15:45:46 [21373] ERROR:python:python_handle_exception:
python_exec("get_rn"): Unhandled exception in the Python code:
May 17 15:45:46 [21373] ERROR:python:python_handle_exception:   Traceback
(most recent call last):
May 17 15:45:46 [21373] ERROR:python:python_handle_exception: File
"/home/gordon/opensips_proxy_source/modules/python/dumbat.py", line 61, in
get_rn
return re.match('.*rn\=\+6114([\d]{2}).*', str(raw_enum_result)
).group(1);
May 17 15:45:46 [21373] ERROR:python:python_handle_exception: File
"/usr/lib64/python2.7/re.py", line 137, in match   < python2.7 not 3
May 17 15:45:46 [21373] ERROR:python:python_handle_exception:   TypeError:
an integer is required
May 17 15:45:46 [21373] AFTER EXTRACTION (get_rn) The value of
the rn code is [-1]
May 17 15:45:46 [21373] incoming reply



2) the type error seems to be coming from re.py . I will trace more later
but we need to make my opensips use python 3.


So, how do I specify python3 to be used in my opensips?


Regards,
Gordon Yeong


On Sat, 16 May 2020 at 21:09, Gordon Yeong  wrote:

> Tomi
>
> I will try it on monday. Let u know. Thank you, stay safw and have a good
> weekend :)
>
> On Sat, 16 May 2020, 8:08 pm Tomi Hakkarainen,  wrote:
>
>> Hi,
>> My second guess :)
>>
>> Check this
>> https://github.com/OpenSIPS/opensips/blob/master/modules/python/handler.py
>>
>> Differs from your version… Can these differences cause the failure?
>>
>> The __init__ located inside class
>>
>> And the mod_init located last in the script (does the order count for
>> anything in python?)
>>
>> Also called handler function always returns 1 not the init
>>
>> Tomi
>>
>> On 16. May 2020, at 11.20, Gordon Yeong  wrote:
>>
>> Yeah I looked at that and ran my code on the python3 interpreter - it
>> worked.
>> Then i put it into a class - it worked.
>>  And then only did I put it (the class) to use in opensips..
>>
>> Had there been an issue, python3 would have kicked and scream which it
>> did not.
>>
>>  No issue with the regexp.
>>  Thank you
>>
>> Gordon
>>
>> On Sat, 16 May 2020 at 18:03, Tomi Hakkarainen  wrote:
>>
>>> Hi,
>>>
>>> not sure has this nothing to do with the error but game to my eye trying
>>> to figure out what this bunch of code is really doing...
>>>
>>> from python re docs:
>>>
>>> Regular expressions use the backslash character ('\') to indicate
>>> special forms or to allow special characters to be used without invoking
>>> their special meaning. This collides with Python’s usage of the same
>>> character for the same purpose in string literals; for example, to match a
>>> literal backslash, one might have to write '' as the pattern
>>> string, because the regular expression must be \\, and each backslash
>>> must be expressed as \\ inside a regular Python string literal. Also,
>>> please note that any invalid escape sequences in Python’s usage of the
>>> backslash in string literals now generate a DeprecationWarning
>>> <https://docs.python.org/3/library/exceptions.html#DeprecationWarning> and
>>> in the future this will become a SyntaxError
>>> <https://docs.python.org/3/library/exceptions.html#SyntaxError>. This
>>> behaviour will happen even if it is a valid escape sequence for a regular
>>> expression.
>>>
>>> The solution is to use Python’s raw string notation for regular
>>> expression patterns; backslashes are not handled in any special way in a
>>> string literal prefixed with 'r'. So r"\n" is a two-character string
>>> containing '\' and 'n', while "\n"is a one-character string containing
>>> a newline.
>>>
>>>
>>> Tomi
>>>
>>> On 16. May 2020, at 1.47, Gordon Yeong  wrote:
>>>
>>> 
>>> It's passed the init. If i did a print (LM_ERR) In the first line of
>>> init(), it doesn't show that print.
>>>
>>> If i  did a print (LM_ERR)a static string   in the get_rn()  before the
>>> line that calls compile(), i noticed that it does print out.  And if i
>>> tried to print a static string right after the compile() call,  it doesn'

Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-16 Thread Gordon Yeong
Tomi

I will try it on monday. Let u know. Thank you, stay safw and have a good
weekend :)

On Sat, 16 May 2020, 8:08 pm Tomi Hakkarainen,  wrote:

> Hi,
> My second guess :)
>
> Check this
> https://github.com/OpenSIPS/opensips/blob/master/modules/python/handler.py
>
> Differs from your version… Can these differences cause the failure?
>
> The __init__ located inside class
>
> And the mod_init located last in the script (does the order count for
> anything in python?)
>
> Also called handler function always returns 1 not the init
>
> Tomi
>
> On 16. May 2020, at 11.20, Gordon Yeong  wrote:
>
> Yeah I looked at that and ran my code on the python3 interpreter - it
> worked.
> Then i put it into a class - it worked.
>  And then only did I put it (the class) to use in opensips..
>
> Had there been an issue, python3 would have kicked and scream which it did
> not.
>
>  No issue with the regexp.
>  Thank you
>
> Gordon
>
> On Sat, 16 May 2020 at 18:03, Tomi Hakkarainen  wrote:
>
>> Hi,
>>
>> not sure has this nothing to do with the error but game to my eye trying
>> to figure out what this bunch of code is really doing...
>>
>> from python re docs:
>>
>> Regular expressions use the backslash character ('\') to indicate
>> special forms or to allow special characters to be used without invoking
>> their special meaning. This collides with Python’s usage of the same
>> character for the same purpose in string literals; for example, to match a
>> literal backslash, one might have to write '' as the pattern string,
>> because the regular expression must be \\, and each backslash must be
>> expressed as \\ inside a regular Python string literal. Also, please
>> note that any invalid escape sequences in Python’s usage of the backslash
>> in string literals now generate a DeprecationWarning
>> <https://docs.python.org/3/library/exceptions.html#DeprecationWarning> and
>> in the future this will become a SyntaxError
>> <https://docs.python.org/3/library/exceptions.html#SyntaxError>. This
>> behaviour will happen even if it is a valid escape sequence for a regular
>> expression.
>>
>> The solution is to use Python’s raw string notation for regular
>> expression patterns; backslashes are not handled in any special way in a
>> string literal prefixed with 'r'. So r"\n" is a two-character string
>> containing '\' and 'n', while "\n"is a one-character string containing a
>> newline.
>>
>>
>> Tomi
>>
>> On 16. May 2020, at 1.47, Gordon Yeong  wrote:
>>
>> 
>> It's passed the init. If i did a print (LM_ERR) In the first line of
>> init(), it doesn't show that print.
>>
>> If i  did a print (LM_ERR)a static string   in the get_rn()  before the
>> line that calls compile(), i noticed that it does print out.  And if i
>> tried to print a static string right after the compile() call,  it doesn't
>> print and it calls TypeError.
>>
>> That's why i suspect something is wrong bit can't tell exactly what
>>
>>
>> On Fri, 15 May 2020, 11:21 pm Ben Newlin,  wrote:
>>
>>> Gordon,
>>>
>>>
>>>
>>> Are you sure the TypeError is not occurring in mod_init? It looks like
>>> you are trying to do a print on a Class definition.
>>>
>>>
>>>
>>> Ben Newlin
>>>
>>>
>>>
>>> *From: *Users  on behalf of Gordon
>>> Yeong 
>>> *Reply-To: *OpenSIPS users mailling list 
>>> *Date: *Friday, May 15, 2020 at 1:54 AM
>>> *To: *OpenSIPS users mailling list 
>>> *Subject: *[OpenSIPS-Users] python module - python_exec() behaviour in
>>> opensips
>>>
>>>
>>>
>>> hi guys,
>>>
>>>  Using opensips 3.0 and python3 here.
>>>
>>>
>>>
>>>  I have a script which parses a number in a string
>>> (r'.*rn=\+6114(\d{2})').
>>>
>>>
>>>
>>> Script is as follows:
>>>
>>> -- start ---
>>>
>>>
>>>
>>>
>>>
>>> #!/usr/bin/python3
>>> import re;
>>> import pprint;
>>>
>>>
>>> class test:
>>>
>>> def get_rn():
>>> rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
>>> doit = rnRegExp.match( str("sip:+61386947785;npdi;rn=+
>>> 611...@tipt.ns.zippi.vocus.com;user=phone"));
>>>
>>> if doit:
>>> pp = p

Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-16 Thread Tomi Hakkarainen
Hi,
My second guess :)

Check this
https://github.com/OpenSIPS/opensips/blob/master/modules/python/handler.py 
<https://github.com/OpenSIPS/opensips/blob/master/modules/python/handler.py>

Differs from your version… Can these differences cause the failure?

The __init__ located inside class

And the mod_init located last in the script (does the order count for anything 
in python?)

Also called handler function always returns 1 not the init

Tomi

On 16. May 2020, at 11.20, Gordon Yeong  wrote:

Yeah I looked at that and ran my code on the python3 interpreter - it worked. 
Then i put it into a class - it worked.
 And then only did I put it (the class) to use in opensips..

Had there been an issue, python3 would have kicked and scream which it did not.

 No issue with the regexp. 
 Thank you

Gordon

On Sat, 16 May 2020 at 18:03, Tomi Hakkarainen mailto:tpai...@gmail.com>> wrote:
Hi,

not sure has this nothing to do with the error but game to my eye trying to 
figure out what this bunch of code is really doing...

from python re docs:

Regular expressions use the backslash character ('\') to indicate special forms 
or to allow special characters to be used without invoking their special 
meaning. This collides with Python’s usage of the same character for the same 
purpose in string literals; for example, to match a literal backslash, one 
might have to write '' as the pattern string, because the regular 
expression must be \\, and each backslash must be expressed as \\ inside a 
regular Python string literal. Also, please note that any invalid escape 
sequences in Python’s usage of the backslash in string literals now generate a 
DeprecationWarning 
<https://docs.python.org/3/library/exceptions.html#DeprecationWarning> and in 
the future this will become a SyntaxError 
<https://docs.python.org/3/library/exceptions.html#SyntaxError>. This behaviour 
will happen even if it is a valid escape sequence for a regular expression.

The solution is to use Python’s raw string notation for regular expression 
patterns; backslashes are not handled in any special way in a string literal 
prefixed with 'r'. So r"\n" is a two-character string containing '\' and 'n', 
while "\n"is a one-character string containing a newline.


Tomi

On 16. May 2020, at 1.47, Gordon Yeong mailto:anexi...@gmail.com>> wrote:


It's passed the init. If i did a print (LM_ERR) In the first line of init(), it 
doesn't show that print. 

If i  did a print (LM_ERR)a static string   in the get_rn()  before the line 
that calls compile(), i noticed that it does print out.  And if i tried to 
print a static string right after the compile() call,  it doesn't print and it 
calls TypeError.

That's why i suspect something is wrong bit can't tell exactly what


On Fri, 15 May 2020, 11:21 pm Ben Newlin, mailto:ben.new...@genesys.com>> wrote:
Gordon,

 

Are you sure the TypeError is not occurring in mod_init? It looks like you are 
trying to do a print on a Class definition.

 

Ben Newlin

 

From: Users mailto:users-boun...@lists.opensips.org>> on behalf of Gordon Yeong 
mailto:anexi...@gmail.com>>
Reply-To: OpenSIPS users mailling list mailto:users@lists.opensips.org>>
Date: Friday, May 15, 2020 at 1:54 AM
To: OpenSIPS users mailling list mailto:users@lists.opensips.org>>
Subject: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

 

hi guys,

 Using opensips 3.0 and python3 here.

 

 I have a script which parses a number in a string (r'.*rn=\+6114(\d{2})').

 

Script is as follows:

-- start ---

 

 

#!/usr/bin/python3
import re;
import pprint;


class test:

def get_rn():
rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
doit = rnRegExp.match( 
str("sip:+61386947785;npdi;rn=+611...@tipt.ns.zippi.vocus.com 
<mailto:611...@tipt.ns.zippi.vocus.com>;user=phone"));

if doit:
pp = pprint.PrettyPrinter(indent=4);
return doit.group(1);
else:
return None;

result = test.get_rn();

if result is None:
print("Got no match\n");
else:
print("Result is " + result);

 

--- end --

 

In my opensips setup, I have the function above looking like this:

 

 start


from OpenSIPS import LM_ERR
import re;
import pprint;

def mod_init():
print("In mod_init, SIP MSG is : ");
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(SIPMsg);
return SIPMsg();

def __init__():
return 1;

import re;
import pprint;

class SIPMsg:

def child_init(self, rank):
return 0

def get_rn(self, msg, raw_enum_result):
try:
 get_rn = re.compile(r'.*rn=\+6114(\d{2})');

 rn = get_rn.match(str(raw_enum_result));
 return rn.group(1);
except AttributeError:
 # Invalid input string
 LM_ERR(" a

Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-16 Thread Gordon Yeong
Yeah I looked at that and ran my code on the python3 interpreter - it
worked.
Then i put it into a class - it worked.
 And then only did I put it (the class) to use in opensips..

Had there been an issue, python3 would have kicked and scream which it did
not.

 No issue with the regexp.
 Thank you

Gordon

On Sat, 16 May 2020 at 18:03, Tomi Hakkarainen  wrote:

> Hi,
>
> not sure has this nothing to do with the error but game to my eye trying
> to figure out what this bunch of code is really doing...
>
> from python re docs:
>
> Regular expressions use the backslash character ('\') to indicate special
> forms or to allow special characters to be used without invoking their
> special meaning. This collides with Python’s usage of the same character
> for the same purpose in string literals; for example, to match a literal
> backslash, one might have to write '' as the pattern string, because
> the regular expression must be \\, and each backslash must be expressed
> as \\ inside a regular Python string literal. Also, please note that any
> invalid escape sequences in Python’s usage of the backslash in string
> literals now generate a DeprecationWarning
> <https://docs.python.org/3/library/exceptions.html#DeprecationWarning> and
> in the future this will become a SyntaxError
> <https://docs.python.org/3/library/exceptions.html#SyntaxError>. This
> behaviour will happen even if it is a valid escape sequence for a regular
> expression.
>
> The solution is to use Python’s raw string notation for regular expression
> patterns; backslashes are not handled in any special way in a string
> literal prefixed with 'r'. So r"\n" is a two-character string containing
> '\' and 'n', while "\n"is a one-character string containing a newline.
>
>
> Tomi
>
> On 16. May 2020, at 1.47, Gordon Yeong  wrote:
>
> 
> It's passed the init. If i did a print (LM_ERR) In the first line of
> init(), it doesn't show that print.
>
> If i  did a print (LM_ERR)a static string   in the get_rn()  before the
> line that calls compile(), i noticed that it does print out.  And if i
> tried to print a static string right after the compile() call,  it doesn't
> print and it calls TypeError.
>
> That's why i suspect something is wrong bit can't tell exactly what
>
>
> On Fri, 15 May 2020, 11:21 pm Ben Newlin,  wrote:
>
>> Gordon,
>>
>>
>>
>> Are you sure the TypeError is not occurring in mod_init? It looks like
>> you are trying to do a print on a Class definition.
>>
>>
>>
>> Ben Newlin
>>
>>
>>
>> *From: *Users  on behalf of Gordon
>> Yeong 
>> *Reply-To: *OpenSIPS users mailling list 
>> *Date: *Friday, May 15, 2020 at 1:54 AM
>> *To: *OpenSIPS users mailling list 
>> *Subject: *[OpenSIPS-Users] python module - python_exec() behaviour in
>> opensips
>>
>>
>>
>> hi guys,
>>
>>  Using opensips 3.0 and python3 here.
>>
>>
>>
>>  I have a script which parses a number in a string
>> (r'.*rn=\+6114(\d{2})').
>>
>>
>>
>> Script is as follows:
>>
>> -- start ---
>>
>>
>>
>>
>>
>> #!/usr/bin/python3
>> import re;
>> import pprint;
>>
>>
>> class test:
>>
>> def get_rn():
>> rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
>> doit = rnRegExp.match( str("sip:+61386947785;npdi;rn=+
>> 611...@tipt.ns.zippi.vocus.com;user=phone"));
>>
>> if doit:
>> pp = pprint.PrettyPrinter(indent=4);
>> return doit.group(1);
>> else:
>> return None;
>>
>> result = test.get_rn();
>>
>> if result is None:
>> print("Got no match\n");
>> else:
>> print("Result is " + result);
>>
>>
>>
>> --- end --
>>
>>
>>
>> In my opensips setup, I have the function above looking like this:
>>
>>
>>
>>  start
>>
>>
>> from OpenSIPS import LM_ERR
>> import re;
>> import pprint;
>>
>> def mod_init():
>> print("In mod_init, SIP MSG is : ");
>> pp = pprint.PrettyPrinter(indent=4)
>> pp.pprint(SIPMsg);
>> return SIPMsg();
>>
>> def __init__():
>> return 1;
>>
>> import re;
>> import pprint;
>>
>> class SIPMsg:
>>
>> def child_init(self, rank):
>> return 0
>>
>> def get_rn(self, msg, raw_enum_resul

Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-16 Thread Tomi Hakkarainen
Hi,

not sure has this nothing to do with the error but game to my eye trying to 
figure out what this bunch of code is really doing...

from python re docs:

Regular expressions use the backslash character ('\') to indicate special forms 
or to allow special characters to be used without invoking their special 
meaning. This collides with Python’s usage of the same character for the same 
purpose in string literals; for example, to match a literal backslash, one 
might have to write '' as the pattern string, because the regular 
expression must be \\, and each backslash must be expressed as \\ inside a 
regular Python string literal. Also, please note that any invalid escape 
sequences in Python’s usage of the backslash in string literals now generate a 
DeprecationWarning and in the future this will become a SyntaxError. This 
behaviour will happen even if it is a valid escape sequence for a regular 
expression.

The solution is to use Python’s raw string notation for regular expression 
patterns; backslashes are not handled in any special way in a string literal 
prefixed with 'r'. So r"\n" is a two-character string containing '\' and 'n', 
while "\n"is a one-character string containing a newline.


Tomi

On 16. May 2020, at 1.47, Gordon Yeong  wrote:


It's passed the init. If i did a print (LM_ERR) In the first line of init(), it 
doesn't show that print. 

If i  did a print (LM_ERR)a static string   in the get_rn()  before the line 
that calls compile(), i noticed that it does print out.  And if i tried to 
print a static string right after the compile() call,  it doesn't print and it 
calls TypeError.

That's why i suspect something is wrong bit can't tell exactly what


> On Fri, 15 May 2020, 11:21 pm Ben Newlin,  wrote:
> Gordon,
> 
>  
> 
> Are you sure the TypeError is not occurring in mod_init? It looks like you 
> are trying to do a print on a Class definition.
> 
>  
> 
> Ben Newlin
> 
>  
> 
> From: Users  on behalf of Gordon Yeong 
> 
> Reply-To: OpenSIPS users mailling list 
> Date: Friday, May 15, 2020 at 1:54 AM
> To: OpenSIPS users mailling list 
> Subject: [OpenSIPS-Users] python module - python_exec() behaviour in opensips
> 
>  
> 
> hi guys,
> 
>  Using opensips 3.0 and python3 here.
> 
>  
> 
>  I have a script which parses a number in a string (r'.*rn=\+6114(\d{2})').
> 
>  
> 
> Script is as follows:
> 
> -- start ---
> 
>  
> 
>  
> 
> #!/usr/bin/python3
> import re;
> import pprint;
> 
> 
> class test:
> 
> def get_rn():
> rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
> doit = rnRegExp.match( 
> str("sip:+61386947785;npdi;rn=+611...@tipt.ns.zippi.vocus.com;user=phone"));
> 
> if doit:
> pp = pprint.PrettyPrinter(indent=4);
> return doit.group(1);
> else:
> return None;
> 
> result = test.get_rn();
> 
> if result is None:
> print("Got no match\n");
> else:
> print("Result is " + result);
> 
>  
> 
> --- end --
> 
>  
> 
> In my opensips setup, I have the function above looking like this:
> 
>  
> 
>  start
> 
> 
> from OpenSIPS import LM_ERR
> import re;
> import pprint;
> 
> def mod_init():
> print("In mod_init, SIP MSG is : ");
> pp = pprint.PrettyPrinter(indent=4)
> pp.pprint(SIPMsg);
> return SIPMsg();
> 
> def __init__():
> return 1;
> 
> import re;
> import pprint;
> 
> class SIPMsg:
> 
> def child_init(self, rank):
> return 0
> 
> def get_rn(self, msg, raw_enum_result):
> try:
>  get_rn = re.compile(r'.*rn=\+6114(\d{2})');
> 
>  rn = get_rn.match(str(raw_enum_result));
>  return rn.group(1);
> except AttributeError:
>  # Invalid input string
>  LM_ERR(" attribute ERRor" );
>  return '';
> except TypeError:
>  # Invalid input string
>  LM_ERR(" Type Error" );
>  return '';
> else:
>  LM_ERR(" general ERRor" );
>  return '';
> 
>  
> 
> - end --
> 
>  
> 
>  
> 
>  
> 
> In my opensips config, I call the get_rn() function via python_exec() as 
> below.
> 
>  
> 
> $var(rn_code)=python_exec("get_rn", $var(raw_string));
> 
>  
> 
> I'm facing an issue here because when I run the script by itself in a command 
> line, it works.
> 
>  No "Error: Text Type" but when my opensips run, it keeps hitting 

Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-15 Thread Gordon Yeong
It's passed the init. If i did a print (LM_ERR) In the first line of
init(), it doesn't show that print.

If i  did a print (LM_ERR)a static string   in the get_rn()  before the
line that calls compile(), i noticed that it does print out.  And if i
tried to print a static string right after the compile() call,  it doesn't
print and it calls TypeError.

That's why i suspect something is wrong bit can't tell exactly what


On Fri, 15 May 2020, 11:21 pm Ben Newlin,  wrote:

> Gordon,
>
>
>
> Are you sure the TypeError is not occurring in mod_init? It looks like you
> are trying to do a print on a Class definition.
>
>
>
> Ben Newlin
>
>
>
> *From: *Users  on behalf of Gordon
> Yeong 
> *Reply-To: *OpenSIPS users mailling list 
> *Date: *Friday, May 15, 2020 at 1:54 AM
> *To: *OpenSIPS users mailling list 
> *Subject: *[OpenSIPS-Users] python module - python_exec() behaviour in
> opensips
>
>
>
> hi guys,
>
>  Using opensips 3.0 and python3 here.
>
>
>
>  I have a script which parses a number in a string (r'.*rn=\+6114(\d{2})').
>
>
>
> Script is as follows:
>
> -- start ---
>
>
>
>
>
> #!/usr/bin/python3
> import re;
> import pprint;
>
>
> class test:
>
> def get_rn():
> rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
> doit = rnRegExp.match( str("sip:+61386947785;npdi;rn=+
> 611...@tipt.ns.zippi.vocus.com;user=phone"));
>
> if doit:
> pp = pprint.PrettyPrinter(indent=4);
> return doit.group(1);
> else:
> return None;
>
> result = test.get_rn();
>
> if result is None:
> print("Got no match\n");
> else:
> print("Result is " + result);
>
>
>
> --- end --
>
>
>
> In my opensips setup, I have the function above looking like this:
>
>
>
>  start
>
>
> from OpenSIPS import LM_ERR
> import re;
> import pprint;
>
> def mod_init():
> print("In mod_init, SIP MSG is : ");
> pp = pprint.PrettyPrinter(indent=4)
> pp.pprint(SIPMsg);
> return SIPMsg();
>
> def __init__():
> return 1;
>
> import re;
> import pprint;
>
> class SIPMsg:
>
> def child_init(self, rank):
> return 0
>
> def get_rn(self, msg, raw_enum_result):
> try:
>  get_rn = re.compile(r'.*rn=\+6114(\d{2})');
>
>  rn = get_rn.match(str(raw_enum_result));
>  return rn.group(1);
> except AttributeError:
>  # Invalid input string
>  LM_ERR(" attribute ERRor" );
>  return '';
> except TypeError:
>  # Invalid input string
>  LM_ERR(" Type Error" );
>  return '';
> else:
>  LM_ERR(" general ERRor" );
>  return '';
>
>
>
> - end --
>
>
>
>
>
>
>
> In my opensips config, I call the get_rn() function via python_exec() as
> below.
>
>
>
> $var(rn_code)=python_exec("get_rn", $var(raw_string));
>
>
>
> I'm facing an issue here because when I run the script by itself in a
> command line, it works.
>
>  No "Error: Text Type" but when my opensips run, it keeps hitting a
> TypeError.
>
>  I have even explicitly fed the " rn =
> get_rn.match(str(raw_enum_result));" with an explicit string (ie. I dont
> send use the value passed in from the argument BUT instead, just feed it an
> explicit string value) and yet the same issue occurs.
>
>
>
> Does processing control belong directly to python3 when we call
> python_exec() or is there something funny going on here?
>
>
>
> Thank you
>
>
>
>
>
> Regards,
> Gordon
> ___
> Users mailing list
> Users@lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-15 Thread Ben Newlin
Gordon,

Are you sure the TypeError is not occurring in mod_init? It looks like you are 
trying to do a print on a Class definition.

Ben Newlin

From: Users  on behalf of Gordon Yeong 

Reply-To: OpenSIPS users mailling list 
Date: Friday, May 15, 2020 at 1:54 AM
To: OpenSIPS users mailling list 
Subject: [OpenSIPS-Users] python module - python_exec() behaviour in opensips

hi guys,
 Using opensips 3.0 and python3 here.

 I have a script which parses a number in a string (r'.*rn=\+6114(\d{2})').

Script is as follows:
-- start ---


#!/usr/bin/python3
import re;
import pprint;


class test:

def get_rn():
rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
doit = rnRegExp.match( 
str("sip:+61386947785;npdi;rn=+611...@tipt.ns.zippi.vocus.com<mailto:611...@tipt.ns.zippi.vocus.com>;user=phone"));

if doit:
pp = pprint.PrettyPrinter(indent=4);
return doit.group(1);
else:
return None;

result = test.get_rn();

if result is None:
print("Got no match\n");
else:
print("Result is " + result);

--- end --

In my opensips setup, I have the function above looking like this:

 start

from OpenSIPS import LM_ERR
import re;
import pprint;

def mod_init():
print("In mod_init, SIP MSG is : ");
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(SIPMsg);
return SIPMsg();

def __init__():
return 1;

import re;
import pprint;

class SIPMsg:

def child_init(self, rank):
return 0

def get_rn(self, msg, raw_enum_result):
try:
 get_rn = re.compile(r'.*rn=\+6114(\d{2})');

 rn = get_rn.match(str(raw_enum_result));
 return rn.group(1);
except AttributeError:
 # Invalid input string
 LM_ERR(" attribute ERRor" );
 return '';
except TypeError:
 # Invalid input string
 LM_ERR(" Type Error" );
 return '';
else:
 LM_ERR(" general ERRor" );
 return '';

- end --



In my opensips config, I call the get_rn() function via python_exec() as below.

$var(rn_code)=python_exec("get_rn", $var(raw_string));

I'm facing an issue here because when I run the script by itself in a command 
line, it works.
 No "Error: Text Type" but when my opensips run, it keeps hitting a TypeError.
 I have even explicitly fed the " rn = get_rn.match(str(raw_enum_result));" 
with an explicit string (ie. I dont send use the value passed in from the 
argument BUT instead, just feed it an explicit string value) and yet the same 
issue occurs.

Does processing control belong directly to python3 when we call python_exec() 
or is there something funny going on here?

Thank you


Regards,
Gordon
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


[OpenSIPS-Users] python module - python_exec() behaviour in opensips

2020-05-14 Thread Gordon Yeong
hi guys,
 Using opensips 3.0 and python3 here.

 I have a script which parses a number in a string (r'.*rn=\+6114(\d{2})').

Script is as follows:
-- start ---


#!/usr/bin/python3
import re;
import pprint;


class test:

def get_rn():
rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
doit = rnRegExp.match( str("sip:+61386947785;npdi;rn=+
611...@tipt.ns.zippi.vocus.com;user=phone"));

if doit:
pp = pprint.PrettyPrinter(indent=4);
return doit.group(1);
else:
return None;

result = test.get_rn();

if result is None:
print("Got no match\n");
else:
print("Result is " + result);

--- end --

In my opensips setup, I have the function above looking like this:

 start

from OpenSIPS import LM_ERR
import re;
import pprint;

def mod_init():
print("In mod_init, SIP MSG is : ");
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(SIPMsg);
return SIPMsg();

def __init__():
return 1;

import re;
import pprint;

class SIPMsg:

def child_init(self, rank):
return 0

def get_rn(self, msg, raw_enum_result):
try:
 get_rn = re.compile(r'.*rn=\+6114(\d{2})');

 rn = get_rn.match(str(raw_enum_result));
 return rn.group(1);
except AttributeError:
 # Invalid input string
 LM_ERR(" attribute ERRor" );
 return '';
except TypeError:
 # Invalid input string
 LM_ERR(" Type Error" );
 return '';
else:
 LM_ERR(" general ERRor" );
 return '';

- end --



In my opensips config, I call the get_rn() function via python_exec() as
below.

$var(rn_code)=python_exec("get_rn", $var(raw_string));

I'm facing an issue here because when I run the script by itself in a
command line, it works.
 No "Error: Text Type" but when my opensips run, it keeps hitting a
TypeError.
 I have even explicitly fed the " rn = get_rn.match(str(raw_enum_result));"
with an explicit string (ie. I dont send use the value passed in from the
argument BUT instead, just feed it an explicit string value) and yet the
same issue occurs.

Does processing control belong directly to python3 when we call
python_exec() or is there something funny going on here?

Thank you


Regards,
Gordon
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] python module - bug and questions

2017-04-21 Thread Maxim Sobolev
Robert, what Bogdan says is essentially correct. The OpenSIPS itself is not
using any threads AFAIK, therefore python module code is kept as simple as
possible. Now back to the original question: we use quite a lot of python
code in our routing and some of the python modules that are running are
actually creating threads on their own and it appears to be pretty stable.
What OS / python version are you using? What could be different in our case
is that we link our OpenSIPS binary with pthreads always (which may or may
not be the case on your build), so there might be some vital threads
runtime infrastructure that is not getting initialized in your case.

-Max


On Fri, Apr 21, 2017 at 1:25 AM, Bogdan-Andrei Iancu 
wrote:

> Hi Robert,
>
> The only question I can answer is 1) - OpenSIPS it is a multi-process
> application (and not using threads).
>
> How the python module is design (from threading perspective), I do not
> know - maybe Maxim, the author of this module can help with this.
>
> Regards,
>
> Bogdan-Andrei Iancu
>   OpenSIPS Founder and Developer
>   http://www.opensips-solutions.com
>
> OpenSIPS Summit May 2017 Amsterdam
>   http://www.opensips.org/events/Summit-2017Amsterdam.html
>
> On 04/19/2017 08:43 PM, Mundkowsky, Robert wrote:
>
>
>
> Hi,
>
>
>
> This email should likely go to your other dev forum, but I don’t have
> access yet.
>
>
>
> I am using openSIPS 2.2.3 on Ubuntu 16.04.2 LTS.
>
>
>
> I am using the python module.  The python script called works fine when
> called from outside openSIPS and it works fine when called inside openSIPS,
> if it is triggered once at a time.
>
>
>
> But if the python script is triggered twice by two phone calls or more or
> even one call after another in short order, then there are weird errors
> which show up in different places in the code like:
>
>
>
> ERROR:python:python_handle_exception: #011TypeError: an integer is
> required
>
>
>
> I am guessing the openSIP python module has some problem/s related to
> threading.
>
>
>
>
>
> Questions:
>
> 1)  I am guessing that OpenSIPS uses a multi-threaded architecture?
>
> 2)  Is the python module meant to be a single thread? Or
> multi-threaded?
>
> a.   If it is meant to be single threaded then why use python library
> thread functions? Just use python library without multi-threaded stuff.
>
> b.  If it is meant to be multi-threaded then why is there only one
> call to PyThreadState_New and myThreadState is a global used everywhere?
>
>i.  I
> would think a thread per call to python_exec would make more sense and make
> the code easier to understand?
>
> 3)  Also why is there no clean up code (PyThreadState_Clear,
> PyThreadState_Delete, Py_Finalize)?
>
> a.   I am guessing the idea is you do not need clean up, because it
> only happens when openSIPS is turned off.
>
>
>
> Robert
>
>
>
>
>
> For reference:
>
> 
> https://www.codeproject.com/articles/11805/embedding-python-in-c-c-part-i
>
> 
> http://www.awasu.com/weblog/embedding-python/threads/
>
>
> 
> http://stackoverflow.com/questions/26061298/python-multi-thread-multi-
> interpreter-c-api
>
>
>
> --
>
> This e-mail and any files transmitted with it may contain privileged or
> confidential information. It is solely for use by the individual for whom
> it is intended, even if addressed incorrectly. If you received this e-mail
> in error, please notify the sender; do not disclose, copy, distribute, or
> take any action in reliance on the contents of this information; and delete
> it from your system. Any other use of this e-mail is prohibited.
>
> Thank you for your compliance.
> --
>
>
> ___
> Users mailing 
> listUsers@lists.opensips.orghttp://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
>
>


-- 
Maksym Sobolyev
Sippy Software, Inc.
Internet Telephony (VoIP) Experts
Tel (Canada): +1-778-783-0474
Tel (Toll-Free): +1-855-747-7779
Fax: +1-866-857-6942
Web: http://www.sippysoft.com
MSN: sa...@sippysoft.com
Skype: SippySoft
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] python module - bug and questions

2017-04-21 Thread Bogdan-Andrei Iancu

Hi Robert,

The only question I can answer is 1) - OpenSIPS it is a multi-process 
application (and not using threads).


How the python module is design (from threading perspective), I do not 
know - maybe Maxim, the author of this module can help with this.


Regards,

Bogdan-Andrei Iancu
  OpenSIPS Founder and Developer
  http://www.opensips-solutions.com

OpenSIPS Summit May 2017 Amsterdam
  http://www.opensips.org/events/Summit-2017Amsterdam.html

On 04/19/2017 08:43 PM, Mundkowsky, Robert wrote:


Hi,

This email should likely go to your other dev forum, but I don’t have 
access yet.


I am using openSIPS 2.2.3 on Ubuntu 16.04.2 LTS.

I am using the python module.  The python script called works fine 
when called from outside openSIPS and it works fine when called inside 
openSIPS, if it is triggered once at a time.


But if the python script is triggered twice by two phone calls or more 
or even one call after another in short order, then there are weird 
errors which show up in different places in the code like:


ERROR:python:python_handle_exception: #011TypeError: an integer is 
required


I am guessing the openSIP python module has some problem/s related to 
threading.


Questions:

1)I am guessing that OpenSIPS uses a multi-threaded architecture?

2)Is the python module meant to be a single thread? Or multi-threaded?

a.If it is meant to be single threaded then why use python library 
thread functions? Just use python library without multi-threaded stuff.


b.If it is meant to be multi-threaded then why is there only one call 
to PyThreadState_New and myThreadState is a global used everywhere?


i.I would think a thread per call to python_exec would make more sense 
and make the code easier to understand?


3)Also why is there no clean up code (PyThreadState_Clear, 
PyThreadState_Delete, Py_Finalize)?


a.I am guessing the idea is you do not need clean up, because it only 
happens when openSIPS is turned off.


Robert

For reference:

https://www.codeproject.com/articles/11805/embedding-python-in-c-c-part-i

http://www.awasu.com/weblog/embedding-python/threads/

http://stackoverflow.com/questions/26061298/python-multi-thread-multi-interpreter-c-api




This e-mail and any files transmitted with it may contain privileged 
or confidential information. It is solely for use by the individual 
for whom it is intended, even if addressed incorrectly. If you 
received this e-mail in error, please notify the sender; do not 
disclose, copy, distribute, or take any action in reliance on the 
contents of this information; and delete it from your system. Any 
other use of this e-mail is prohibited.



Thank you for your compliance.




___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


[OpenSIPS-Users] python module - bug and questions

2017-04-19 Thread Mundkowsky, Robert

Hi,

This email should likely go to your other dev forum, but I don't have access 
yet.

I am using openSIPS 2.2.3 on Ubuntu 16.04.2 LTS.

I am using the python module.  The python script called works fine when called 
from outside openSIPS and it works fine when called inside openSIPS, if it is 
triggered once at a time.

But if the python script is triggered twice by two phone calls or more or even 
one call after another in short order, then there are weird errors which show 
up in different places in the code like:

ERROR:python:python_handle_exception: #011TypeError: an integer is required

I am guessing the openSIP python module has some problem/s related to threading.


Questions:

1)  I am guessing that OpenSIPS uses a multi-threaded architecture?

2)  Is the python module meant to be a single thread? Or multi-threaded?

a.   If it is meant to be single threaded then why use python library 
thread functions? Just use python library without multi-threaded stuff.

b.  If it is meant to be multi-threaded then why is there only one call to 
PyThreadState_New and myThreadState is a global used everywhere?

   i.  I would 
think a thread per call to python_exec would make more sense and make the code 
easier to understand?

3)  Also why is there no clean up code (PyThreadState_Clear, 
PyThreadState_Delete, Py_Finalize)?

a.   I am guessing the idea is you do not need clean up, because it only 
happens when openSIPS is turned off.

Robert


For reference:
https://www.codeproject.com/articles/11805/embedding-python-in-c-c-part-i
http://www.awasu.com/weblog/embedding-python/threads/
http://stackoverflow.com/questions/26061298/python-multi-thread-multi-interpreter-c-api




This e-mail and any files transmitted with it may contain privileged or 
confidential information. It is solely for use by the individual for whom it is 
intended, even if addressed incorrectly. If you received this e-mail in error, 
please notify the sender; do not disclose, copy, distribute, or take any action 
in reliance on the contents of this information; and delete it from your 
system. Any other use of this e-mail is prohibited.


Thank you for your compliance.


___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2012-08-27 Thread Bogdan-Andrei Iancu

Hi Duane,

The python module is not really obsolete, but rather an incomplete 
module - the developer (Maxim) uploading the module haven;t posted any 
documentation on it, so it is a kind of a black box (as usage).


Regards,

Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
http://www.opensips-solutions.com


On 08/25/2012 07:39 PM, Duane Larson wrote:


The python module is no longer maintained and is now obsolete.   
Bogdan greyed out the link a while back.


On Aug 25, 2012 9:01 AM, shaahin shaahin.mad...@gmail.com 
mailto:shaahin.mad...@gmail.com wrote:


Hi Maksym, I tried finding the documentation on the CookBooks
webpage http://www.opensips.org/Resources/DocsModules18, but
there still is no documentation made available there. Since this
thread belongs to more than 2 years ago, I am wondering whether
the documentation has never been written, or I am seeking it in
the wrong place. Cheers, Shaahin

View this message in context: Re: Python module on OpenSIPS ?

http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p7581417.html
Sent from the OpenSIPS - Users mailing list archive

http://opensips-open-sip-server.1449251.n2.nabble.com/OpenSIPS-Users-f1449235.html
at Nabble.com.

___
Users mailing list
Users@lists.opensips.org mailto:Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2012-08-27 Thread duane . larson

Ah. I knew at was something like that.

On , Bogdan-Andrei Iancu bog...@opensips.org wrote:







Hi Duane,





The python module is not really obsolete, but rather an
incomplete module - the developer (Maxim) uploading the module
haven;t posted any documentation on it, so it is a kind of a black
box (as usage).





Regards,




Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
http://www.opensips-solutions.com




On 08/25/2012 07:39 PM, Duane Larson wrote:




The python module is no longer maintained and is now
obsolete. Bogdan greyed out the link a while back.
On Aug 25, 2012 9:01 AM, shaahin shaahin.mad...@gmail.com
wrote:



Hi Maksym,
I tried finding the documentation on the CookBooks
webpage, but there still is no documentation made
available there. Since this thread belongs to more than 2
years ago, I am wondering whether the documentation has never
been written, or I am seeking it in the wrong place.
Cheers,
Shaahin




View this message in context: Re: Python module on OpenSIPS ?



Sent from the OpenSIPS - Users mailing list archive at
Nabble.com.





___



Users mailing list



Users@lists.opensips.org



http://lists.opensips.org/cgi-bin/mailman/listinfo/users










___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users







___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2012-08-25 Thread shaahin
Hi Maksym,

I tried finding the documentation on the 
http://www.opensips.org/Resources/DocsModules18 CookBooks webpage , but
there still is no documentation made available there. Since this thread
belongs to more than 2 years ago, I am wondering whether the documentation
has never been written, or I am seeking it in the wrong place.

Cheers,
Shaahin



--
View this message in context: 
http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p7581417.html
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2012-08-25 Thread Duane Larson
The python module is no longer maintained and is now obsolete.   Bogdan
greyed out the link a while back.
On Aug 25, 2012 9:01 AM, shaahin shaahin.mad...@gmail.com wrote:

 Hi Maksym, I tried finding the documentation on the CookBooks 
 webpagehttp://www.opensips.org/Resources/DocsModules18,
 but there still is no documentation made available there. Since this thread
 belongs to more than 2 years ago, I am wondering whether the documentation
 has never been written, or I am seeking it in the wrong place. Cheers,
 Shaahin
 --
 View this message in context: Re: Python module on OpenSIPS 
 ?http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p7581417.html
 Sent from the OpenSIPS - Users mailing list 
 archivehttp://opensips-open-sip-server.1449251.n2.nabble.com/OpenSIPS-Users-f1449235.htmlat
  Nabble.com.

 ___
 Users mailing list
 Users@lists.opensips.org
 http://lists.opensips.org/cgi-bin/mailman/listinfo/users


___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2012-08-25 Thread shaahin
Thanks for the response.

I need to customise the routing logic by making queries from another
database. Now that Python is out of the equation, what is the best choice of
implementing this customisation? Java  WeSIP don't seem to be good choices;
looks as if those are no longer maintained either. There remains only Perl,
I assume. I would appreciate any guide and advice.

Regards,
Shaahin



--
View this message in context: 
http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p7581420.html
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.

___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2012-08-25 Thread Ali Pey
Hi Shaahin,

If it's only DB queries check out the avpops modules. You can query any DB
and make decisions based on the results. If that's not enough, then I guess
Perl would be your best bet.

Regards,
Ali Pey

On Sat, Aug 25, 2012 at 1:22 PM, shaahin shaahin.mad...@gmail.com wrote:

 Thanks for the response.

 I need to customise the routing logic by making queries from another
 database. Now that Python is out of the equation, what is the best choice
 of
 implementing this customisation? Java  WeSIP don't seem to be good
 choices;
 looks as if those are no longer maintained either. There remains only Perl,
 I assume. I would appreciate any guide and advice.

 Regards,
 Shaahin



 --
 View this message in context:
 http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p7581420.html
 Sent from the OpenSIPS - Users mailing list archive at Nabble.com.

 ___
 Users mailing list
 Users@lists.opensips.org
 http://lists.opensips.org/cgi-bin/mailman/listinfo/users

___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2012-08-25 Thread shaahin
Thank you for the response, Ali.

Regards,
Shaahin



--
View this message in context: 
http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p7581424.html
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.

___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


[OpenSIPS-Users] Python module on OpenSIPS ?

2010-05-07 Thread samoh

Hi everybody,

I read on the site
(http://www.opensips.org/index.php?n=Resources.DocsModules), there is python
module but this path
http://www.opensips.org/html/docs/modules/devel/python.html don't exit ?!

I want to use the python script to manage my opensips 1.6. is there a
solution for that ?

Best regards.
Sam.
-- 
View this message in context: 
http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p5018382.html
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.

___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2010-05-07 Thread Bogdan-Andrei Iancu
Hi Sam,

Unfortunately the developer of this module haven't uploaded a 
documentation file for it - I asked him several time to do it, but I 
cannot do more...

At least the module will stay in the trunk (will not be pushed to 
stable) until it gets proper docs.

Regards,
Bogdan

samoh wrote:
 Hi everybody,

 I read on the site
 (http://www.opensips.org/index.php?n=Resources.DocsModules), there is python
 module but this path
 http://www.opensips.org/html/docs/modules/devel/python.html don't exit ?!

 I want to use the python script to manage my opensips 1.6. is there a
 solution for that ?

 Best regards.
 Sam.
   


-- 
Bogdan-Andrei Iancu
www.voice-system.ro


___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2010-05-07 Thread samoh

Thank you for your response.



2010/5/7 Bogdan-Andrei Iancu [via OpenSIPS (Open SIP Server)] 
ml-node+5019983-349032558-513...@n2.nabble.comml-node%2b5019983-349032558-513...@n2.nabble.com


 Hi Sam,

 Unfortunately the developer of this module haven't uploaded a
 documentation file for it - I asked him several time to do it, but I
 cannot do more...

 At least the module will stay in the trunk (will not be pushed to
 stable) until it gets proper docs.

 Regards,
 Bogdan

 samoh wrote:

  Hi everybody,
 
  I read on the site
  (http://www.opensips.org/index.php?n=Resources.DocsModules), there is
 python
  module but this path
  http://www.opensips.org/html/docs/modules/devel/python.html don't exit
 ?!
 
  I want to use the python script to manage my opensips 1.6. is there a
  solution for that ?
 
  Best regards.
  Sam.
 


 --
 Bogdan-Andrei Iancu
 www.voice-system.ro


 ___
 Users mailing list
 [hidden email] http://user/SendEmail.jtp?type=nodenode=5019983i=0
 http://lists.opensips.org/cgi-bin/mailman/listinfo/users


 --
  View message @
 http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p5019983.html
 To unsubscribe from Python module on OpenSIPS ?, click 
 herehttp://opensips-open-sip-server.1449251.n2.nabble.com/subscriptions/Unsubscribe.jtp?code=ZGFobWFuaS5zYW15QGdtYWlsLmNvbXw1MDE4MzgyfDIyODk1MzQ5Nw==.




-- 
View this message in context: 
http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p5020097.html
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] Python module on OpenSIPS ?

2010-05-07 Thread samoh

Hi Bogdan,

Thank you for your response.

Best regards.
Sam.
-- 
View this message in context: 
http://opensips-open-sip-server.1449251.n2.nabble.com/Python-module-on-OpenSIPS-tp5018382p5020105.html
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.

___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users