小学园PHP | 18 Apr 2013 09:36
Favicon

Can i inherit the twisted.web.http.Request.requestReceived ??

Can i inherit the twisted.web.http.Request.requestReceived ??

In the comment, said that "This method is not intended for users".
I has inherited the rawDataReceived and it like this:

def rawDataReceived(self, data):
        self.resetTimeout()
        if len(data) < self.length:
            self.requests[-1].content.send(data)
            self.length = self.length - len(data)
        else:
            self.requests[-1].content.send(data[:self.length])
            self._finishRequestBody(data[self.length:])

the "self.requests[-1].content.send(data)" will send the data in another http connection. In fact, i use the httplib here.
All goes well, but it doesn't work at the last step in allContentReceived. And it's req.requestReceived(command, path, version).

So can i inherit this method requestReceived. Or where is it go wrong?

my code is here. You can download it.
Attachment (cumulus.py): application/octet-stream, 29 KiB
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
小学园PHP | 18 Apr 2013 09:01
Favicon

Can i inherit the twisted.web.http.Request.requestReceived ??

Can i inherit the twisted.web.http.Request.requestReceived ??

In the comment, said that "This method is not intended for users".
I has inherited the rawDataReceived and it like this:

def rawDataReceived(self, data):
        self.resetTimeout()
        if len(data) < self.length:
            self.requests[-1].content.send(data)
            self.length = self.length - len(data)
        else:
            self.requests[-1].content.send(data[:self.length])
            self._finishRequestBody(data[self.length:])

the "self.requests[-1].content.send(data)" will send the data in another http connection. In fact, i use the httplib here.
All goes well, but it doesn't work at the last step in allContentReceived. And it's req.requestReceived(command, path, version).

So can i inherit this method requestReceived. Or where is it go wrong? 

my code is in the accessory
Attachment (cumulus.py): application/octet-stream, 29 KiB
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Matt Behrens | 5 Apr 2013 14:15
Gravatar

HTTP authentication for twisted.web.client.Agent (#5148)

Hi all,

I'm looking into Twisted for some projects at work and believe I may be able to work on #5148 <http://twistedmatrix.com/trac/ticket/5148> to add HTTP authentication to twisted.web.client.Agent, since I need at least Basic support (and will probably just add Digest too while I'm at it.)

I took a look at the branch changeset <http://twistedmatrix.com/trac/changeset?new=32269%40branches%2Fhttp-client-auth-5148-2&old=32267%40trunk> and it looks like what's been done so far is the addition of a basic agent that will eventually talk to an as-of-yet-uninvented responder that will provide the authentication.  Is there any more than this at this point?  Did anyone have ideas that they felt would work better?

I'm pretty new to actually using Twisted, but I think I get it.  I may need some help making the end result fit well, since I'm discovering a lot of new things as I dig into the source.  (Obviously, step 1 is bring that work up to the trunk… my merge attempt was a disaster, so I might just hand-apply the changes for now.)

P.S. I'm zigg on IRC and Trac, but I'm not necessarily online or responsive most of the time.
Attachment (smime.p7s): application/pkcs7-signature, 4334 bytes
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Adam Buga | 25 Mar 2013 18:43
Picon

txJSON-RPC, deferred, and longpolling ajax -- limited number of connections, setting

Hi,
I'm writing a simple JSONRPC server that is intended to have a number of longpolling http connections. 

-On the server side, I'm using txJSON-RPC and utilizing returning deferred (which translate into NOT_DONE_YET at the next layer). 
-On a clientside, I'm using JQuery to kick off a longpolling ajax POST to the rpc interface. 

Upon the requests arrival to the RPC server I returned a Deferred, adding it to my list. The POST should only return data (finish the request) once the server side has some changed state. It works for basic tests. 

However, once I increase the number of outstanding connections, I don't see any more connections accepted from my browser. I seem to be capped at 6 open connections. If I start a new browser, ie: chrome, or even change the URL from localhost to 127.0.0.1 I'm able to open another 6. 

I've never done much server programming so I'm a bit confused as to where to look to fix this. I've import pdb and set_trace() all the way down to the tcp.py part and I still don't see any activity coming in.

What steps should I take to identify and fix this limitation? Any help would be appreciated!

-Adam
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
小学园PHP | 22 Mar 2013 02:34
Favicon

Re: Twisted-web Digest, Vol 107, Issue 4

Thanks, Laurens. I will have a try with your advices.

Message: 2
Date: Thu, 21 Mar 2013 07:32:18 -0700
From: Laurens Van Houtven <_ <at> lvh.cc>
Subject: Re: [Twisted-web] A Question, TIA!
To: Twisted Web World <twisted-web <at> twistedmatrix.com>
Message-ID:
<CAE_Hg6YN8-cf42=ddPSW2w6zJ08-R+9z=+9G0q2EHOXYyMSRdQ <at> mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Sounds like you want twisted.web.client.Agent;  when you make a request you
get an IResponse object that has a deliverBody method that takes a
protocol. That protocol can receive chunks (dataReceived), or you could use
e.g. a LineReceiver if you know they're delimited chunks.



_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
小学园PHP | 21 Mar 2013 08:48
Favicon

A Question, TIA!

My program(Cumulus) receives http put(file by chunk).

And then resend the file to another process(Hadoop).
The trouble is that i need get the file object in my program(not stored on disk then read from).
So where should i get it? rawDataReceived or allContentReceived?
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
A Desai | 12 Mar 2013 11:15
Picon
Favicon

Setting of TCP Receive buffer size and Flow Control in producer/consumer

Scenario:  TCP Receive Buffer on twisted HTTP server using the twisted application framework.  And its behavior when set up as producer/consumer.

(1) Would like to set the receive buffer size on socket.  One way to do this would be to create a derived class of TCPServer (or SSLServer) and set the buffer size and use derived class server in the .tac file.  Would like to know if there is any sample code for such usage?  For example, in which method of the derived class would one set the receive buffer size?

(2) When an incoming http POST request is acting as a producer of data, which is tied to a consumer resource (some other connection), how can I control the incoming tcp window size, if the consumer has paused consuming?  I presume the incoming network data will keep piling up in the 'huge' tcp buffer eventually advertising a 'tcp zero window' to the network peer of the data producer, AND the server ends up using up a large amount of memory for the paused connection.  Is there an alternative?  I realize that the TCP protocol inhibits 'reducing of an already advertised receive window', but I am wondering if pauseProducing() on an http channel could do something to at least prevent the tcp window size from increasing any further?

Thank you,
Arun
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Levi Nie | 15 Jan 2013 10:58
Picon

Re: Twisted-web Digest, Vol 105, Issue 2

tks


2013/1/6 <twisted-web-request <at> twistedmatrix.com>
Send Twisted-web mailing list submissions to
        twisted-web <at> twistedmatrix.com

To subscribe or unsubscribe via the World Wide Web, visit
        http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
or, via email, send a message with subject or body 'help' to
        twisted-web-request <at> twistedmatrix.com

You can reach the person managing the list at
        twisted-web-owner <at> twistedmatrix.com

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Twisted-web digest..."


Today's Topics:

   1. Re: [Twisted-Python] Speed of rendering? (Peter Westlake)
   2. Re: [Twisted-Python] Speed of rendering?
      (exarkun <at> twistedmatrix.com)
   3. file upload with twisted (Levi Nie)
   4. Re: file upload with twisted (Glyph)
   5. Re: file upload with twisted (??????? ?????)


----------------------------------------------------------------------

Message: 1
Date: Fri, 04 Jan 2013 18:30:47 +0000
From: Peter Westlake <peter.westlake <at> pobox.com>
Subject: Re: [Twisted-web] [Twisted-Python] Speed of rendering?
To: Twisted Web World <twisted-web <at> twistedmatrix.com>
Message-ID:
        <1357324247.31399.140661173476561.11F56E5E <at> webmail.messagingengine.com>

Content-Type: text/plain

A while back I promised to write some benchmarks for
twisted.web.template's flattening functions. Is something like this
suitable? If so, I'll add lots more test cases. The output format could
be improved, too - any preferences?

Peter.

from twisted.web.template import flatten
from twisted.web.server import Request
import twisted.web.http

channel = twisted.web.http.HTTPChannel()
request = Request(channel, False)


def make(content):
    def f():
        d = flatten(request, content, lambda _: None)
        assert d.called
    return f


def test(content):
    return timeit.timeit(stmt=make(content), number=repeats)

repeats = 1000

deeplist = ['centre']
for n in range(100):
    deeplist = [deeplist]

tests = {
    'empty': '',
    'string': 'hello',
    'shortlist': ['hello'],
    'longlist': [str(n) for n in range(100)],
    'deeplist': deeplist,
}


if __name__ == '__main__':
    import timeit
    from sys import argv
    for name in argv[1:] or tests:
        print name, test(tests[name])



------------------------------

Message: 2
Date: Fri, 04 Jan 2013 19:58:13 -0000
From: exarkun <at> twistedmatrix.com
Subject: Re: [Twisted-web] [Twisted-Python] Speed of rendering?
To: Twisted Web World <twisted-web <at> twistedmatrix.com>
Message-ID:
        <20130104195813.4649.1661214274.divmod.xquotient.20 <at> localhost6.localdomain6>

Content-Type: text/plain; charset="utf-8"; format="flowed"

On 06:30 pm, peter.westlake <at> pobox.com wrote:
>A while back I promised to write some benchmarks for
>twisted.web.template's flattening functions. Is something like this
>suitable? If so, I'll add lots more test cases. The output format could
>be improved, too - any preferences?

The output should be something that we can load into our codespeed
instance.  The output of any of the existing benchmarks in lp:twisted-
benchmarks should be a good example of that format (I don't even recall
what it is right now - it may not even be a "format" so much as a shape
of data to submit to an HTTP API).

The `timeit` module is probably not suitable to use to collect the data,
as it makes some questionable choices with respect to measurement
technique, and at the very least it's inconsistent with the rest of the
benchmarks we have.

Selecting data to operate on is probably an important part of this
benchmark (or collection of benchmarks).  It may not be possible to
capture all of the interesting performance characteristics in a single
dataset.  However, at least something that includes HTML tags is
probably desirable, since that is the primary use-case.

There are some other Python templating systems with benchmarks.  One
approach that might make sense is to try to build analogous benchmarks
for twisted.web.template.  (Or perhaps a little thought will reveal that
it's not possible to make comparisons between twisted.web.template and
those systems, so there's no reason to follow their benchmarking lead.)

Jean-Paul
>Peter.
>
>from twisted.web.template import flatten
>from twisted.web.server import Request
>import twisted.web.http
>
>channel = twisted.web.http.HTTPChannel()
>request = Request(channel, False)
>
>
>def make(content):
>    def f():
>        d = flatten(request, content, lambda _: None)
>        assert d.called
>    return f
>
>
>def test(content):
>    return timeit.timeit(stmt=make(content), number=repeats)
>
>repeats = 1000
>
>deeplist = ['centre']
>for n in range(100):
>    deeplist = [deeplist]
>
>tests = {
>    'empty': '',
>    'string': 'hello',
>    'shortlist': ['hello'],
>    'longlist': [str(n) for n in range(100)],
>    'deeplist': deeplist,
>}
>
>
>if __name__ == '__main__':
>    import timeit
>    from sys import argv
>    for name in argv[1:] or tests:
>        print name, test(tests[name])
>
>_______________________________________________
>Twisted-web mailing list
>Twisted-web <at> twistedmatrix.com
>http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web



------------------------------

Message: 3
Date: Sat, 5 Jan 2013 09:50:37 +0800
From: Levi Nie <levinie001 <at> gmail.com>
Subject: [Twisted-web] file upload with twisted
To: "twisted-web <at> twistedmatrix.com" <twisted-web <at> twistedmatrix.com>
Message-ID:
        <CAEMsKDudEvLCeVf=sVPW_BE7rX2qtx9rAQERvssAMsckF9yYfA <at> mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

When i send a http request with a big file, can i check the content-length
then enable or disable the
file upload?

I use the s3cmd client sent the request. And i need disable the file upload
if the file size is over the quota.

how can i do this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20130105/43bc7e14/attachment.html

------------------------------

Message: 4
Date: Fri, 4 Jan 2013 20:14:51 -0800
From: Glyph <glyph <at> twistedmatrix.com>
Subject: Re: [Twisted-web] file upload with twisted
To: Twisted Web World <twisted-web <at> twistedmatrix.com>
Message-ID: <DEA8BBC4-E7C6-446B-90A3-BA1037BD1267 <at> twistedmatrix.com>
Content-Type: text/plain; charset=iso-8859-1


On Jan 4, 2013, at 5:50 PM, Levi Nie <levinie001 <at> gmail.com> wrote:

> When i send a http request with a big file, can i check the content-length then enable or disable the
> file upload?
>
> I use the s3cmd client sent the request. And i need disable the file upload if the file size is over the quota.
>
> how can i do this?

This s3cmd? https://github.com/s3tools/s3cmd/blob/master/s3cmd

It doesn't look like it uses Twisted, so I don't think this is a question for this list.




------------------------------

Message: 5
Date: Sat, 5 Jan 2013 15:25:21 +0600
From: ??????? ????? <poisonoff <at> gmail.com>
Subject: Re: [Twisted-web] file upload with twisted
To: Twisted Web World <twisted-web <at> twistedmatrix.com>
Message-ID:
        <CACgbmJ=G-FZZee62VADTV2FcLUxu0zC4PY9R3LUa2CU7tVP2Lg <at> mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

I resolve same problem in self project, reimplement method
handleContentChunk in server.Request

My code:

<code># For maximum
        handleContentChunkLength = 0

        def handleContentChunk(self, data):
                """
                Write a chunk of data.
                """
                self.handleContentChunkLength += len(data)

                if self.handleContentChunkLength >= WEB_LIMIT_REQUEST_SIZE:
                        self.transport.write(b"HTTP/1.1 413 Request Entity Too Large\r\n\r\n")
                        self.transport.loseConnection()

                        # Raise to log error
                        raise ValueError('Maximum length equal')

                self.content.write(data)</code>

On Sat, Jan 5, 2013 at 10:14 AM, Glyph <glyph <at> twistedmatrix.com> wrote:
>
> On Jan 4, 2013, at 5:50 PM, Levi Nie <levinie001 <at> gmail.com> wrote:
>
>> When i send a http request with a big file, can i check the content-length then enable or disable the
>> file upload?
>>
>> I use the s3cmd client sent the request. And i need disable the file upload if the file size is over the quota.
>>
>> how can i do this?
>
> This s3cmd? https://github.com/s3tools/s3cmd/blob/master/s3cmd
>
> It doesn't look like it uses Twisted, so I don't think this is a question for this list.
>
>
> _______________________________________________
> Twisted-web mailing list
> Twisted-web <at> twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web



------------------------------

_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web


End of Twisted-web Digest, Vol 105, Issue 2
*******************************************

_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Levi Nie | 15 Jan 2013 09:55
Picon

interrupt the file sending if the file size over the quota...some errors here...

i want to interrupt the file sending. but i can't change the client. so i need change the server.
All things go well, but the message i wanna response seem not work.
is the self.transport.loseConnection() (the last line) blocking the messages?
in fact, i work on Cumulus(nimbus project) which based on twisted. And i use s3cmd as the client.

here is the my code:

        def headerReceived(self,line):
        pycb.log(logging.INFO, "===== def headerReceived of cumulus.py")
        http.HTTPChannel.headerReceived(self,line)
        pycb.log(logging.INFO, "===== self.length is %s"%self.length)
        
        header, data = line.split(':', 1)
        header = header.lower()
        data = data.strip()
        if header=='authorization':
            self.authorization=data
            
        
        if self.length and self.authorization:
            user_id = self.authorization.split(':')[0].split()[1].strip()
            user = pycb.config.auth.get_user(user_id)
    
            pycb.log(logging.INFO, "===== user who put this object is %s"%user)
            
            remaining_quota = user.get_remaining_quota()
            pycb.log(logging.INFO, "===== remaining_quota is %s"%remaining_quota)
            quota_check=self.length-remaining_quota
            pycb.log(logging.INFO, "===== quota_check=self.length-remaining_quota of cumulus.py")
            
            if quota_check>0:
                requestId = str(uuid.uuid1()).replace("-", "")
                ex=cbException('AccountProblem')
                
                m_msg = "HTTP/1.1 %s %s\r\n" % (ex.httpCode, ex.httpDesc)
                self.transport.write(m_msg)
                
                m_msg = "%s: %s\r\n" % (('x-amz-request-id', requestId))
                self.transport.write(m_msg)
                #req.setHeader('x-amz-request-id', requestId)
                
                m_msg = "%s: %s\r\n" % (('x-amz-id-2', str(uuid.uuid1())))
                self.transport.write(m_msg)
                
                e_msg = ex.make_xml_string(self._path, str(uuid.uuid1()))
                pycb.log(logging.INFO, "===== e_msg is %s"%e_msg)
                #self.transport.write("\r\n")
                self.transport.write(e_msg)
                pycb.log(logging.INFO, "===== self.transport.write(e_msg)")
                
                
                self.transport.loseConnection()
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Levi Nie | 5 Jan 2013 02:50
Picon

file upload with twisted

When i send a http request with a big file, can i check the content-length then enable or disable the
file upload?

I use the s3cmd client sent the request. And i need disable the file upload if the file size is over the quota.

how can i do this?
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Peter Westlake | 4 Jan 2013 17:00
Picon
Favicon

Redirect after login with nevow guard

I'm using nevow.guard, and when someone logs in I would like to send
them to the URL they originally typed. It's possible to do this by
posting to the URL guard.LOGIN_AVATAR + other stuff, e.g. to go to
http://example.com/foo/bar after logging in, the login page should post
to http://example.com/__login__/foo/bar. This works nicely. The problem
is, the login page doesn't know that the user was trying to go to
foo/bar. How can it get that information? I would have thought that it
would be available as the segments argument in locateChild, but for some
reason it isn't. Before logging in, the segments argument is always
empty.

Peter.

Gmane