[Twisted-Python] what is a non-class class?

2014-09-01 Thread Wolfgang Rohdewald
>From spread/jelly.py in _unjelly_method:

-if type(im_class) is not types.ClassType:
 raise InsecureJelly("Method found with non-class class.")

Same problem in _unjelly_instance

What is a non-class class or rather what sort of types is meant to
be insecure?

Suggestions for a better error message instead of "non-class class"?

This should work with both old style and new style classes, right
now it works only for old style and fails for new style. Working
with Python3 gives bonus points.

Current source code does not have test cases for both _unjelly_instance
and _unjelly_method using new style classes. My patch for ticket 4935
has a such a test case for _unjelly_method which fails as expected.

If only user defined classes are accepted as secure, see also
https://stackoverflow.com/questions/14612865/how-to-check-if-object-is-instance-of-new-style-user-defined-class

Would it be acceptable to instead exclude an explicit list of 
basic types as that stackoverflow answer suggests?

if im_class in (int, long, float, bool, list, set, frozenset, dict, type(None), 
str,
unicode, tuple, what else?):
  raise InsecureJelly

https://twistedmatrix.com/documents/current/api/twisted.spread.jelly.InsecureJelly.html
does not cover this.

Python 2.7.6:


>>> class A(object):
>>> 
...   pass  

... 

>>> type(A)
   

>>> type(int)


>>> import types
>>> 
>>> types.ClassType
   

>>> class B:
...   pass  

... 

>>> type(B)



Python 3.3:
>>> class A:
...   pass
... 
>>> type(A)

>>> type(int)



-- 
Wolfgang

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Using spawnProcess

2014-09-01 Thread exarkun

On 12:24 pm, grigorescu_cipr...@yahoo.com wrote:

Hello,
I have wrote a custom protocol(inherit from SMTPClient) and 
factory(inherit from ClientFactory) in order to send emails from 
multiple ips(multiple connections, factories).


Now I want to run this pice of code multiple times using spawnProcess 
to send emails simultaneous, each process having "n" connections from 
"n" ips.


How can i use spawnProcess? Or is another way to send emails in a 
parallel fashion with twisted? Maybe another approach?


You don't need multiple processes to send email concurrently.  If you 
were to use `twisted.mail.smtp.sendmail`, then you could do this by just 
making multiple calls to `sendmail`.  You don't have to wait for one 
email to be completely sent before you start trying to send the next 
one.  For example, to send two emails concurrently:



   from sys import stdout

   from twisted.mail.smtp import sendmail
   from twisted.internet.defer import gatherResults
   from twisted.internet.task import react
   from twisted.python.log import startLogging

   def main():
   return gatherResults([
   sendmail(...),
   sendmail(...),
   ])

   startLogging(stdout)
   react(main, [])

You should be able to do something similar with the API you've 
constructed (or perhaps you can just use `sendmail` instead).


Jean-Paul

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] jelly with new-style classes: method references are not resolved

2014-09-01 Thread exarkun

On 12:31 pm, wolfgang@rohdewald.de wrote:
Am Montag, 1. September 2014, 11:57:22 schrieb 
exar...@twistedmatrix.com:

>Why has this fix never been included? It is necessary for porting to
>Python 3.

Perhaps because the ticket was never given the "review" keyword - so 
no

one ever noticed that there was a potential fix attached to it.


So I should formally be able to review this since I am not the author.


Hi Wolfgang,

Your input on the issue would be much appreciated, yes.  However, since 
neither you nor the contributor has commit access, you can't actually 
grant the ticket a passing review.

What I can say for certain is that the fix looks OK, and porting to
Python3 depends on it.

Could somebody else please review this ticket 4935?


I took a look at the patch.  There are a couple issues:

 1) The tests are not written as unit tests which integrate into the 
existing test suite.  They need to be rewritten so that `trial twisted` 
will run them.


 2) It wasn't immediately obvious to me how the issue is fixed by the 
patch.  It would be nice to either comment on the ticket explaining how 
the change fixes the problem or add such information in a comment near 
the code that is changing.


Thanks,
Jean-Paul

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] jelly with new-style classes: method references are not resolved

2014-09-01 Thread Wolfgang Rohdewald
Am Montag, 1. September 2014, 11:57:22 schrieb exar...@twistedmatrix.com:
> >Why has this fix never been included? It is necessary for porting to 
> >Python 3.
> 
> Perhaps because the ticket was never given the "review" keyword - so no 
> one ever noticed that there was a potential fix attached to it.

So I should formally be able to review this since I am not the author.

What I can say for certain is that the fix looks OK, and porting to
Python3 depends on it.

Could somebody else please review this ticket 4935?

-- 
Wolfgang

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] Using spawnProcess

2014-09-01 Thread Grigorescu Ciprian
Hello,
I have wrote a custom protocol(inherit from SMTPClient) and factory(inherit 
from ClientFactory) in order to send emails from multiple ips(multiple 
connections, factories).

Now I want to run this pice of code multiple times using spawnProcess to send 
emails simultaneous, each process having "n" connections from "n" ips.

How can i use spawnProcess? Or is another way to send emails in a parallel 
fashion with twisted? Maybe another approach? 



Thank you,___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] jelly with new-style classes: method references are not resolved

2014-09-01 Thread exarkun

On 11:39 am, wolfgang@rohdewald.de wrote:

Hi,

while trying to port jelly to Python 3 (banana tests already pass with 
Python 3),


I found a bug in jelly. It has already been reported 3 years ago with 
ticket 4935.


And there is a fix attached to that ticket. This fix resolves the 
problem for me.


Why has this fix never been included? It is necessary for porting to 
Python 3.


Perhaps because the ticket was never given the "review" keyword - so no 
one ever noticed that there was a potential fix attached to it.


See https://twistedmatrix.com/trac/wiki/ReviewProcess

Jean-Paul

--
Wolfgang

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] jelly with new-style classes: method references are not resolved

2014-09-01 Thread Wolfgang Rohdewald
Hi,

while trying to port jelly to Python 3 (banana tests already pass with Python 
3),

I found a bug in jelly. It has already been reported 3 years ago with ticket 
4935.

And there is a fix attached to that ticket. This fix resolves the problem for 
me.

Why has this fix never been included? It is necessary for porting to Python 3.

-- 
Wolfgang

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python