[issue46767] [Doc] sqlite3 Cursor.execute() return value is unspecified

2022-02-16 Thread Pierre Thierry


New submission from Pierre Thierry :

In the documentation of the sqlite3 module, the return value for 
Connection.execute() is told to be the Cursor that was implicitly created, but 
nothing is said about the return value/type when using Cursor.execute().

--
components: Library (Lib)
messages: 413327
nosy: kephas
priority: normal
severity: normal
status: open
title: [Doc] sqlite3 Cursor.execute() return value is unspecified
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 
<https://bugs.python.org/issue46767>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31753] Unnecessary closure in ast.literal_eval

2021-05-12 Thread Thierry Excoffier


Thierry Excoffier  added the comment:

I assumed that the standard python library does not create circular references, 
so the GC can be disabled safely in real time application.

Each time 'literal_eval' is called, it creates a circular reference and so a 
memory leak.

The source of this leak is the recursive closure.

--
nosy: +thierry.excoffier

___
Python tracker 
<https://bugs.python.org/issue31753>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38894] Path.glob() sometimes misses files that match

2019-11-22 Thread Thierry Parmentelat


Thierry Parmentelat  added the comment:

to clarify, when I said 'lambda user' I mean regular, non-root user that has no 
permission to read in /root

--

___
Python tracker 
<https://bugs.python.org/issue38894>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38894] Path.glob() sometimes misses files that match

2019-11-22 Thread Thierry Parmentelat


New submission from Thierry Parmentelat :

I have observed this on a linux box running fedora29

$ python3 --version
Python 3.7.5
$ uname -a
Linux faraday.inria.fr 5.3.11-100.fc29.x86_64 #1 SMP Tue Nov 12 20:41:25 UTC 
2019 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/fedora-release
Fedora release 29 (Twenty Nine)

 steps to reproduce:

This assumes that /root is not readable by lambda users

- as root:

# mkdir /tmp/foo
# cd /tmp/foo
# touch a b d e
# ln -s /root/anywhere c

# ls -l
total 0
-rw-r--r-- 1 root root  0 Nov 22 14:51 a
-rw-r--r-- 1 root root  0 Nov 22 14:51 b
lrwxrwxrwx 1 root root 14 Nov 22 14:53 c -> /root/anywhere
-rw-r--r-- 1 root root  0 Nov 22 14:51 d
-rw-r--r-- 1 root root  0 Nov 22 14:51 e


- as a lambda user:

we can see all files

$ ls -l /tmp/foo
total 0
-rw-r--r-- 1 root root  0 Nov 22 14:51 a
-rw-r--r-- 1 root root  0 Nov 22 14:51 b
lrwxrwxrwx 1 root root 14 Nov 22 14:53 c -> /root/anywhere
-rw-r--r-- 1 root root  0 Nov 22 14:51 d
-rw-r--r-- 1 root root  0 Nov 22 14:51 e

and with glob.glob() too

In [1]: import glob

In [2]: for filename in glob.glob("/tmp/foo/*"):
   ...: print(filename)
   ...:
/tmp/foo/c
/tmp/foo/e
/tmp/foo/d
/tmp/foo/b
/tmp/foo/a


BUT Path.glob() is not working as expected

In [3]: from pathlib import Path

In [4]: for filename in Path("/tmp/foo/").glob("*"):
   ...: print(filename)
   ...:



- If I now I go back as root and remove the problematic file in /tmp/foo

# rm /tmp/foo/c


- and try again as a lambda user

In [5]: for filename in Path("/tmp/foo/").glob("*"):
   ...: print(filename)
   ...:
/tmp/foo/e
/tmp/foo/d
/tmp/foo/b
/tmp/foo/a


 discussion

in my case in a real application I was getting *some* files - not an empty list 
like here. 

I ran strace on that real application
it's fairly clear from that output that the odd symlink is causing the scanning 
of all files to break instead of continuing (see snip below)
of course the order in which files are read from the disk will impact the 
behaviour, that's why I created the symlink last, that might need to be changed 
to reproduce successfully in another setup



 strace extract


getdents64(3, /* 189 entries */, 32768) = 8640
getdents64(3, /* 0 entries */, 32768)   = 0
close(3)= 0
stat("/var/lib/rhubarbe-images/centos.ndz", {st_mode=S_IFREG|0644, 
st_size=1002438656, ...}) = 0
stat("/var/lib/rhubarbe-images/oai-enb.ndz", {st_mode=S_IFREG|0644, 
st_size=2840592384, ...}) = 0

stat("/var/lib/rhubarbe-images/ubuntu-floodlight.ndz", {st_mode=S_IFREG|0644, 
st_size=2559574016, ...}) = 0
stat("/var/lib/rhubarbe-images/ndnsim.ndz", {st_mode=S_IFREG|0644, 
st_size=4153409536, ...}) = 0

==> that's the line about the broken symlink in my real app
stat("/var/lib/rhubarbe-images/push-to-preplab.sh", 0x7ffd3ac4a140) = -1 EACCES 
(Permission denied)
==> and here it stops scanning files while there are still quite a lot to be 
dealt with

write(1, "/var/lib/rhubarbe-images/fedora-"..., 
82/var/lib/rhubarbe-images/fedora-31.ndz
/var/lib/rhubarbe-images/fedora-31-ssh.ndz
) = 82
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x7fc583705e70}, {sa_handler=0x7fc583936f10, sa_mask=[], \
sa_flags=SA_RESTORER, sa_restorer=0x7fc583705e70}, 8) = 0
sigaltstack(NULL, {ss_sp=0x560a7dac3330, ss_flags=0, ss_size=16384}) = 0
sigaltstack({ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=0}, NULL) = 0
exit_group(0)   = ?
+++ exited with 0 +++

--
messages: 357284
nosy: thierry.parmentelat
priority: normal
severity: normal
status: open
title: Path.glob() sometimes misses files that match
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue38894>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35237] Allow Path instances in sys.path ?

2018-11-13 Thread Thierry Parmentelat


New submission from Thierry Parmentelat :

Hi; this is my first entry in this repo

I ran today into a rather frustrating experience, that I'd to avoid it for 
others as far as possible

In a nutshell I had a sphinx stub that read:

import sys
sys.path.append("..")

import mymodule


and because I was switching from os.path to pathlib.Path, I rather stupidly 
changed it into this

import sys
sys.path.append(Path("..").resolve())

import mymodule


---
When trying to run this new code, the message I got was ModuleNotFoundError
So I tried to troubleshoot the situation, and inserted something like

for x in sys.path:
print(x)

and so the proper path showed up, and that's the point where I started banging 
my head against the screen
Granted, I was doing too many changes at the same time, and it's entirely my 
fault if it took me ages really to figure it out eventually.

---
Still, my proposal would be to

*) either accept Path instances in sys.path, or
*) somehow send a warning message stating that the Path instance is totally 
ignored; at least, I haven't found the corresponding piece of code yet, but as 
far as I am concerned it's truly as if this Path instance had been completely 
ignored when executing the import statement
*) or at the very least add a mention about this possible issue in the import 
documentation


I understand it was a stupid mistake, but with Path becoming THE right way to 
deal with paths, I think it is safe to predict that I won't be the only one 
making it.

As I said I am a complete newbie with cpython's codebase and devel practices, 
so I'll warmly welcome all inputs on this one.

thanks

--
components: Library (Lib)
messages: 329864
nosy: thierry.parmentelat
priority: normal
severity: normal
status: open
title: Allow Path instances in sys.path ?
type: enhancement
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue35237>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



match point

2015-12-22 Thread Thierry

Hi,

Reading the docs about regular expressions, I am under the impression
that calling
re.match(pattern, string)
is exactly the same as
re.search(r'\A'+pattern, string)

Same for fullmatch, that amounts to
re.search(r'\A'+pattern+r'\Z', string)

The docs devote a chapter to "6.2.5.3. search() vs. match()", but they
only discuss how match() is different from search() with '^', completely
eluding the case of search() with r'\A'.

At first I thought those functions could have been introduced at a time
when r'\A' and r'\Z' did not exist, but then I noticed that re.fullmatch
is a recent addition (python 3.4)

Surely the python devs are not cluttering the interface of the re module
with useless functions for no reason, so what am I missing?

Maybe re.match has an implementation that makes it more efficient? But
then why would I ever use r'\A', since that anchor makes a pattern match
in only a single position, and is therefore useless in functions like
re.findall, re.finditer or re.split?

Thanks,

Thierry


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


Re: match point

2015-12-22 Thread Thierry Closen

I found the story behind the creation of re.fullmatch(). 

I had no luck before because I was searching under "www.python.org/dev",
while in reality it sprang out of a bug report:
https://bugs.python.org/issue16203

In summary, there were repeated bugs where during maintenance of code
the $ symbol disappeared from patterns, hence the decision to create a
function that anchors the pattern to the end of the string independently
of the presence of that symbol.

I am perplexed by what I discovered, as I would never have thought that
such prominent functions can be created to scratch such a minor itch:
The creation of fullmatch() might address this very specific issue, but 
I would tend to think that if really certain symbols disappear from
patterns inside a code base, this should be seen as the sign of more
profound problems in the code maintenance processes.

Anyway, the discussion around that bug inspired me another argument that
is more satisfying:

When I was saying that
re.fullmatch(pattern, string)
is exactly the same as
re.search(r'\A'+pattern+r'\Z', string)
I was wrong.

For example if pattern starts with an inline flag like (?i), we cannot
simply stick \A in front of it.

Other example, consider pattern is 'a|b'. We end up with:
re.search(r'\Aa|b\Z', string)
which is not what we want.

To avoid that problem we need to add parentheses:
re.search(r'\A('+pattern+r')\Z', string)
But now we created a group, and if the pattern already contained groups
and backreferences we may just have broken it.

So we need to use a non-capturing group:
re.search(r'\A(?:'+pattern+r')\Z', string)
...and now I think we can say we are at a level of complexity where we
cannot reasonably expect the average user to always remember to write
exactly this, so it makes sense to add an easy-to-use fullmatch function
to the re namespace.

It may not be the real historical reason behind re.fullmatch, but
personally I will stick with that one :)

Cheers,

Thierry


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


Re: Evaluation order

2015-07-10 Thread Thierry Chappuis
Hi,

No, the value of t is a reference to tje list. So first, (1) the value of
the reference t is recovered, (2) the parenthesis is evaluated, (...) the
whole expression is evaluated.

To evaluate (2), the .sort() call is executed in place with the side effect
of sorting the content of t. t.sort() returns None. When the whole
expression is evaluated, the sorted list will be displayed, as expected.

Kind regards

2015-07-10 14:04 GMT+02:00 candide c.cand...@laposte.net:

 Le vendredi 10 juillet 2015 04:02:56 UTC+2, Chris Angelico a écrit :



  I'm not sure what contradiction you're referring to, here. The
  evaluation that you're pointing out says, as Terry showed via the
  disassembly, that Python's first action is to look up the name 't' and
  grab a reference to whatever object it points to.


 But in order to perform an operation, the interpreter has to evaluate the
 operands and evaluating is not grabbing a reference to.

  The execution of
  t.sort() has to happen before the multiplication, because of the
  parentheses.
 



 Official docs explains what evaluation is :

 When the name is bound to an object, evaluation of the atom yields that
 object.

 So, since the Python interpreter is performing evaluation from left to
 right, the first operand of the expression :

 t*(1+int(bool(t.sort(

 evaluates to [2020, 42, 2015]. Next, the second operatand evaluates to the
 integer 1. So I was expecting the result to be a shallow copy of the first
 list [2020, 42, 2015] (the value of t before side effect produced by the
 sort method). On the contrary, the final result takes into in account the
 side effect and it is as if the first operand has been evaluated twice
 before execution of the multiplication operation.




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

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


Re: Evaluation order

2015-07-10 Thread Thierry Chappuis
Hi,

No, the value of t is a reference to tje list. So first, (1) the value of
the reference t is recovered, (2) the parenthesis is evaluated, (...) the
whole expression is evaluated.

To evaluate (2), the .sort() call is executed in place with the side effect
of sorting the content of t. t.sort() returns None. When the whole
expression is evaluated, the sorted list will be displayed, as expected.

Kind regards

2015-07-10 14:04 GMT+02:00 candide c.cand...@laposte.net:

 Le vendredi 10 juillet 2015 04:02:56 UTC+2, Chris Angelico a écrit :



  I'm not sure what contradiction you're referring to, here. The
  evaluation that you're pointing out says, as Terry showed via the
  disassembly, that Python's first action is to look up the name 't' and
  grab a reference to whatever object it points to.


 But in order to perform an operation, the interpreter has to evaluate the
 operands and evaluating is not grabbing a reference to.

  The execution of
  t.sort() has to happen before the multiplication, because of the
  parentheses.
 



 Official docs explains what evaluation is :

 When the name is bound to an object, evaluation of the atom yields that
 object.

 So, since the Python interpreter is performing evaluation from left to
 right, the first operand of the expression :

 t*(1+int(bool(t.sort(

 evaluates to [2020, 42, 2015]. Next, the second operatand evaluates to the
 integer 1. So I was expecting the result to be a shallow copy of the first
 list [2020, 42, 2015] (the value of t before side effect produced by the
 sort method). On the contrary, the final result takes into in account the
 side effect and it is as if the first operand has been evaluated twice
 before execution of the multiplication operation.




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

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


Re: Evaluation order

2015-07-10 Thread Thierry Chappuis
Anyway, if we enter this kind of discussion, it is a reliable indication that
the code smells. There is a pythonic way to express the same task:

 t.sort()
 t

kind regards

Thierry

On ven., juil. 10, 2015 at 2:28 PM, Terry Reedy  tjre...@udel.edu 
[tjre...@udel.edu]  wrote:
On 7/10/2015 8:04 AM, candide wrote:
 Le vendredi 10 juillet 2015 04:02:56 UTC+2, Chris Angelico a écrit :
 I'm not sure what contradiction you're referring to, here. The
 evaluation that you're pointing out says, as Terry showed via the
 disassembly, that Python's first action is to look up the name 't' and
 grab a reference to whatever object it points to.

 But in order to perform an operation, the interpreter has to evaluate
 the operands and evaluating is not grabbing a reference to.

In the CPython, evaluating a name is implemented as getting the
reference corresponding to the name.

 The execution of
 t.sort() has to happen before the multiplication, because of the
 parentheses.

 Official docs explains what evaluation is :

 When the name is bound to an object, evaluation of the atom yields that
object.

Conceptually, that is exactly right. How that is implemented on a
computer in CPython is to load the address on the top of the virtual
machine stack.

 So, since the Python interpreter is performing evaluation from left to right,
 the first operand of the expression :

 t*(1+int(bool(t.sort(

 evaluates to [2020, 42, 2015].

't' evaluates to the ***mutable*** list that 't' is bound to.

 Next, the second operatand evaluates to the integer 1.

And in the process of that evaluation, the list is sorted.


--
Terry Jan Reedy


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


Re: Creating .exe file in Python

2015-06-15 Thread Thierry Chappuis

Hi,

The question is why to you want to create an exe from your python project?

Setuptools is capable to create small .exe launchers in the Scripts dir of 
your

python install. These launchers start a python script and use the python
interpreter registered on your platform. That's pretty light and that's my
prefered solution.

If installing the Python interpreter is an issue for the end user, we can 
make
the installer do it for him. Installer programs like Inno Setup let you do 
it

quite easily.

Kind regards

Thierry


On lun., juin 15, 2015 at 4:10 PM,  subhabrata.bane...@gmail.com 
[subhabrata.bane...@gmail.com]  wrote:
On Monday, June 15, 2015 at 5:12:24 PM UTC+5:30, subhabrat...@gmail.com 
wrote:

 Dear Group,

 I am trying to learn how to create .exe file for Python. I tried to work
around
 http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program 
went

nice.
 But if I try to make exe for larger programs with methods and classes I 
am

getting error.

 If any one of the esteemed members may kindly suggest how to work out.
 I am using Python2.7+ on Windows 7 Professional.

 Regards,
 Subhabrata Banerjee.

I am also experimenting around Pyinstaller, cx_Freeze and Inno Studio. But 
not

finding ample examples and manuals.
Regards,
Subhabrata.
--
https://mail.python.org/mailman/listinfo/python-list-- 
https://mail.python.org/mailman/listinfo/python-list


problem while using os.walk with utf-8 characters

2015-05-12 Thread Thierry GAYET
Hi,

I'm using the os.walk function for parsing files from an external mass-storage 
such as usbkey.

When i try the following code, i have an error:

from __future__ import unicode_literals

import sys
reload(sys)
sys.setdefaultencoding('utf_8')

for dirname, dirnames, filenames in os.walk(os.path.join(massStorage, path)):
or
for dirname, dirnames, filenames in os.walk(unicode(path, 'utf-8')

And my error is:
'ascii' codec can't encode character u'\xe9' in position 58: ordinal not in 
range(128)

The wrong character is an accent (french one).

It doesn't work when i start it but after a reboot i need to restart the code 
to make it work properly without any error.

Any idea about the first fact related to the usf-8 support with external files 
that can be encoded with any charset (latin-1, utf-8, ... )

Secondly, why it can works after a restart of the python script ?

BR

Thierry GAYET



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


[issue19056] Windows 7, script exec not working without explicit cal of python.exe

2013-09-21 Thread Thierry Seunevel

Thierry Seunevel added the comment:

Many thanks for your answers.
printing the sys.path gave me this output (parsed with newlines)
'', 'D:\\soft\\python\\lib', 
'D:\\Thierry\\python\\d\\thierry\\python',  mispelled
'C:\\Windows\\system32\\python27.zip',
'd:\\soft\\python\\DLLs', 
'd:\\soft\\python\\lib\\plat-win', 
'd:\\soft\\python\\lib\\lib-tk', 
'd:\\soft\\python', 
'd:\\soft\\python\\lib\\site-packages'

I corrected the PATH and PYTHONPATH environment variables and now sys.path is 
'', 'd:\\thierry\\python', 
'C:\\Windows\\system32\\python27.zip', 
'd:\\soft\\python\\DLLs', 
'd:\\soft\\python\\lib', 
'd:\\soft\\python\\lib\\plat-win', 
'd:\\soft\\python\\lib\\lib-tk', 
'd:\\soft\\python', 
'd:\\soft\\python\\lib\\site-packages'

And it works !

--
resolution:  - fixed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19056
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19056] Windows 7, script exec not working without explicit cal of python.exe

2013-09-20 Thread Thierry Seunevel

New submission from Thierry Seunevel:

Executing a script from the command prompt works if Python.exe called 
explicitly, doesn't work if script name only.
Example :
python.exe script.py is ok
script.py gives the following :
Traceback (most recent call last):
  File D:\soft\python\lib\site.py, line 548, in module
main()
  File D:\soft\python\lib\site.py, line 530, in main
known_paths = addusersitepackages(known_paths)
  File D:\soft\python\lib\site.py, line 266, in addusersitepackages
user_site = getusersitepackages()
  File D:\soft\python\lib\site.py, line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
  File D:\soft\python\lib\site.py, line 231, in getuserbase
USER_BASE = get_config_var('userbase')
  File D:\soft\python\lib\sysconfig.py, line 516, in get_config_var
return get_config_vars().get(name)
  File D:\soft\python\lib\sysconfig.py, line 449, in get_config_vars
import re
  File D:\soft\python\lib\re.py, line 105, in module
import sre_compile
  File D:\soft\python\lib\sre_compile.py, line 14, in module
import sre_parse
  File D:\soft\python\lib\sre_parse.py, line 17, in module
from sre_constants import *
  File D:\soft\python\lib\sre_constants.py, line 18, in module
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Association of py extension to the python.exe is ok, Path contains the path for 
python directory (and also to \lib) and is the first dir in path.
Why is there a difference between the 2 invocations as they are calling the 
same exe?

--
components: Windows
messages: 198136
nosy: tsunwell
priority: normal
severity: normal
status: open
title: Windows 7, script exec not working without explicit cal of python.exe
type: behavior
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19056
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13486] msvc9compiler.py doesn't properly generate manifest files.

2012-03-25 Thread Thierry Bastian

Thierry Bastian thier...@filewave.com added the comment:

I have the same issue. To be honest it is because I'm using MSVC2010. I know it 
is not a supported platform but the patch to fix the problem is really just the 
following (and it is compatible with MSVC2008):

--- Lib/distutils/msvc9compiler.py.orig Mon Jun 21 17:27:46 2010
+++ Lib/distutils/msvc9compiler.py  Mon Mar 12 13:23:56 2012
@@ -645,6 +645,7 @@
 build_temp,
 os.path.basename(output_filename) + .manifest)
 ld_args.append('/MANIFESTFILE:' + temp_manifest)
+ld_args.append('/MANIFEST')

 if extra_preargs:
 ld_args[:0] = extra_preargs


On a side-note I wrote a CMakeLists.txt for python for windows. I have to say 
it was pretty easy even if I'm not building everything (I left out tcl/tk and 
bsddb). I would hope python in the future could use a more flexible way if 
being built. For reference, I copy here the cmakelists.txt.

--
nosy: +Thierry.Bastian
Added file: http://bugs.python.org/file25022/python-cmakelists.txt

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13486
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: sys.stdout, urllib and unicode... I don't understand.

2008-11-12 Thread Thierry
Thank you to both of you (Marc and Tino).

I feel a bit stupid right now, because as both of you said, encoding
my source string to utf-8 do not produce an exception when I pass it
to urllib.quote() and is what it should be.
I was certain that this created an error sooner, and id not tried it
again.
The result of 2 days making random changes and hoping it works. I
know, reflection should have primed. My bad...

The same goes for my treatment in the iteration over the request
result.
I now have an
 line=line.encode('utf-8')
and no errors (as long as I don't try to print this to stdout, which I
understand).
So, I'm now really getting back an unicode string that I can handle as
such.

I really am confused about what I was trying to do...
I cannot understand what I did that caused those errors, because the
state the script is now correspond to what I have in mind originally.

BTW: ``line.strip()`` removes all whitespace at both ends *including
newlines*, so there are no '\n' to replace anymore.
Not exactly...
It's that I receive a string, with 2 literal characters in it: \ and
n.
What I (want to) do here is that I replace those 2 characters with 1
chr(10).

And functions in the
`string` module that are also implemented as method on `str` or `unicode`
are deprecated.
I actually had read that, but not modified my code.
Thank to point it out

Anyway, thanks again to both of you.
I'm quite happy to see it working the way I intended.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sys.stdout, urllib and unicode... I don't understand.

2008-11-12 Thread Thierry
 Are you sure that Python wasn't just printing out \n because you'd
 asked it to show you the repr() of a string containing newlines?

Yes, I am sure. Because I dumped the ord() values to check them.
But again, I'm stumped on how complicated I have made this.
I should not try to code anymore at 2am.
--
http://mail.python.org/mailman/listinfo/python-list


sys.stdout, urllib and unicode... I don't understand.

2008-11-11 Thread Thierry
Hello fellow pythonists,

I'm a relatively new python developer, and I try to adjust my
understanding about how things works to python, but I have hit a
block, that I cannot understand.
I needed to output unicode datas back from a web service, and could
not get back unicode/multibyte text before applying an hack that I
don't understand (thank you google)

I have realized an wxPython simple application, that takes the input
of a user, send it to a web service, and get back translations in
several languages.
The service itself is fully UTF-8.

The source string is first encoded to latin1 after a passage into
unicode.normalize(), as urllib.quote() cannot work on unicode
srcText=unicodedata.normalize('NFKD',srcText).encode('latin1','ignore')

After that, an urllib request is sent with this encoded string to the
web service
con=urllib2.Request(self.url, headers={'User-Agent':'Mozilla/5.0 (X11; U; 
Linux i686) Gecko/20071127 Firefox/2.0.0.11'}, 
origin_req_host='http://translate.google.com')

req=urllib2.urlopen(con)

First problem, how to determine the encoding of the return ?
If I inspect a request from firefox, I see that the server return
header specify UTF-8
But if I use this code:
ret=U''
for line in req:
  ret=ret+string.replace(line.strip(),'\n',chr(10))
I end up with an UnicodeDecodeError. I tried various line.decode(),
line.normalize and such, but could not make this error disapear.
I, until now, avoided that problem as the service always seems to
return 1 line, but I am wondering.

Second problem, if I try an
print line
into the loop, I too get the same error. I though that unicode() would
force python to consider the given text as unicode, not to try to
convert it to unicode.
Here again, trying several normalize/decode combination did not helped
at all.

Then, looking for help through google, I have found this post:
http://mail.python.org/pipermail/python-list/2007-October/462977.html
and I gave it a try. What I did, though, was not to override
sys.stdout, but to declare a new writer stream as a property of my
main class:
self.out=OutStreamEncoder(sys.stdout, 'utf-8')

But what is strange, is that since I did that, even without using this
self.out writer, the unicode translation are working as I was
expecting them to. Except on the for loop, where a concatenation still
triggers the UnicodeDecodeErro exception.
I know the explicit is better than implicit python motto, and I
really like it.
But here, I don't understand what is going on.

Does the fact that defining that writer object does a initialization
of the standard sys.stdout object ?
Does it is related to an internal usage of it, maybe in urllib ?
I tried to find more on the subject, but felt short.
Can someone explain to me what is happening ?
The full script source can be found at 
http://www.webalis.com/translator/translator.pyw
--
http://mail.python.org/mailman/listinfo/python-list


Converting a time string to a more readable date, time

2008-10-27 Thread Thierry Lam
I have a python time string which has the following value:

1225137896

The above corresponds to 2008/10/27 16:04:56

What can I use to convert 1225137896 to a more readable date, time
format?
--
http://mail.python.org/mailman/listinfo/python-list


Re: what is meaning of @ in pyhon program.

2008-06-28 Thread Thierry
 ie:
 @if os.exists(foo):
    etc
    etc

 and

 @for blah:
    etc
    etc


This sounds more like PHP code, where a @ prefixing a function means
that even if there are errors or warnings, you don't want to see them.
--
http://mail.python.org/mailman/listinfo/python-list


new to python, looking for streams clues

2008-06-04 Thread Thierry
Hello peoples,

As I said, I'm new to python, and particularly to XML generation in
python.
Using the 4suite XML package, I have been able to produce XML, but
only directly to STDOUT.

Refering to the 4suite markupWriter refrence, the class needs a stream
to output the generated XML, and if none is specified, it's the STDOUT
stream that is used.

What I would like, would be to store the generated XML into a python
object which implement the stream interface to be able to transform it
via XSLT if needed (it's in a web based project).

But, I've read the python doc for the last 12 hours without finding
anything about an existing object that implements that interface.
Am I missing something, or should I really create that object myself ?

I mean, I just need something that I can write into and read
thereafter.
It should already exists, no ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: new to python, looking for streams clues

2008-06-04 Thread Thierry
On Jun 4, 1:50 pm, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:
 Thierry a écrit :



  Hello peoples,

  As I said, I'm new to python, and particularly to XML generation in
  python.
  Using the 4suite XML package, I have been able to produce XML, but
  only directly to STDOUT.

  Refering to the 4suite markupWriter refrence, the class needs a stream
  to output the generated XML, and if none is specified, it's the STDOUT
  stream that is used.

  What I would like, would be to store the generated XML into a python
  object which implement the stream interface to be able to transform it
  via XSLT if needed (it's in a web based project).

  But, I've read the python doc for the last 12 hours without finding
  anything about an existing object that implements that interface.
  Am I missing something, or should I really create that object myself ?

  I mean, I just need something that I can write into and read
  thereafter.
  It should already exists, no ?

 It does, it's named StringIO (or cStringIO for the faster C
 implementation), and it's part of the standard lib. AFAICT, it should
 fit your needs.

Thanks everyone.

I had seen it, but understood that you had to give it an already
existing string to operate on that one.
I feel a bit stupid. Time to get back to those lost sleep hours, I
presume.

But again, thanks everyone.
--
http://mail.python.org/mailman/listinfo/python-list


Re: writing Python in Emacs

2008-01-19 Thread Thierry Volpiatto

I add just a note about ipython:
if you use a version  0.6.15 may be you will have a bad output
on error like:

==  :
instead of:
if __name__ == __main__:

all the characters are missing.

To avoid that, run in ipython:
%upgrade -nolegacy

uncomment in ~/.ipython/ipy_user_config.py:
import ipy_defaults

restart emacs and try a .py with some syntax errors.
It should be ok now.

Terry Jones [EMAIL PROTECTED] writes:

 Richard == Richard Szopa [EMAIL PROTECTED] writes:

 Richard I am a devoted Emacs user and I write a lot in Python.

 Me too.

 Richard I need the following features:

 Richard 1) Tab completion, ideally Slime like. That is, when there's not
 Richard enough letters to unambiguously complete a symbol, I want it to
 Richard show a buffer (w/o taking the focus) w/ the possible
 Richard completions. In an ideal world, it would be able to complete
 Richard fo.baTAB to foo.bar. I imagine this would require quite tight
 Richard Emacs-Python integration.

 I know this is not what you want, but I use hippie expand (M-/) to cycle
 through possible completions. It's not Python aware, but it is of some use.

 Richard 2) Sending the toplevel definition (class or function) to the Python
 Richard buffer.

 I switched to IPython to have better interaction with a spawned Python.

 To use IPython you need to use the Python mode that is NOT the one from
 (endorsed?) by the FSF. It gives you some completion (at least in the
 *Python* buffer) and you can send pieces of the buffer to the python
 process, via py-send-region (C-c |), py-execute-def-or-class (M-C-x), etc.

 Richard 3) Hints on function/method arguments. IDLE has this done nearly
 Richard right, but the hints are a bit too intrusive for me. I would like to
 Richard see them in the minibuffer.

 I don't have this.

 Richard 4) (optional) I would like to see the definition of a function
 Richard function or class by hitting M-. on its name. (I understand that
 Richard this may be impossible for methods, as Emacs would have to
 Richard automagically infer the type of the object).

 This is just an emacs tag file need. Have you googled for something like
 emacs tags python? The issue of methods might be overcome by just moving
 through tags with the same name. Yes, that requires _you_ to know when
 you've hit the right thing. That's not optimal, but it's better than
 nothing. Ideally you could send the definition to IPython, ask it for the
 class info, and use that to jump to the right tag.

 Richard I have tried a couple of times both python-modes (the one shipped w/
 Richard Python and the one shipped w/ Emacs), pymacs and stuff like that...
 Richard And, as I said, never got it right. But, maybe I just cannot find the
 Richard way to configure it, and some configuration hints will be enough...

 If you have the time, please summarize your findings. The emacs/python
 world has always seemed quite amorphous to me too.

 Terry
 ___
 help-gnu-emacs mailing list
 [EMAIL PROTECTED]
 http://lists.gnu.org/mailman/listinfo/help-gnu-emacs


-- 
A + Thierry
Pub key: http://pgp.mit.edu
-- 
http://mail.python.org/mailman/listinfo/python-list


Extending Python with C API

2007-09-13 Thread Thierry Masson
Hello,

I'm trying to use the C API to extend Python. I've looked at various books
and web sites (including the docs at python.org) and I can't get any of the
samples to work. Below is a very minimalist example that I'm trying to get
working and I was wondering if someone could tell me where I'm going wrong.
It's probably something very obvious to those familiar with this technique.

gtestmodule.c:

#include Python.h

int GetInt(int iVal)
{
return iVal;
}

char* GetString(void)
{
return This is the message;
}

PyObject* gtestmodule_GetInt(PyObject* pSelf, PyObject* pArgs)
{
int x = 0;
if (!PyArg_ParseTuple(pArgs, i, x))
return NULL;
GetInt(x);
return PyBuildValue(i, x);
}

PyObject* gtestmodule_GetString(PyObject* pSelf, PyObject* pArgs)
{
char* szMsg = GetString();
return PyBuildValue(s, szMsg);
}

static PyMethodDef gtestmoduleMethods[] =
{
{GetInt, gtestmodule_GetInt, METH_VARARGS, Description goes here},
{GetString, gtestmodule_GetString, METH_VARARGS, Description goes
here},
{NULL, NULL}
};

setup.py:

from distutils.core import setup, Extension
setup(name = gtestmodule,
  version = 1.0,
  maintainer = thierry masson,
  maintainer_email = [EMAIL PROTECTED],
  description = test module,
  ext_modules = [Extension(gtestmodule,[gtestmodule.c])],
 )

test.py:
--
import gtestmodule
print gtestmodule.GetInt(36);
print gtestmodule.GetString();

The setup script builds the library OK, and I've verified that
gtestmodule.so is getting created. But when I try to run a test script (
test.py, above) that uses the library, I get this error:

Traceback (most recent call last):
  File test.py, line 2, in ?
import gtestmodule
ImportError: ./gtestmodule.so: undefined symbol: PyBuildValue

The OS is Red Hat Enterprise Linux ES release 3 (Taroon Update 8), and the
Python version is 2.2.3 (rather old, I know, but I don't control the server
environment and my sysadmin tells me this is the most recent version of
Python officially supported by Red Hat.

Can anyone see where I'm going wrong?

Thanks!

Thierry
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python with C API

2007-09-13 Thread Thierry Masson
On 9/13/07, Carsten Haese wrote:
Your module C code uses an unknown function by the name of PyBuildValue.
The actual name of the function you mean is Py_BuildValue.

Thank you so much, Carsten. I can't believe I missed that underscore! I'm
posting the working code below in case it ever turns out to be useful for
someone else who is new to the Python C API. (I also added the init
function, which I forgot to include in my original post). I've verified that
this code works on Red Hat Enterprise Linux ES release 3 (Taroon Update 8).

Code for writing a C API Python Extension (cobbled together from so many
online and printed sources that it's hard to know where to start with the
acknowledgements):

File gtestmodule.c:
==
#include Python.h

/* First, a couple of C functions that do the real work */
/* In this test example, real work is perhaps exaggerating a little */
int GetInt(int iVal)
{
// Double the supplied value and pass it back
return iVal * 2;
}

char* GetString(void)
{
return This is the message;
}

/* Now a couple of corresponding wrapper functions so that Python can get
access to them */

/* Python requires this return data type and these arguments */
PyObject* gtestmodule_GetInt(PyObject* pSelf, PyObject* pArgs)
{
int x = 0, iRet = 0;

/* Validate and assign the single integer argument (that's what GetInt()
expects) */
/* The i means just one integer */
/* Two integers would be ii; an integer, a string, a float and a long
would be isdl */
if (!PyArg_ParseTuple(pArgs, i, x))
return NULL;

iRet = GetInt(x);
return Py_BuildValue(i, iRet);
}

PyObject* gtestmodule_GetString(PyObject* pSelf, PyObject* pArgs)
{
char* szMsg = GetString();
return Py_BuildValue(s, szMsg);
}

/* Method table for mapping function names to wrapper functions */
static PyMethodDef gtestmoduleMethods[] =
{
{GetInt, gtestmodule_GetInt, METH_VARARGS, Description goes here},
{GetString, gtestmodule_GetString, METH_VARARGS, Description goes
here},
{NULL, NULL}
};

/* Module initialization function */
initgtestmodule(void)
{
Py_InitModule(gtestmodule, gtestmoduleMethods);
}

File setup.py:
=
# To build and install the module, use: python setup.py install
# Running this will generate a library file (gtestmodule.so on Linux)
#
from distutils.core import setup, Extension
setup(name = gtestmodule,
  version = 1.0,
  maintainer = your name here,
  maintainer_email = [EMAIL PROTECTED],
  description = test module,
  ext_modules = [Extension(gtestmodule,[ gtestmodule.c])],
)

File test.py:

# Simple test routine to run after building the library file
import gtestmodule
print gtestmodule.GetInt(36);
print gtestmodule.GetString();
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Yet Another Software Challenge

2007-05-15 Thread Thierry
On May 14, 3:40 pm, Paul McGuire [EMAIL PROTECTED] wrote:

 In Riddle 2, the global declarations are unnecessary, as you are
 only referencing the globally-defined vars for read.

 Also in Riddle 2, I would replace
 for s in alphabet: indices[s] = alphabet.index(s)
 with
 indices = dict( (s,i) for i,s in enumerate(alphabet) )

 (I see part of your Python Challenge as giving new Pythoners something
 to cut their teeth on, and so this is an opportunity for giving
 examples of good style.)

 I do enjoy these challenges, they are quite addicting. :)

 -- Paul

Hi Paul,

Many thanks for your feedback and your example of good Python style.

Even though the challenge is opened to any language practitioner, I
must confess that I personally prefer Python and that languages like
Python and Ruby are likely to be the most effective to solve the
riddles.

Don't hesitate to report any issue you could find.

Enjoy. Cheers. Thierry

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


Yet Another Software Challenge

2007-05-14 Thread Thierry
For those interested in bprogramming riddles/b, I would like to
announce a new programming challenge I'm just launching at
http://software.challenge.googlepages.com

This challenge is in its early stage and thus set to be continuously
improved.

I would be especially interested in your comments and feedbacks about
this initiative and its relevance.

Enjoy!

Thierry

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


WMI Python, writing remotely and retrieving env variables values

2007-01-12 Thread Thierry Lam
I'm using the WMI library for python and I was able to connect to
another computer on the network with the following line:

c = wmi.WMI(computer=the-network-computer, user=hello,
password=hello)

Is there a way to write information to a file on that computer?

How do I read environment variables, for example SystemDrive?

Thierry

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


Re: HTTPS Login

2006-08-31 Thread Thierry Lam
Instead of using the following:

 req = urllib2.Request(https://web.site.com/default.aspx;, params)
 data = urllib2.urlopen(req)


Try:

data = urllib.urlopen(https://web.site.com/default.aspx;, param)

Thierry

Tom Grove wrote:
 I am trying to login to a secure website and I am having some difficulty
 understanding the process.  Here is what I have with my limited
 knowledge of the subject:

 ##Start Code##
 #!/usr/bin/env
 python



 import
 urllib

 import
 urllib2



 #
 Main

 params =
 urllib.urlencode({

 user :
 username,

 pass :
 password

 })



 req = urllib2.Request(https://web.site.com/default.aspx;,
 params)
 data =
 urllib2.urlopen(req)



 for line in
 data.readlines():

 print line
 ##End Code##

 This just doesn't seem to work.  It just brings me back to a login screen.
 
 If you can lend a hand it would be much appreciated.
 
 -Tom

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


Finding yesterday's date with datetime

2006-05-15 Thread Thierry Lam
Is there an easy way to determine the yesterday's date(year-month-day)
from the python datetime library if I know today's date?

Thanks
Thierry

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


Python poly obsolete?

2006-03-17 Thread Thierry Lam
I have a piece of python code which goes like the following:

import poly

list = [1, 2, 3]

result = poly.scan(list)

I'm using Python 2.3.4 and I don't think that poly library is working
properly, I read somewhere that's it's obsolete now. What's the
alternative?

Thanks
Thierry

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


Re: Timeout at command prompt

2006-01-12 Thread Thierry Lam
Which Python version are you using? I'm getting the following error
with Python 2.3.4:

Traceback (most recent call last):
  File C:\home\pciroot\vcur\sdk\tools\inter.py, line 32, in ?
signal.signal(signal.SIGALRM, input)
AttributeError: 'module' object has no attribute 'SIGALRM'


Thierry

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


Re: Timeout at command prompt

2006-01-12 Thread Thierry Lam
Is there a windows equivalent for that solution?

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


Re: Timeout at command prompt

2006-01-12 Thread Thierry Lam
I got the signal to work on linux with sys.stdin.readline() but the
process timeout after x seconds even when I input something.  Is there
a way to close the signal after getting a correct input from the
console window?

Thanks
Thierry

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


Timeout at command prompt

2006-01-11 Thread Thierry Lam
I can use the python function raw_input() to read any input from the
user but how can I add a timeout so that my program exits after x
period of time when no input has been entered.

Thierry

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


Renaming files in ftplib

2006-01-07 Thread Thierry Lam
Let's say I have a file called 'test.c' on my local machine and I'm
ftping a file with similar name from a remote computer.  I want to
prefix the file ftped over with a T_, how do I do that through ftplib
in python?

Thanks
Thierry

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


Copying files between different linux machines

2006-01-07 Thread Thierry Lam
Let's say I have two linux machines with the following names:
-linone
-lintwo

If I'm currently on linone and if I want to copy a bunch of files from
lintwo into linone, how can that be done in a python script without
using ftp?

Thanks
Thierry

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


Help in File selector window in pygtk

2005-11-21 Thread Thierry Lam
Let's say I have a main window which has a File menu. When I click on
the File menu and the open button, I have a File selector window which
comes in front of my main window.  How do I make the main window
unselectable?

Thanks
Thierry

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


Help with modal in Gtk::FileChooserDialog

2005-11-21 Thread Thierry Lam
Does anyone know how to set modal to True for Gtk::FileChooserDialog?

Thanks
Thierry

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


Walking through directories and files

2005-09-16 Thread Thierry Lam
I'm trying to use the os.walk() method to search all the directory from
a root directory and display their contents. For example, I want my
output to be like the following:


directoryA
stuffs.c
stuffs2.cpp

directoryB
asd.c
asdf.cpp


Any ideas how to do it? Currently, I can only print all the filenames
first and then the directory names.

Thanks
Thierry

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


Re: Creating Pie Chart from Python

2005-09-16 Thread Thierry Lam
Those python pie chart add ons are not very useful. For my specific pie
chart, I have some 6-8 items to show up and some of them occupy only
2-5% of the pie. This cause the names and percentages to overlap each
other.

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


Creating Pie Chart from Python

2005-09-15 Thread Thierry Lam
Let's say I have the following data:

500 objects:
-100 are red
-300 are blue
-the rest are green

Is there some python package which can represent the above information
in a pie chart?

Thanks
Thierry

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


Re: Creating Pie Chart from Python

2005-09-15 Thread Thierry Lam
In a web browser, having a pie chart in some image format will be great.

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


Writing at the beginning of a file

2005-09-14 Thread Thierry Lam
Let's say I already wrote a file and have the following:

testing
testing testing
testing testing testing

Is there an easy way to write something of variable length at the top
of the file?

For example,

6 testing written
testing
testing testing
testing testing testing

I tried to write some garbage on top right after opening the file and
then use seek to overwrite the garbage, but since the string to be
written can be of variable length, I'm not sure how much garbage I have
to write initially.

The other way to do what I want is to write the whole thing to a new
file, but I want to skip that method if there's an alternative way.

Another way of doing it is to buffer the whole file writing into some
variable, but that means I have to change 2000+ lines of codes and
change fp.write() to something else.

Any suggestions please?

Thanks
Thierry

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


Python xml.dom, help reading attribute data

2005-09-06 Thread Thierry Lam
Let's say I have the following xml tag:

para role=success1/para

I can't figure out what kind of python xml.dom codes I should invoke to
read the data 1? Any help please?

Thanks
Thierry

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


Ignoring ampersand() as a special character in xml

2005-09-06 Thread Thierry Lam
Let's say I have the following xml tag:

para role=sourcea  b/para

Currently, an xml parser will treat  as a special character.  Does
anyone know the special characters to use around the ampersand so that
the xml parser can treat a  b as a whole value?

Thanks
Thierry

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


Mapping network drive on Linux

2005-08-31 Thread Thierry Lam
On windows, if I want to map a network drive to a local drive on my
computer, I do the following:

data = {
'remote' : '\\blah\data',
'local' : 'Z:'
   }
   win32net.NetUseAdd(None, 1, data)


How am I supposed to do similar thing on Linux?

Thanks
Thierry

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


Calling ftp commands from python

2005-08-31 Thread Thierry Lam
Is it possible to run an ftp command to connect to some remote computer
on the network.

For example, if I want to retrieve some data from
\\remcomputer\datafiles on the network and copy it to my local
computer, how do I do it in python on the Unix side?

I don't want to use mount since I don't have permission.

Thanks
Thierry

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


Mapping a drive to a network path

2005-07-22 Thread Thierry Lam
In DOS, if I want to map a network path to a drive, I do the following:

net use z: \\computer\folder

How do we do something similar in python?

Thanks
Thierry

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


Re: Mapping a drive to a network path

2005-07-22 Thread Thierry Lam
Thanks, that helps.

Thierry

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


Reading output from standard out

2005-05-02 Thread Thierry Lam








Lets say I have a python program which prints output
to standard out, lets call it HelloApp. How do I capture these outputs
from the python GUI tkinter? For example, I want to call HelloApp from my GUI
program and I want to send the output live to a tkinter text area.



Thanks

Thierry






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

Reading output from standard out

2005-05-02 Thread Thierry Lam








Lets say I have a python program which prints output
to standard out, lets call it HelloApp. How do I capture these
outputs from the python GUI tkinter? For example, I want to call HelloApp from
my GUI program and I want to send the output live to a tkinter text area.



Thanks

Thierry






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