<div dir="ltr">tks</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/1/6  <span dir="ltr">&lt;<a href="mailto:twisted-web-request@twistedmatrix.com" target="_blank">twisted-web-request@twistedmatrix.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send Twisted-web mailing list submissions to<br>
        <a href="mailto:twisted-web@twistedmatrix.com">twisted-web@twistedmatrix.com</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:twisted-web-request@twistedmatrix.com">twisted-web-request@twistedmatrix.com</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:twisted-web-owner@twistedmatrix.com">twisted-web-owner@twistedmatrix.com</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of Twisted-web digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. Re: [Twisted-Python] Speed of rendering? (Peter Westlake)<br>
   2. Re: [Twisted-Python] Speed of rendering?<br>
      (<a href="mailto:exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a>)<br>
   3. file upload with twisted (Levi Nie)<br>
   4. Re: file upload with twisted (Glyph)<br>
   5. Re: file upload with twisted (??????? ?????)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Fri, 04 Jan 2013 18:30:47 +0000<br>
From: Peter Westlake &lt;<a href="mailto:peter.westlake@pobox.com">peter.westlake@pobox.com</a>&gt;<br>
Subject: Re: [Twisted-web] [Twisted-Python] Speed of rendering?<br>
To: Twisted Web World &lt;<a href="mailto:twisted-web@twistedmatrix.com">twisted-web@twistedmatrix.com</a>&gt;<br>
Message-ID:<br>
        &lt;<a href="mailto:1357324247.31399.140661173476561.11F56E5E@webmail.messagingengine.com">1357324247.31399.140661173476561.11F56E5E@webmail.messagingengine.com</a>&gt;<br>
<br>
Content-Type: text/plain<br>
<br>
A while back I promised to write some benchmarks for<br>
twisted.web.template&#39;s flattening functions. Is something like this<br>
suitable? If so, I&#39;ll add lots more test cases. The output format could<br>
be improved, too - any preferences?<br>
<br>
Peter.<br>
<br>
from twisted.web.template import flatten<br>
from twisted.web.server import Request<br>
import twisted.web.http<br>
<br>
channel = twisted.web.http.HTTPChannel()<br>
request = Request(channel, False)<br>
<br>
<br>
def make(content):<br>
    def f():<br>
        d = flatten(request, content, lambda _: None)<br>
        assert d.called<br>
    return f<br>
<br>
<br>
def test(content):<br>
    return timeit.timeit(stmt=make(content), number=repeats)<br>
<br>
repeats = 1000<br>
<br>
deeplist = [&#39;centre&#39;]<br>
for n in range(100):<br>
    deeplist = [deeplist]<br>
<br>
tests = {<br>
    &#39;empty&#39;: &#39;&#39;,<br>
    &#39;string&#39;: &#39;hello&#39;,<br>
    &#39;shortlist&#39;: [&#39;hello&#39;],<br>
    &#39;longlist&#39;: [str(n) for n in range(100)],<br>
    &#39;deeplist&#39;: deeplist,<br>
}<br>
<br>
<br>
if __name__ == &#39;__main__&#39;:<br>
    import timeit<br>
    from sys import argv<br>
    for name in argv[1:] or tests:<br>
        print name, test(tests[name])<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Fri, 04 Jan 2013 19:58:13 -0000<br>
From: <a href="mailto:exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a><br>
Subject: Re: [Twisted-web] [Twisted-Python] Speed of rendering?<br>
To: Twisted Web World &lt;<a href="mailto:twisted-web@twistedmatrix.com">twisted-web@twistedmatrix.com</a>&gt;<br>
Message-ID:<br>
        &lt;20130104195813.4649.1661214274.divmod.xquotient.20@localhost6.localdomain6&gt;<br>
<br>
Content-Type: text/plain; charset=&quot;utf-8&quot;; format=&quot;flowed&quot;<br>
<br>
On 06:30 pm, <a href="mailto:peter.westlake@pobox.com">peter.westlake@pobox.com</a> wrote:<br>
&gt;A while back I promised to write some benchmarks for<br>
&gt;twisted.web.template&#39;s flattening functions. Is something like this<br>
&gt;suitable? If so, I&#39;ll add lots more test cases. The output format could<br>
&gt;be improved, too - any preferences?<br>
<br>
The output should be something that we can load into our codespeed<br>
instance.  The output of any of the existing benchmarks in lp:twisted-<br>
benchmarks should be a good example of that format (I don&#39;t even recall<br>
what it is right now - it may not even be a &quot;format&quot; so much as a shape<br>
of data to submit to an HTTP API).<br>
<br>
The `timeit` module is probably not suitable to use to collect the data,<br>
as it makes some questionable choices with respect to measurement<br>
technique, and at the very least it&#39;s inconsistent with the rest of the<br>
benchmarks we have.<br>
<br>
Selecting data to operate on is probably an important part of this<br>
benchmark (or collection of benchmarks).  It may not be possible to<br>
capture all of the interesting performance characteristics in a single<br>
dataset.  However, at least something that includes HTML tags is<br>
probably desirable, since that is the primary use-case.<br>
<br>
There are some other Python templating systems with benchmarks.  One<br>
approach that might make sense is to try to build analogous benchmarks<br>
for twisted.web.template.  (Or perhaps a little thought will reveal that<br>
it&#39;s not possible to make comparisons between twisted.web.template and<br>
those systems, so there&#39;s no reason to follow their benchmarking lead.)<br>
<br>
Jean-Paul<br>
&gt;Peter.<br>
&gt;<br>
&gt;from twisted.web.template import flatten<br>
&gt;from twisted.web.server import Request<br>
&gt;import twisted.web.http<br>
&gt;<br>
&gt;channel = twisted.web.http.HTTPChannel()<br>
&gt;request = Request(channel, False)<br>
&gt;<br>
&gt;<br>
&gt;def make(content):<br>
&gt;    def f():<br>
&gt;        d = flatten(request, content, lambda _: None)<br>
&gt;        assert d.called<br>
&gt;    return f<br>
&gt;<br>
&gt;<br>
&gt;def test(content):<br>
&gt;    return timeit.timeit(stmt=make(content), number=repeats)<br>
&gt;<br>
&gt;repeats = 1000<br>
&gt;<br>
&gt;deeplist = [&#39;centre&#39;]<br>
&gt;for n in range(100):<br>
&gt;    deeplist = [deeplist]<br>
&gt;<br>
&gt;tests = {<br>
&gt;    &#39;empty&#39;: &#39;&#39;,<br>
&gt;    &#39;string&#39;: &#39;hello&#39;,<br>
&gt;    &#39;shortlist&#39;: [&#39;hello&#39;],<br>
&gt;    &#39;longlist&#39;: [str(n) for n in range(100)],<br>
&gt;    &#39;deeplist&#39;: deeplist,<br>
&gt;}<br>
&gt;<br>
&gt;<br>
&gt;if __name__ == &#39;__main__&#39;:<br>
&gt;    import timeit<br>
&gt;    from sys import argv<br>
&gt;    for name in argv[1:] or tests:<br>
&gt;        print name, test(tests[name])<br>
&gt;<br>
&gt;_______________________________________________<br>
&gt;Twisted-web mailing list<br>
&gt;<a href="mailto:Twisted-web@twistedmatrix.com">Twisted-web@twistedmatrix.com</a><br>
&gt;<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Sat, 5 Jan 2013 09:50:37 +0800<br>
From: Levi Nie &lt;<a href="mailto:levinie001@gmail.com">levinie001@gmail.com</a>&gt;<br>
Subject: [Twisted-web] file upload with twisted<br>
To: &quot;<a href="mailto:twisted-web@twistedmatrix.com">twisted-web@twistedmatrix.com</a>&quot; &lt;<a href="mailto:twisted-web@twistedmatrix.com">twisted-web@twistedmatrix.com</a>&gt;<br>
Message-ID:<br>
        &lt;CAEMsKDudEvLCeVf=<a href="mailto:sVPW_BE7rX2qtx9rAQERvssAMsckF9yYfA@mail.gmail.com">sVPW_BE7rX2qtx9rAQERvssAMsckF9yYfA@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br>
<br>
When i send a http request with a big file, can i check the content-length<br>
then enable or disable the<br>
file upload?<br>
<br>
I use the s3cmd client sent the request. And i need disable the file upload<br>
if the file size is over the quota.<br>
<br>
how can i do this?<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://twistedmatrix.com/pipermail/twisted-web/attachments/20130105/43bc7e14/attachment.html" target="_blank">http://twistedmatrix.com/pipermail/twisted-web/attachments/20130105/43bc7e14/attachment.html</a><br>

<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Fri, 4 Jan 2013 20:14:51 -0800<br>
From: Glyph &lt;<a href="mailto:glyph@twistedmatrix.com">glyph@twistedmatrix.com</a>&gt;<br>
Subject: Re: [Twisted-web] file upload with twisted<br>
To: Twisted Web World &lt;<a href="mailto:twisted-web@twistedmatrix.com">twisted-web@twistedmatrix.com</a>&gt;<br>
Message-ID: &lt;<a href="mailto:DEA8BBC4-E7C6-446B-90A3-BA1037BD1267@twistedmatrix.com">DEA8BBC4-E7C6-446B-90A3-BA1037BD1267@twistedmatrix.com</a>&gt;<br>
Content-Type: text/plain; charset=iso-8859-1<br>
<br>
<br>
On Jan 4, 2013, at 5:50 PM, Levi Nie &lt;<a href="mailto:levinie001@gmail.com">levinie001@gmail.com</a>&gt; wrote:<br>
<br>
&gt; When i send a http request with a big file, can i check the content-length then enable or disable the<br>
&gt; file upload?<br>
&gt;<br>
&gt; I use the s3cmd client sent the request. And i need disable the file upload if the file size is over the quota.<br>
&gt;<br>
&gt; how can i do this?<br>
<br>
This s3cmd? <a href="https://github.com/s3tools/s3cmd/blob/master/s3cmd" target="_blank">https://github.com/s3tools/s3cmd/blob/master/s3cmd</a><br>
<br>
It doesn&#39;t look like it uses Twisted, so I don&#39;t think this is a question for this list.<br>
<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 5<br>
Date: Sat, 5 Jan 2013 15:25:21 +0600<br>
From: ??????? ????? &lt;<a href="mailto:poisonoff@gmail.com">poisonoff@gmail.com</a>&gt;<br>
Subject: Re: [Twisted-web] file upload with twisted<br>
To: Twisted Web World &lt;<a href="mailto:twisted-web@twistedmatrix.com">twisted-web@twistedmatrix.com</a>&gt;<br>
Message-ID:<br>
        &lt;CACgbmJ=<a href="mailto:G-FZZee62VADTV2FcLUxu0zC4PY9R3LUa2CU7tVP2Lg@mail.gmail.com">G-FZZee62VADTV2FcLUxu0zC4PY9R3LUa2CU7tVP2Lg@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
I resolve same problem in self project, reimplement method<br>
handleContentChunk in server.Request<br>
<br>
My code:<br>
<br>
&lt;code&gt;# For maximum<br>
        handleContentChunkLength = 0<br>
<br>
        def handleContentChunk(self, data):<br>
                &quot;&quot;&quot;<br>
                Write a chunk of data.<br>
                &quot;&quot;&quot;<br>
                self.handleContentChunkLength += len(data)<br>
<br>
                if self.handleContentChunkLength &gt;= WEB_LIMIT_REQUEST_SIZE:<br>
                        self.transport.write(b&quot;HTTP/1.1 413 Request Entity Too Large\r\n\r\n&quot;)<br>
                        self.transport.loseConnection()<br>
<br>
                        # Raise to log error<br>
                        raise ValueError(&#39;Maximum length equal&#39;)<br>
<br>
                self.content.write(data)&lt;/code&gt;<br>
<br>
On Sat, Jan 5, 2013 at 10:14 AM, Glyph &lt;<a href="mailto:glyph@twistedmatrix.com">glyph@twistedmatrix.com</a>&gt; wrote:<br>
&gt;<br>
&gt; On Jan 4, 2013, at 5:50 PM, Levi Nie &lt;<a href="mailto:levinie001@gmail.com">levinie001@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; When i send a http request with a big file, can i check the content-length then enable or disable the<br>
&gt;&gt; file upload?<br>
&gt;&gt;<br>
&gt;&gt; I use the s3cmd client sent the request. And i need disable the file upload if the file size is over the quota.<br>
&gt;&gt;<br>
&gt;&gt; how can i do this?<br>
&gt;<br>
&gt; This s3cmd? <a href="https://github.com/s3tools/s3cmd/blob/master/s3cmd" target="_blank">https://github.com/s3tools/s3cmd/blob/master/s3cmd</a><br>
&gt;<br>
&gt; It doesn&#39;t look like it uses Twisted, so I don&#39;t think this is a question for this list.<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Twisted-web mailing list<br>
&gt; <a href="mailto:Twisted-web@twistedmatrix.com">Twisted-web@twistedmatrix.com</a><br>
&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br>
<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Twisted-web mailing list<br>
<a href="mailto:Twisted-web@twistedmatrix.com">Twisted-web@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br>
<br>
<br>
End of Twisted-web Digest, Vol 105, Issue 2<br>
*******************************************<br>
</blockquote></div><br></div>