Re: symlinks with python3 http.server.CGIHTTPRequestHandler

2022-01-11 Thread Kirill Ratkin

Hi

Maybe you have some restrictions on file system level. Some selinux for 
example.



I try similar steps on my local 'linux mint' and ... linked script is 
called my http.server without errors.



Here is my 'tree':

├── cgi-bin
│   └── test.py -> ../orig.py
└── orig.py

All files are executable and test.py is link to orig.py which is in one 
directory level up:


$ ls -Rla
.:
total 16
drwxrwxr-x  3 kirill kirill 4096 Jan 11 14:04 .
drwxrwxrwt 23 root   root   4096 Jan 11 14:11 ..
drwxrwxr-x  2 kirill kirill 4096 Jan 11 14:03 cgi-bin
-rwxrwxr-x  1 kirill kirill   31 Jan 11 14:04 orig.py

./cgi-bin:
total 8
drwxrwxr-x 2 kirill kirill 4096 Jan 11 14:03 .
drwxrwxr-x 3 kirill kirill 4096 Jan 11 14:04 ..
lrwxrwxrwx 1 kirill kirill   10 Jan 11 14:03 test.py -> ../orig.py

I do 'curl' request:

curl -v http://0.0.0.0:8000/cgi-bin/test.py

And http.server get log:

$ python3 -m http.server --cgi 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
127.0.0.1 - - [11/Jan/2022 14:40:19] "GET /cgi-bin/test.py HTTP/1.1" 200 -


On 1/10/22 22:10, Nat Taylor wrote:

python3 -m http.server --cgi 8090

--
https://mail.python.org/mailman/listinfo/python-list


Re: symlinks with python3 http.server.CGIHTTPRequestHandler

2022-01-11 Thread Chris Angelico
On Tue, Jan 11, 2022 at 6:17 AM Nat Taylor  wrote:
>
> Is it possible to get http.server.CGIHTTPRequestHandler to run a symlink-ed
> script?
>
> In the example below, GET /cgi-bin/test.py results in a 404 because it is a
> symlink.
>
> % mkdir -p test/cgi-bin
> % cd test
> % vi test.py
> % chmod +x test.py
> % ln -s test.py cgi-bin

I just noticed something. This might not produce the effect you want;
a symlink aims at a specific named target, and if you use a relative
path, it's relative to the directory containing the symlink, not the
directory you were in when you created it. What happens if, instead,
you do this:

% cd cgi-bin
% ln -s ../test.py .

? Conversely, can you, with whichever setup you're looking at, read
the source code for the script by catting it from cgi-bin? It might be
that the link is actually unreadable or pointing to the wrong place.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Script profiling details

2022-01-11 Thread Dieter Maurer
Joseph L. Casale wrote at 2022-1-10 18:43 +:
> ...
>I expected this given the implementation, but I was hoping to get some
>finer details so I can track down the specific module or at least the specific
>file so I have a place to start reviewing code for optimizations.
>
>Is there something I can use to analyze the existing profile output or to 
>generate
>it with more feedback?

You might try `py-spy`.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why operations between dict views return a set and not a frozenset?

2022-01-11 Thread Marco Sulla
Ok... so I suppose, since you're inviting me to use dis and look at the
bytecode, that are you talking about constants in assembly, so const in C?
Sorry for the confusion, I'm not so skilled in C and I know nearly nothing
about assembly. Furthermore I never look at the bytecode of any language
before, so I simply didn't understand you.

I think this is what you mean:

>>> dis.dis("for _ in {1, 2}: pass")
  1   0 SETUP_LOOP  12 (to 14)
  2 LOAD_CONST   3 (frozenset({1, 2}))
  4 GET_ITER
>>6 FOR_ITER 4 (to 12)
  8 STORE_NAME   0 (_)
 10 JUMP_ABSOLUTE6
>>   12 POP_BLOCK
>>   14 LOAD_CONST   2 (None)
 16 RETURN_VALUE
>>> a = {1, 2}
>>> dis.dis("for _ in a: pass")
  1   0 SETUP_LOOP  12 (to 14)
  2 LOAD_NAME0 (a)
  4 GET_ITER
>>6 FOR_ITER 4 (to 12)
  8 STORE_NAME   1 (_)
 10 JUMP_ABSOLUTE6
>>   12 POP_BLOCK
>>   14 LOAD_CONST   0 (None)
 16 RETURN_VALUE


On Tue, 11 Jan 2022 at 01:05, Chris Angelico  wrote:

> On Tue, Jan 11, 2022 at 10:26 AM Marco Sulla
>  wrote:
> >
> > On Wed, 5 Jan 2022 at 23:02, Chris Angelico  wrote:
> > >
> > > On Thu, Jan 6, 2022 at 8:01 AM Marco Sulla <
> marco.sulla.pyt...@gmail.com> wrote:
> > > >
> > > > On Wed, 5 Jan 2022 at 14:16, Chris Angelico 
> wrote:
> > > > > That's an entirely invisible optimization, but it's more than just
> > > > > "frozenset is faster than set". It's that a frozenset or tuple can
> be
> > > > > stored as a function's constants, which is a massive difference.
> > > >
> > > > Can you explain this?
> > >
> > > Play around with dis.dis and timeit.
> >
> > ? I don't understand. You're talking about function constants. What
> > are they? I can't dig deep into something if I can't know what it is.
> > Maybe are you talking about function default values for parameters?
>
> No, I'm talking about constants. Every function has them.
>
> > Of course. You can use a proxy and slow down almost everything much
> > more. Or you can simply create a version of the mutable object with
> > fewer methods, as more or less frozenset is. I checked the
> > implementation, no fast iteration is implemented. I do not understand
> > why in `for x in {1, 2, 3}` the set is substituted by a frozenset.
>
> Constants. Like I said, play around with dis.dis, and explore what's
> already happening. A set can't be a constant, a frozenset can be.
> Constants are way faster than building from scratch.
>
> Explore. Play around. I'm not going to try to explain everything in detail.
>
> If you're delving into the details of the C implementation of the
> dictionary, I would have expected you'd already be familiar with the
> way that functions behave.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why operations between dict views return a set and not a frozenset?

2022-01-11 Thread Chris Angelico
On Wed, Jan 12, 2022 at 5:49 AM Marco Sulla
 wrote:
>
> Ok... so I suppose, since you're inviting me to use dis and look at the 
> bytecode, that are you talking about constants in assembly, so const in C? 
> Sorry for the confusion, I'm not so skilled in C and I know nearly nothing 
> about assembly. Furthermore I never look at the bytecode of any language 
> before, so I simply didn't understand you.
>

No, I'm talking about constants in Python.

> I think this is what you mean:
>
> >>> dis.dis("for _ in {1, 2}: pass")
>   1   0 SETUP_LOOP  12 (to 14)
>   2 LOAD_CONST   3 (frozenset({1, 2}))

This is a constant.

>   4 GET_ITER
> >>6 FOR_ITER 4 (to 12)
>   8 STORE_NAME   0 (_)
>  10 JUMP_ABSOLUTE6
> >>   12 POP_BLOCK
> >>   14 LOAD_CONST   2 (None)

This is a constant.

>  16 RETURN_VALUE
> >>> a = {1, 2}
> >>> dis.dis("for _ in a: pass")
>   1   0 SETUP_LOOP  12 (to 14)
>   2 LOAD_NAME0 (a)
>   4 GET_ITER
> >>6 FOR_ITER 4 (to 12)
>   8 STORE_NAME   1 (_)
>  10 JUMP_ABSOLUTE6
> >>   12 POP_BLOCK
> >>   14 LOAD_CONST   0 (None)

This is a constant.

>  16 RETURN_VALUE
>

Try the same thing with other code and see whether you can see a
difference. In other words, *play around with dis.dis*.

If you're trying to hack on the internals of the CPython dictionary
implementation and do not understand how Python bytecode is executed,
you are doomed to make many MANY errors of judgment about performance.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A Newspaper for Python Mailing Lists

2022-01-11 Thread Abdur-Rahmaan Janhangeer
Added RSS:

2.0 unless later versions have some advantages:

https://pyherald.com/rss.xml

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius

>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A Newspaper for Python Mailing Lists

2022-01-11 Thread Paul Bryan
Subscribed. 🙂️

On Wed, 2022-01-12 at 00:35 +0400, Abdur-Rahmaan Janhangeer wrote:
> Added RSS:
> 
> 2.0 unless later versions have some advantages:
> 
> https://pyherald.com/rss.xml
> 
> Kind Regards,
> 
> Abdur-Rahmaan Janhangeer
> about | blog 
> github
> Mauritius
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A Newspaper for Python Mailing Lists

2022-01-11 Thread Peter J. Holzer
On 2022-01-11 12:38:44 -0800, Paul Bryan wrote:
> Subscribed. 🙂️

Same.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why operations between dict views return a set and not a frozenset?

2022-01-11 Thread Peter J. Holzer
On 2022-01-11 19:49:20 +0100, Marco Sulla wrote:
> I think this is what you mean:
> 
> >>> dis.dis("for _ in {1, 2}: pass")
>   1   0 SETUP_LOOP  12 (to 14)
>   2 LOAD_CONST   3 (frozenset({1, 2}))
>   4 GET_ITER
> >>6 FOR_ITER 4 (to 12)
>   8 STORE_NAME   0 (_)
>  10 JUMP_ABSOLUTE6
> >>   12 POP_BLOCK
> >>   14 LOAD_CONST   2 (None)
>  16 RETURN_VALUE
> >>> a = {1, 2}
> >>> dis.dis("for _ in a: pass")
>   1   0 SETUP_LOOP  12 (to 14)
>   2 LOAD_NAME0 (a)
>   4 GET_ITER
> >>6 FOR_ITER 4 (to 12)
>   8 STORE_NAME   1 (_)
>  10 JUMP_ABSOLUTE6
> >>   12 POP_BLOCK
> >>   14 LOAD_CONST   0 (None)
>  16 RETURN_VALUE

I think you have omitted the part that Chris was hinting at.

>>> dis.dis("a = {1, 2};\nfor _ in a: pass")
  1   0 LOAD_CONST   0 (1)
  2 LOAD_CONST   1 (2)
  4 BUILD_SET2
  6 STORE_NAME   0 (a)

  2   8 LOAD_NAME0 (a)
 10 GET_ITER
>>   12 FOR_ITER 4 (to 18)
 14 STORE_NAME   1 (_)
 16 JUMP_ABSOLUTE   12
>>   18 LOAD_CONST   2 (None)
 20 RETURN_VALUE

Now compare

  2 LOAD_CONST   3 (frozenset({1, 2}))

with

  1   0 LOAD_CONST   0 (1)
  2 LOAD_CONST   1 (2)
  4 BUILD_SET2

and you see the difference between using a frozenset as a constant and
building a set at runtime.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


sharing data across Examples docstrings

2022-01-11 Thread Sebastian Luque
Hello,

I am searching for a mechanism for sharing data across Examples sections
in docstrings within a class.  For instance:

class Foo:

def foo(self):
"""Method foo title

The example generating data below may be much more laborious.

Examples

>>> x = list("abc")  # may be very long and tedious to generate

"""
pass

def bar(self):
"""Method bar title

Examples

>>> # do something else with x from foo Example

"""
pass


Thanks,
-- 
Seb
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sharing data across Examples docstrings

2022-01-11 Thread Chris Angelico
On Wed, Jan 12, 2022 at 9:11 AM Sebastian Luque  wrote:
>
> Hello,
>
> I am searching for a mechanism for sharing data across Examples sections
> in docstrings within a class.  For instance:

This seems like trying to cram too much information into the
docstring, but oh well... do what you will.

I'd recommend a decorator. The easiest way would probably be to have a
placeholder of some sort in the actual docstring, and in the
decorator, you replace __doc__ with the modified form.

To do what you're asking for, your decorator would either need to go
through every method in the class and mutate its docstring (in which
case you'd decorate the class), or mutate the docstring of exactly one
function (in which case you'd decorate that method).

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sharing data across Examples docstrings

2022-01-11 Thread Cameron Simpson
On 11Jan2022 16:09, Sebastian Luque  wrote:
>I am searching for a mechanism for sharing data across Examples 
>sections
>in docstrings within a class.  For instance:
>
>class Foo:
>
>def foo(self):
>"""Method foo title
>
>The example generating data below may be much more laborious.
>
>Examples
>
>>>> x = list("abc")  # may be very long and tedious to generate
>
>"""
>pass
>
>def bar(self):
>"""Method bar title
>
>Examples
>
>>>> # do something else with x from foo Example
>
>"""
>pass

Personally I'd be inclined to put long identical examples in the class 
docstring instead of the method, but that may not be appropriate.

I've got an @fmtdoc decorator I use mostly for embedding "constants" in 
docstrings, in my cs.deco module: https://pypi.org/project/cs.deco/, 
thus:

from cs.deco import fmtdoc

It turns your docstring into a formatted string. You could embed a 
repeated example that way:

EXAMPLE = r'''
long example here
'''


@fmtdoc
def foo(...):
''' Blah blah.

Example:
{EXAMPLE}
'''

Note - @fmtdoc is only suitable for limited things - use with 
discretion.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sharing data across Examples docstrings

2022-01-11 Thread Sebastian Luque
On Wed, 12 Jan 2022 09:28:16 +1100,
Cameron Simpson  wrote:

[...]

> Personally I'd be inclined to put long identical examples in the class
> docstring instead of the method, but that may not be appropriate.

Good point, and perhaps it's best to put a comprehensive example in the
class docstring, rather than scatter it across the methods' docstrings.
The situation is one in which the methods are typically (but not always)
intended to be used as part of a pipeline of operations; e.g. Foo.foo()
would almost always be used before Foo.bar().

Thanks,
-- 
Seb
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Script profiling details

2022-01-11 Thread Joseph L. Casale
> You might try `py-spy`.

That worked well, I started trying to get more data from the profile
output with the stats module but didn't quite get there. 

Thank you everyone,
jlc
-- 
https://mail.python.org/mailman/listinfo/python-list