Re: Problem with __str__ if baseclass is list

2005-11-13 Thread Serge Orlov
Edward C. Jones wrote:
> #! /usr/bin/env python
>
> class A(list):
>  def __init__(self, alist, n):
>  list.__init__(self, alist)
>  self.n = n
>
>  def __str__(self):
>  return 'AS(%s, %i)' % (list.__str__(self), self.n)
>
>  def __repr__(self):
>  return 'AR(%s, %i)' % (list.__repr__(self), self.n)
>
> a = A(['x', 'y'], 7)
>
> print 1, a
> print 2, repr(a)
> print 3, list.__str__(a)
> print 4, list.__repr__(a)
>
> """
> The output is:
>
> 1 AS(AR(['x', 'y'], 7), 7)
> 2 AR(['x', 'y'], 7)
> 3 AR(['x', 'y'], 7)
> 4 ['x', 'y']
>
> Why is list.__str__(a) == "AR(['x', 'y'], 7)"?

Because it's coded like this:
def __str__(self):
return repr(self)

That implies str(x) == repr(x), since you don't want that, don't call
list.__str__

>
> Note: The problem goes away if "list.__str__(a)" is replaced with
> "list.__repr__(self)".
> """

That's right. You *cannot* call list.__str__ because it contradicts
design of class A

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


Re: Inheritence Problem

2005-11-13 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
> Hello.  I'm trying to mod an open source app called TinyERP and inherit
> from a parent object, and in essence change how _column is defined.  I
> found sample code of:

Looks like "Spot the differences" puzzle to me. Hint: look at the
underscore characters.

>
> class custom_product(osv.osv):
>   __inherits__ = "product.product"
>   __name__ = "product.product"
>  _columns  = {
> 'color' : fields.many2one('color','Color'),
> 'size': fields.many2one('size','Size'),
>  }
> custom_product()
>

...

>  class product_uom_categ(osv.osv):
>   _name = 'product.uom.categ'
>   _description = 'Product uom categ'
>   _columns = {
>   'name': fields.char('Name', size=64, required=True),
>   }
> product_uom_categ()

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


Re: Confusion about __call__ and attribute lookup

2005-11-13 Thread Serge Orlov
Kent Johnson wrote:
> Leif K-Brooks wrote:
> > New-style classes look up special methods on the class, not on the instance:
>
> For my future reference, is this documented somewhere in the standard docs?
>

Looks like it's the most detailed explanation on the net:

http://mail.python.org/pipermail/python-dev/2003-May/035732.html

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


Re: newbie - How do I import automatically?

2005-11-17 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
> I also checked in command prompt, and there it works!, but not in IDLE.
> And it's in IDLE that I work all the time. Can anything be done to get
> it to work there?

According to command line help
   (run C:\Python24\Lib\idlelib>idle.py -h )
"idle -s" is what you're looking for.

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


Re: pySonic - writing a sample to a file

2005-11-17 Thread Serge Orlov

netspeed.com.au wrote:
> Hi all:
>
> Hopefully a simple question. I have been putting together an application
> using pySonic. I find the documentaion fine with plenty of examples but I
> cant see how to save a sample (or any recorded audio) to a file.
>
> Am I missing something obvious?

Python comes with read/write support for several audio file formats:
http://docs.python.org/lib/mmedia.html
perhaps you can get raw stream from pySonic and save it using python
stdlib module?

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


Re: best way to discover this process's current memory usage, cross-platform?

2005-11-17 Thread Serge Orlov

Jack Diederich wrote:
> Electric Fence[1] uses the LD_PRELOAD method.  I've successfully used it to
> track down leaks in a python C extension.  If you look at the setup.py in
> probstat[2] you'll see
>   #libraries = ["efence"] # uncomment to use ElectricFence
> which is a holdover from developing.

I've also successfully used Electric Fence many years ago to track down
leaks in a C/Linux program. Since that time Electric Fence has been
forked into DUMA project http://duma.sourceforge.net/ and was ported to
windows, perhaps it has become cross-platform? I've never tried it on
anything besides Linux.

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


Re: PyExcelerator - mishandling of formulas?

2005-11-17 Thread Serge Orlov
Marco Aschwanden wrote:
> Hi,
>
> Yesterday I placed a bug report on PyExcelerators-Sourceforge-page... but
> I am not so sure anymore, whether this is really a bug - I could imagine
> that I missed something, but I don't see what. Please confirm that my bug
> is due to mishandling and I will gladly retreat my bug report.
>
> In a formula, I would like to point to a field on another worksheet.
> pyExcelerator chokes on these references!
>
> 
>
> import pyExcelerator
>
> wb = pyExcelerator.Workbook()
> ws_summary = wb.add_sheet('Summary')
> ws_data = wb.add_sheet('Data')
>
> ws_summary.write(0,0, pyExcelerator.Formula('Data:A1')) <--- Here it
> chokes!
> ws_data.write(0, 0, '4000')
>
> wb.save('not_parsing.xls')
>
> 
>
> Is this a bug or am I doing something wrong?

I think you're doing it wrong. ":" character means range, to refer to a
sheet use "!" charater: Data!A1

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


Re: sqlite utf8 encoding error

2005-11-17 Thread Serge Orlov
Jarek Zgoda wrote:
> Fredrik Lundh napisa³(a):
>
> >>UnicodeDecodeError: 'utf8' codec can't decode bytes in position 13-18:
> >>unsupported Unicode code range
> >>
> >>does anyone have any idea on what could be going wrong?  The string
> >>that I store in the database table is:
> >>
> >>'Keinen Text für Übereinstimmungsfehler gefunden'
> >
> > $ more test.py
> > # -*- coding: iso-8859-1 -*-
> > u = u'Keinen Text für Übereinstimmungsfehler gefunden'
> > s = u.encode("iso-8859-1")
> > u = s.decode("utf-8") # <-- this gives an error
> >
> > $ python test.py
> > Traceback (most recent call last):
> >   File "test.py", line 4, in ?
> > u = s.decode("utf-8") # <-- this gives an error
> >   File "lib/encodings/utf_8.py", line 16, in decode
> > return codecs.utf_8_decode(input, errors, True)
> > UnicodeDecodeError: 'utf8' codec can't decode bytes in position 13-18:
> > unsupported Unicode code range
>
> I cann't wait for the moment when encoded strings go away from Python.
> The more I program in this language, the more confusion this difference
> is causing. Now most of functions and various object's methods accept
> strings and unicode, making it hard to find sources of Unicode*Errors.

Library writers can speed up the transition by hiding 8bit interface,
for example:

import sqlite
sqlite.I_promise_to_pass_8bit_string_only_in_utf8_encoding(my_signature="sig.gif")

if you don't call this function 8bit strings will not be accepted :)
IMHO if libraries keep on excepting both str and unicode till python
3.0, it will just prolong the confusion of unicode newbies instead of
guiding them in the right direction _right now_.

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


Re: Python obfuscation

2005-11-18 Thread Serge Orlov
Ben Sizer wrote:
> Mike Meyer wrote:
> > "Ben Sizer" <[EMAIL PROTECTED]> writes:
> > > Decompyle (http://www.crazy-compilers.com/decompyle/ ) claims to be
> > > pretty advanced. I don't know if you can download it any more to test
> > > this claim though.
> >
> > No, it doesn't claim to be advanced. It claims to be good at what it
> > does. There's no comparison with other decompilers at all. In
> > particular, this doesn't give you any idea whether or not similar
> > products exist for x86 or 68k binaries.
>
> That's irrelevant. We don't require a citable source to prove the
> simple fact that x86 binaries do not by default contain symbol names
> whereas Python .pyc and .pyo files do contain them. So any
> decompilation of (for example) C++ code is going to lose all the
> readable qualities, as well as missing any symbolic constants,
> enumerations, templated classes and functions, macros,  #includes,
> inlined functions, typedefs, some distinctions between array indexing
> and pointer arithmetic, which inner scope a simple data variable is
> declared in, distinctions between functions/member functions declared
> as not 'thiscall'/static member functions, const declarations, etc.

If you protection is actually boils down to "if (licensed) ..."
everything you described will just slightly inconvinient an experienced
cracker. I've read a cracker's detailed walkthrough, it took him 26
minutes to crack a program that asks for a serial number. Basically it
looks like this: set breakpoint on event where "OK" button is pressed
after a serial number is entered, set watchpoint on memory where the
serial number is stored, study all places where this memory is read,
find the ultimate "jump if" instruction.



>
> > I've dealt with some very powerfull disassemblers and
> > decompilers, but none of them worked on modern architectures.
>
> You can definitely extract something useful from them, but without
> symbol names you're going to have to be working with a good debugger
> and a decent knowledge of how to use it if you want to find anything
> specific. Whereas Python could give you something pretty obvious such
> as:
>
>6 LOAD_FAST0 (licensed)
>9 JUMP_IF_FALSE9 (to 21)

I can suggest at least two methods to obfuscate python byte code:

1. Apply some function before writing byte code to file, apply reverse
function upon reading.

2. Take opcodes.h and assign new random numbers to opcodes, also take
ceval.c and reorder opcode handlers in the switch statement to make
reverse engeneering even harder.

I believe this will require at least several hours of manual work
before you can use stock python disassembler.


>
> My interest lies in being able to use encrypted data (where 'data' can
> also include parts of the code) so that the data can only be read by my
> Python program, and specifically by a single instance of that program.
> You would be able to make a backup copy (or 20), you could give the
> whole lot to someone else, etc etc. I would just like to make it so
> that you can't stick the data file on Bittorrent and have the entire
> world playing with data that was only purchased once.

This is doable even in python. Basic idea is that you need to spread
your obfuscation code and blend it with algorithm:

1. Generate user identity on your server and insert it inside your
distribution. Spread it all over the code, don't store it in a file,
don't store in one big variable, instead divide the user identity in
four bits part and spread their storage over different places. Note
this actually doesn't have anything to do with python, it's true for
C/C++. If you don't follow this your protection is vulnerable to replay
attack: crackers will just distribute data file + stolen user identity.

2. Generate custom data files for each user, using various parts of
user id as scrambling key for different parts of the data file. For
example: suppose you have data file for a game and you store initial
coordinates of characters as coordinates (0..65535,0..65535) as four
bytes. Normal code to load them from file would like like

x,y = buf[0]+256*buf[1], buf[2]+256*buf[3]

obfuscated would look like

x,y = buf[0]+c*((buf[1]+ t + 7)&c), buf[2]+c*((buf[1]+ t + 7)&c)

where t contains some bits from user id and c==256



I hope it's not very vague description. I think this approach will do
what you want. Don't forget that you will also need to bind you program
to hardware, or users will just distribute your program + data file
together. I hope they won't mind that your program is tied to one
computer :)

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


Re: Python as Guido Intended

2005-11-27 Thread Serge Orlov
Antoon Pardon wrote:
> No it wasn't. From what I have picked up, the ternary operator
> was finaly introduced after one of the developers tripped over
> the commonly used idiom to simulate a ternary operator, which
> can fail in certain cases.

>
> Anyway, when I was arguing for a ternary operator in python,
> those who opposed me, certainly gave me the impression that
> they thought I wanted to mangle the language, the mere idea
> of a ternary operator was against the spirit of python.
>
> When I argued for a more general loop construct similar
> objections were made and the proposal was fiercely fought.
> Someone even started a PEP, with the intention to bury
> the idea. (That can be from before I argued for it)
>
> Now I have read about both that they will be introduced in
> Python 2.5 without a whisper of protest.

Protesting BDFL is absolutely useless by definition even if you
disagree. Tim Peters wanted generators for 10 years

and he has much more power of convincing Guido than you. Why do you
think your proposal should be immediately accepted?

By the way, I don't see the features you mentioned neither in

nor among PEPs. Perhaps they are not final?

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


Re: Locale confusion

2005-01-11 Thread Serge . Orlov
Jorgen Grahn wrote:
[snip]

>
> frailea> cat foo
> import locale
> print locale.getlocale()
> locale.setlocale(locale.LC_CTYPE)
> print locale.getlocale()
>
> When I paste it into an interactive Python session, the locale is
already
> set up correctly (which is what I suppose interactive mode /should/
do):
>
> >>> import locale
> >>> print locale.getlocale()
> ['sv_SE', 'ISO8859-1']
> >>> locale.setlocale(locale.LC_CTYPE)
> 'sv_SE'
> >>> print locale.getlocale()
> ['sv_SE', 'ISO8859-1']
> >>>
>
> When I run it as a script it isn't though, and the setlocale() call
does not
> appear to fall back to looking at $LANG as it's supposed to(?), so my
> LC_CTYPE remains in the POSIX locale:
>
> frailea> python foo
> (None, None)
> (None, None)
>
> The corresponding program written in C works as expected:
>
> frailea> cat foot.c
> #include 
> #include 
> int main(void) {
> printf("%s\n", setlocale(LC_CTYPE, 0));
> printf("%s\n", setlocale(LC_CTYPE, ""));
> printf("%s\n", setlocale(LC_CTYPE, 0));
> return 0;
> }
> frailea> ./foot
> C
> sv_SE
> sv_SE
>
> So, is this my fault or Python's?  I realize I could just adapt and
set
> $LC_CTYPE explicitly in my environment, but I don't want to
capitulate for a
> Python bug, if that's what this is.

Try locale.setlocale(locale.LC_CTYPE,"") as in your C program. It would
be great if locale.setlocale with one parameter would be deprecated,
because it suddenly acts like getlocale. It's unpythonic.

By the way, since you took time to setup various LC_* variables there
is no need to play with LC_CTYPE category. Just use the standard idiom.
import locale
locale.setlocale(LC_ALL,"")

 Serge.

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


Re: Python & unicode

2005-01-11 Thread Serge . Orlov
Michel Claveau - abstraction méta-galactique non triviale en fuite
perpétuelle. wrote:
> Hi !
>
> >>> and plain Latin letters
>
> But not all letters  (no : é à ç à ê ö ñ  etc.)
>
>
>
> Therefore, the Python's support of Unicode is... limited.
>

So is the support of Unicode in virtually every computer language
because they don't support ... digits except 0..9. Does anyone know a
language that supports?

  Serge.

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


Re: Python & unicode

2005-01-11 Thread Serge Orlov
Leif K-Brooks wrote:
> [EMAIL PROTECTED] wrote:
> > So is the support of Unicode in virtually every computer language
> > because they don't support ... digits except 0..9.
>
> Hex digits aren't 0..9.
>

You're right, I forgot about hex. But that's boring :) How about Hebrew
numerals which are present in Unicode?

  Serge.

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


Re: Python & unicode

2005-01-11 Thread Serge Orlov
Michel Claveau - abstraction méta-galactique non triviale en fuite
perpétuelle. wrote:
> Hi !
>
> >>> It is a least-common-denominator argument, not a "this is better"
> argument.
>
> I understand, but I have a feeling of attempt at hegemony.  Is
english
> language really least-common-denominator for a russian who writes
into
> cyrillic, or not anglophone chinese?

I don't know about Chinese but English *is* the least common
denominator for native Russian software developers, there are a lot of
reasons for that:

- to switch between Russian keyboard layout and English keyboard you
need to press a switch key or usually even two keys (at the same time).
Since language syntax and library calls are in English you have to
switch often. Very often you forget what is the current keyboard layout
and start typing in wrong one and you have to delete the garbage, hit
switch key and type it again. If it happens ten times every ten minutes
it will drive you crazy.

- Most of native Russian developers graduated from universities or
institutes. They attended hundreds of hours of math and physics
classes. All these classes use latin notation.

- Any serious local sw development job application mentions "Technical
English" as requirement. It means you're expected to read technical
documents in English.

- At the same time majority of native Russians developers do not speak
English very well and they feel they need more English practice. Using
English identifiers is a chance to practice while you work.

- The amount of useful information in English is much greater than in
Russian, thanks to Internet.

Surprised? :)

  Serge.

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


Re: Python & unicode

2005-01-12 Thread Serge Orlov
Michel Claveau - abstraction méta-galactique non triviale en fuite
perpétuelle. wrote:
> Hi !
>
> Sorry, but I think that, for russians, english is an *add-on*,
> and not a common-denominator.

You miss the point, programs are not English writings, they are written
in computer languages using libraries with English identifiers. On the
other hand comments and documentation are text. And Russian programmers
do write Russian comments in programs.
I've seen that a lot of times. On the other hand I've never seen any
serious program written with Russian identifiers. Sure such programs
may exist but my point is that they are very rare. That makes English
the language of choice for Russian programmers. I'm not against the
ability to write identifiers in my native Russian language, I don't
mind it. I'm just trying to get the message across that Russian
programmers are not dying for such feature and almost all of them don't
use such feature in languages that permit Unicode identifiers.

> English is the most known language, but it is not common.  It is
> the same difference as between co-operation and colonization.

When I hear "It's the same difference as ..." it raises a red flag in
my mind. Often, fine words have no connection to the subject. I can say
that it's the same difference as between ability to drive a car and
ability to walk. The car doesn't own you ;)

  Serge.

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


Re: Unicode conversion in 'print'

2005-01-13 Thread Serge Orlov
Ricardo Bugalho wrote:
> Hello,
>  I'm using Python 2.3.4 and I noticed that, when stdout is a
terminal,
> the 'print' statement converts Unicode strings into the encoding
> defined by the locales instead of the one returned by
> sys.getdefaultencoding().

Sure. It uses the encoding of you console. Here is explanation why it
uses locale to get the encoding of console:
http://www.python.org/moin/PrintFails

> However, I can't find any references to it. Anyone knows where it's
> descrbed?

I've just wrote about it here:
http://www.python.org/moin/DefaultEncoding

>
> Example:
>
> !/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> import sys, locale
>
> print 'Python encoding:', sys.getdefaultencoding()
> print 'System encoding:', locale.getpreferredencoding()
> print 'Test string: ', u'Olá mundo'
>
>
> If stdout is a terminal, works fine
> $ python x.py
> Python encoding: ascii
> System encoding: UTF-8
> Test string:  Olá mundo
>
> If I redirect the output to a file, raises an UnicodeEncodeError
exception
> $ python x.py > x.txt
> Traceback (most recent call last):
>   File "x.py", line 8, in ?
> print 'Test string: ', u'Olá mundo'
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in
position 2: ordinal not in range(128)
>

http://www.python.org/moin/ShellRedirectionFails

Feel free to reply here if something is not clear, corrections in wiki
are also welcome.

  Serge.

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


Re: Unicode conversion in 'print'

2005-01-14 Thread Serge Orlov
Ricardo Bugalho wrote:
> Hi,
>  thanks for the information. But what I was really looking for was
> informaion on when and why Python started doing it (previously, it
> always used sys.getdefaultencoding()))

I don't have access to any other version except 2.2 at the moment but I
believe it happened between 2.2 and 2.3 for Windows and UNIX terminals.
On other unsupported terminals I suspect sys.getdefaultencoding is
still used. The reason for the change is proper support of unicode
input/output.


> and why it was done only for 'print' when
> stdout is a terminal instead of always.

The real question is why not *never* use sys.getdefaultencoding()
for printing. If you leave sys.getdefaultencoding() at Python default
value ('ascii') you won't need to worry about it 
sys.getdefaultencoding() is a temporary measure for big projects to
use within one Python version.

  Serge.

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


Re: Why 'r' mode anyway? (was: Re: Pickled text file causing ValueError (dos/unix issue))

2005-01-14 Thread Serge Orlov
Irmen de Jong wrote:
> Tim Peters wrote:
>
> > Yes:  regardless of platform, always open files used for pickles in
> > binary mode.  That is, pass "rb" to open() when reading a pickle
file,
> > and "wb" to open() when writing a pickle file.  Then your pickle
files
> > will work unchanged on all platforms.  The same is true of files
> > containing binary data of any kind (and despite that pickle
protocol 0
> > was called "text mode" for years, it's still binary data).
>
> I've been wondering why there even is the choice between binary mode
> and text mode. Why can't we just do away with the 'text mode' ?

We can't because characters and bytes are not the same things. But I
believe what you're really complaining about is that "t" mode sometimes
mysteriously corrupts data if processed by the code that expects binary
files. In Python 3.0 it will be fixed because file.read will have to
return different objects: bytes for "b" mode, str for "t" mode. It
would be great if file type was split into binfile and textfile,
removing need for cryptic "b" and "t" modes but I'm afraid that's too
much of a change even for Python 3.0

  Serge.

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


Re: oddities in the datetime module

2005-01-14 Thread Serge Orlov
Max M wrote:
> # -*- coding: latin-1 -*-
>
> """
>
> I am currently using the datetime package, but I find that the design
> is oddly
> asymmetric. I would like to know why. Or perhaps I have misunderstood
> how it should be used?

Yes, you did. datetime.timetuple is those who want *time module* format, you 
should use datetime.data, datetime.time, datetime.year 
and so on...

[snip a lot of timetuple wrestling]
> The other way around is also easy.
>
 dt = datetime(2005, 1, 1, 12, 0, 0)
 date(*dt.timetuple()[:3])
> datetime.date(2005, 1, 1)

As they say, if the only tool you have is timetuple, everything looks like 
tuple 

Try this:

>>> dt = datetime(2005, 1, 1, 12, 0, 0)
>>> dt.date()
datetime.date(2005, 1, 1)

  Serge.


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


Re: oddities in the datetime module

2005-01-14 Thread Serge Orlov
Max M wrote:
> Serge Orlov wrote:
>> Max M wrote:
>
>> Yes, you did. datetime.timetuple is those who want *time module*
>> format, you should use datetime.data, datetime.time, datetime.year
>> and so on... As they say, if the only tool you have is timetuple, everything
>> looks like tuple  Try this:
>>
>>>>> dt = datetime(2005, 1, 1, 12, 0, 0)
>>>>> dt.date()
>>
>> datetime.date(2005, 1, 1)
>
> This doesn't solve it. I don't think you understand my issue.

I understand, but I don't think it's something that should be solved. Especially
date(*dt.timetuple()[:3])


> class my_datetime(datetime):
>
> def __add__(self, other):
> result = datetime.__add__(self, other)
> return my_datetime(result.timetuple()[:6])
>

What about:

def __add__(self, other):
result = datetime.__add__(self, other)
return my_datetime.fromdatetime(result)

  Serge. 


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


Re: how to print unicode structures?

2005-01-17 Thread Serge Orlov
Timothy Babytch wrote:
> Imagine you have some list that looks like
> ('unicode', 'not-acii', 'russian') and contains characters not from
> acsii. or list of dicts, or dict of dicts.
>
> how can I print it? not on by one, with "for" - but with just a simple
> print? My debugging would be MUCH simpler.

I think the best (in terms of time) way to do it is to copy pprint.py
to upprint.py and hack it.

>
> Now when I try print or pprint that variable I get a page full of
> '\xe4\xeb\xa2\xa0\xe6\xe3\xaa\xe6\xe3\xaa' and so on.

It looks like bytes, you should get rid of them as soon as possible. If you're 
not looking for speed hacks, as a rule of thumb you 
should convert bytes to unicode characters as soon as possible. When I try to 
print Russian characters I get unicode escapes (\u) 
not byte escapes (\x) like you:
>>> print unicode([u'ÁÂ×'])
[u'\u0430\u0431\u0432']

   Serge.


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


Re: how to print unicode structures?

2005-01-17 Thread Serge Orlov
Serge Orlov wrote:
>>>> print unicode([u'ÁÂ×'])
> [u'\u0430\u0431\u0432']
>
Oops, Outlook Express has screwed the encoding, one more evidence that printing 
unicode is hard :)
I hope this time, the message will be with real Russian characters instead of 
Latin ones.

  Serge. 


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


Re: Printing Filenames with non-Ascii-Characters

2005-02-01 Thread Serge Orlov
Marian Aldenhövel wrote:
> Hi,
>
> I am very new to Python and have run into the following problem. If I
do
> something like
>
>dir = os.listdir(somepath)
>for d in dir:
>   print d
>
> The program fails for filenames that contain non-ascii characters.
>
>'ascii' codec can't encode characters in position 33-34:
>
> I have noticed that this seems to be a very common problem. I have
read a lot
> of postings regarding it but not really found a solution. Is there a
simple
> one?

No :) You're trying to deal with legacy terminals, you can't reliably
print unicode characters across various terminals. It's not really
Python's fault.

>
> What I specifically do not understand is why Python wants to
interpret the
> string as ASCII at all. Where is this setting hidden?

http://www.python.org/moin/PrintFails Let me know if it's not clear. It
would be great if other people fixed/improved this page.

> I am running Python 2.3.4 on Windows XP and I want to run the program
on
> Debian sarge later.

You need cross platform terminal that supports unicode output.
Sergey.

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


Re: sre is broken in SuSE 9.2

2005-02-10 Thread Serge Orlov
Denis S. Otkidach wrote:
> On all platfroms \w matches all unicode letters when used with flag
> re.UNICODE, but this doesn't work on SuSE 9.2:
>
> Python 2.3.4 (#1, Dec 17 2004, 19:56:48)
> [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
> Type "help", "copyright", "credits" or "license" for more
information.
> >>> import re
> >>> re.compile(ur'\w+', re.U).match(u'\xe4')
> >>>
>
> BTW, is correctly recognize this character as lowercase letter:
> >>> import unicodedata
> >>> unicodedata.category(u'\xe4')
> 'Ll'
>
> I've looked through all SuSE patches applied, but found nothing
related.
> What is the reason for broken behavior?  Incorrect configure options?

I can get the same results on RedHat's python 2.2.3 if I pass re.L
option, it looks like this option is implicitly set in Suse.

  Serge

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


Re: sre is broken in SuSE 9.2

2005-02-10 Thread Serge Orlov
Denis S. Otkidach wrote:
> On 10 Feb 2005 03:59:51 -0800
> "Serge Orlov" <[EMAIL PROTECTED]> wrote:
>
> > > On all platfroms \w matches all unicode letters when used with
flag
> > > re.UNICODE, but this doesn't work on SuSE 9.2:
> [...]
> > I can get the same results on RedHat's python 2.2.3 if I pass re.L
> > option, it looks like this option is implicitly set in Suse.
>
> Looks like you are right:
>
> >>> import re
> >>> re.compile(ur'\w+', re.U).match(u'\xe4')
> >>> from locale import *
> >>> setlocale(LC_ALL, 'de_DE')
> 'de_DE'
> >>> re.compile(ur'\w+', re.U).match(u'\xe4')
> <_sre.SRE_Match object at 0x40375560>
>
> But I see nothing related to implicit re.L option in their patches
> and the sources themselves are the same as on other platforms.  I'd
> prefer to find the source of problem.

I found that

print u'\xc4'.isalpha()
import locale
print locale.getlocale()

produces different results on Suse (python 2.3.3)

False
(None, None)


and RedHat (python 2.2.3)

1
(None, None)

  Serge.

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


Re: sre is broken in SuSE 9.2

2005-02-10 Thread Serge Orlov
Denis S. Otkidach wrote:
> On all platfroms \w matches all unicode letters when used with flag
> re.UNICODE, but this doesn't work on SuSE 9.2:
>
> Python 2.3.4 (#1, Dec 17 2004, 19:56:48)
> [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
> Type "help", "copyright", "credits" or "license" for more
information.
> >>> import re
> >>> re.compile(ur'\w+', re.U).match(u'\xe4')
> >>>
>
> BTW, is correctly recognize this character as lowercase letter:
> >>> import unicodedata
> >>> unicodedata.category(u'\xe4')
> 'Ll'
>
> I've looked through all SuSE patches applied, but found nothing
> related. What is the reason for broken behavior?  Incorrect
> configure options?

To summarize the discussion: either it's a bug in glibc or there is an
option to specify modern POSIX locale. POSIX locale consist of
characters from the portable character set, unicode is certainly
portable. 

  Serge.

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


Re: sre is broken in SuSE 9.2

2005-02-10 Thread Serge Orlov
Peter Maas wrote:
> Serge Orlov schrieb:
> > Denis S. Otkidach wrote:
> > To summarize the discussion: either it's a bug in glibc or there is
an
> > option to specify modern POSIX locale. POSIX locale consist of
> > characters from the portable character set, unicode is certainly
> > portable.
>
> What about the environment variable LANG? I have SuSE 9.1 and
> LANG = de_DE.UTF-8. Your example is running well on my computer.

This thread is about problems only with LANG=C or LANG=POSIX, it's not
about other locales. Other locales are working as expected.

  Serge.

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


Re: sre is broken in SuSE 9.2

2005-02-11 Thread Serge Orlov
Denis S. Otkidach wrote:
> On 10 Feb 2005 11:49:33 -0800
> "Serge Orlov" <[EMAIL PROTECTED]> wrote:
>
> > This thread is about problems only with LANG=C or LANG=POSIX, it's
not
> > about other locales. Other locales are working as expected.
>
> You are not right.  I have LANG=de_DE.UTF-8, and the Python
test_re.py
> doesn't pass.

I meant "only with C or POSIX locales" when I wrote "only with LANG=C
or LANG=POSIX". My bad.

> $LANG doesn't matter if I don't call setlocale.

Sure.

> Fortunately setting any non-C locale solves the problem for all (I
> believe) unicode character:
>
> >>> re.compile(ur'\w+', re.U).findall(u'\xb5\xba\xe4\u0430')
> [u'\xb5\xba\xe4\u0430']

I can't find the strict definition of isalpha, but I believe average
C program shouldn't care about the current locale alphabet, so isalpha
is a union of all supported characters in all alphabets

  Serge.

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


Re: sre is broken in SuSE 9.2

2005-02-12 Thread Serge Orlov
"Martin v. Löwis" wrote:
> Serge Orlov wrote:
>  > To summarize the discussion: either it's a bug in glibc or there
> is an
>> option to specify modern POSIX locale. POSIX locale consist of
>> characters from the portable character set, unicode is certainly
>> portable.
>
> Yes, but U+00E4 is not in the portable character set. The portable
> character set is defined here:
>
> http://www.opengroup.org/onlinepubs/007908799/xbd/charset.html

Thanks for the link. They write (in 1997 or earlier ?):

 The wide-character value for each member of the Portable
Character Set will equal its value when used as the lone character
 in an integer character constant. Wide-character codes for other
characters are locale- and *implementation-dependent*

Emphasis is mine. So how many libc implementations with
non-unicode wide-character codes do we have in 2005?
I'm really interested to know.

  Serge.


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


Re: sre is broken in SuSE 9.2

2005-02-12 Thread Serge Orlov
Fredrik Lundh wrote:
> Serge Orlov wrote:
>
>>>>>> re.compile(ur'\w+', re.U).findall(u'\xb5\xba\xe4\u0430')
>>>>>> [u'\xb5\xba\xe4\u0430']
>>
>> I can't find the strict definition of isalpha, but I believe average
>> C program shouldn't care about the current locale alphabet, so
>> isalpha is a union of all supported characters in all alphabets
>
> btw, what does isalpha have to do with this example?

It has to do with this thread. u'\xe4'.isalpha() returns false in
Suse. It's in the same boat as \w

  Serge.


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


Re: sre is broken in SuSE 9.2

2005-02-12 Thread Serge Orlov
Fredrik Lundh wrote:
> Serge Orlov wrote:
>
>>>>>> re.compile(ur'\w+', re.U).findall(u'\xb5\xba\xe4\u0430')
>>>>>> [u'\xb5\xba\xe4\u0430']
>>
>> I can't find the strict definition of isalpha, but I believe average
>> C program shouldn't care about the current locale alphabet, so
>> isalpha is a union of all supported characters in all alphabets
>
> nope.  isalpha() depends on the locale, as does all other ctype
> functions (this also applies to wctype, on some platforms).

I mean "all supported characters in all alphabets [in the current
locale]". For example in ru_RU.koi8-r isalpha should return
true for characters in English and Russian alphabets. In
ru_RU.koi8-u -- for characters in English, Russia and Ukrain
alphabets, in ru_RU.utf-8 -- for all supported by the implementation
alphabetic characters in unicode. IMHO iswalpha in POSIX
locale can return true for all alphabetic characters in unicode
instead of being limited by English alphabet.

  Serge.

true in 


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


Re: writing unicode apps in python - some beginner questions.

2005-02-13 Thread Serge Orlov
WX wrote:
> (#2) Hindi is not displayed correctly on the screen when the
> "Suplemental language support" parts for Windows XP are not installed,
> in particular in the Regional and Languages  Options panel in the
> Control Panel, you have to check "Install files for complex script and
> right-to-left languages (including Thai)".  This adds Thai, and Indic
> language support.  Does anyone know a programmatic way in Python to
> check for this,so I can pop up a message telling users that support
> for this script hasn't been installed in Windows?

I suspect it's hidden in the windows registry. To find out where it's
hidden try the following:
1. Before installing supplemental language support export
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls
into a text file using regedit
2. Install supplemental language support
3. Export the same registry branch into another file and compare with
the first file.

If there are no changes try doing the same for other registry branches:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
HKEY_LOCAL_MACHINE\SYSTEM\

After you find out what's going on you can use python's module
_winreg to read the registry from your python program. Good luck.

  Serge.

 


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


Re: writing unicode apps in python - some beginner questions.

2005-02-13 Thread Serge Orlov
WX wrote:
> (#2) Hindi is not displayed correctly on the screen when the
> "Suplemental language support" parts for Windows XP are not installed,
> in particular in the Regional and Languages  Options panel in the
> Control Panel, you have to check "Install files for complex script and
> right-to-left languages (including Thai)".  This adds Thai, and Indic
> language support.  Does anyone know a programmatic way in Python to
> check for this,so I can pop up a message telling users that support
> for this script hasn't been installed in Windows?

In addition to my previous post you can try the following, more
simple method: try calling setlocale, if Thai support is installed I suspect
you won't get an exception:

>>> import locale
>>> locale.setlocale(locale.LC_ALL,'English')
'English_United States.1252'
>>> locale.setlocale(locale.LC_ALL,'Russian')
'Russian_Russia.1251'
>>> locale.setlocale(locale.LC_ALL,'Thai')
Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python24\lib\locale.py", line 379, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting

  Serge.





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


Re: os.rename() doesn't work w/unicode??

2005-02-14 Thread Serge Orlov
fanbanlo wrote:
> C:\MP3\001.txt -> 0.txt
> C:\MP3\01. ??? - (???).mp3 -> 1.mp3
>
> Traceback (most recent call last):
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 310, in RunScript
> exec codeObject in __main__.__dict__
>   File "C:\MP3\!RenameNum.py", line 40, in ?
> renameFiles(os.path.dirname(sys.argv[0]))
>   File "C:\MP3\!RenameNum.py", line 26, in renameFiles
> os.rename(os.path.join(path, filenames), new_filename)
> OSError: [Errno 22] Invalid argument

os.rename works with unicode, you're getting this error because
question marks are not allowed in file names on Windows.

  Serge.


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


Re: Access to formatting controls from within __repr__ or __str__?

2005-02-18 Thread Serge Orlov
Dan Sommers wrote:

> So my question is:  Is there a way to pass options "through" a format
> string to the __str__ and __repr__ functions?  For example, can I
> define  my own alternate form for use with the '#' formatting
> character, so that '%#s' generates output according to SI guidelines?

You can create your own class FmtTemplate like string.Template was done
in python 2.4: http://docs.python.org/lib/node105.html

and have it call obj.__str__("#s") when you use ${obj:#s} format. I'm
not sure why you want to pass format to repr (as far as I understand
repr is mostly for debug purposes) but you can call from template as
${obj:r} --> obj.__repr__()
${obj:#r} --> obj.__repr__("#r")

fmt = FmtTemplate("quantity1: ${q1:#s}, quantity2: ${q2:#s}")
q1=MyQuantity(...)
q2=MyQuantity(...)
print fmt.substitute(q1=q1,q2=q2)

  Serge.

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


Re: unicode and socket

2005-02-19 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
> It's really funny, I cannot send a unicode stream throuth socket with
> python while all the other languages as perl,c and java can do it.

You may really start laughing loudly  after you find out that you
can  send arbitrary python objects over sockets. If you want language
specific way of sending objects, see Irmen's first answer: use pickle.

> then, how about converting the unicode string to a binary stream?

Sure, there are already three answers in this thread that suggest you
to do that. Use encode method of unicode strings.

> It is possible to send a binary through socket with python?

Sure. If it wouldn't be possible to send bytes through sockets with Python
what else do you think could be sent? Perhaps you're confused that
bytes are stored in byte strings in Python, which are often called strings in
documentation and conversations? It will be fixed in Python 3.0, but
these days you have to store bytes in str type.

  Serge.




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


Re: Access to formatting controls from within __repr__ or __str__?

2005-02-19 Thread Serge Orlov
Dan Sommers wrote:
> On 18 Feb 2005 01:25:06 -0800,
> "Serge Orlov" <[EMAIL PROTECTED]> wrote:
>
>> Dan Sommers wrote:
>
>>> So my question is:  Is there a way to pass options "through" a
>>> format string to the __str__ and __repr__ functions?  For example,
>>> can I define my own alternate form for use with the '#' formatting
>>> character, so that '%#s' generates output according to SI
>>> guidelines?
>
>> You can create your own class FmtTemplate like string.Template was
>> done in python 2.4: http://docs.python.org/lib/node105.html
>
> That looks interesting.  Perhaps that will push me into upgrading to
> 2.4 sooner rather than later (I'm *not* looking forward to rebuilding
> all my extensions...).

You don't need to upgrade to Python 2.4. string.Template is a pure
Python code (about 130 lines) and it looks like it's Python 2.2
compatible. My suggestion was to grab it and hack it to add the
feature you want and then keep it in your own library.

  Serge.


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


Re: UTF-8 / German, Scandinavian letters - is it really this difficult?? Linux & Windows XP

2005-02-22 Thread Serge Orlov
Mike Dee wrote:
> [snip wrestling with byte strings]

In addition to Martin reply I just want to add two notes:
1. Interactive console in python 2.3 has a bug that was fixed
in 2.4, so you can't enter unicode strings at the prompt:

C:\Python24>python.exe
>>> a=u'ÐÐÐ'
>>> a
u'\u0430\u0431\u0432'

C:\Python23>python.exe
>>> a=u'ÐÐÐ'
>>> a
u'\xa0\xa1\xa2'

in 2.3 you need to use decode method to get unicode strings:
>>> import sys
>>> a2='ÐÐÐ'.decode(sys.stdin.encoding)
>>> a2
u'\u0430\u0431\u0432'

2. Suse ships buggy build of python so title doesn't work
properly, see discussion http://tinyurl.com/4k3au

>>> print aoumlautxyz.title()
ÃÃXyz

You will need to call setlocale to help you:

>>> import locale
>>> locale.setlocale(locale.LC_ALL,'')
'en_US.utf-8'
>>> print aoumlautxyz.title()
ÃÃxyz

  Serge.

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


Re: UTF-8 / German, Scandinavian letters - is it really this difficult?? Linux & Windows XP

2005-02-22 Thread Serge Orlov
Paul Boddie wrote:
> One side-effect of the "big push" to UTF-8 amongst the Linux
> distribution vendors/maintainers is the evasion of issues such as
> filesystem encodings and "real" Unicode at the system level. In
> Python, when you have a Unicode object, you are dealing with
> idealised
> sequences of characters, whereas in many system and library APIs out
> there you either get back a sequence of anonymous bytes or a sequence
> of UTF-8 bytes that people are pretending is Unicode, right up until
> the point where someone recompiles the software to use UTF-16
> instead,
> thus causing havoc. Anyone who has needed to expose filesystems
> created by Linux distributions before the UTF-8 "big push" to later
> distributions can attest to the fact that the "see no evil" brass
> monkey is wearing a T-shirt with "UTF-8" written on it.

Unfortunately the monkey is painted in the air with a stick, so
not everyone can see it. Python can't. Given a random linux system
how can you tell if the monkey has pushed it already or not?

  Serge.

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


Re: LC_ALL and os.listdir()

2005-02-23 Thread Serge Orlov
"Martin v. Löwis" wrote:
>> My goal is to build generalized code that consistently works with all
>> kinds of filenames.
>
> Then it is best to drop the notion that file names are
> character strings (because some file names aren't). You
> do so by converting your path variable into a byte
> string. To do that, you could try
>
> path = path.encode(sys.getfilesystemencoding())

Shouldn't os.path.join do that? If you pass a unicode string
and a byte string it currently tries to convert bytes to characters
but it makes more sense to convert the unicode string to bytes
and return two byte strings concatenated.

  Serge.


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


Re: Style guide for subclassing built-in types?

2005-02-24 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
> Thank you but your advice doesn't fit in my case since I want to keep
> the memory usage and the initial time minimum. iterable[::-1] would
> build another list and it would take big memory and time during
> reversing if iterable were huge. (and the "iterable" wouldn't be
> garbage-collected because I want to keep a reference to it)

You need to implement __iter__ method to pass your assert statement:
def __iter__(self):
return reversed(self)

With regards to style guide:

1. write empty subclass
class rev_subclass(list):
pass

2. print dir(rev_subclass) and write unit tests for every method. There
are 41 of them :) There is also __doc__ attribute you need to override.

3. Implement all the methods of rev_subclass to pass the tests.

  Serge.

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


Re: LC_ALL and os.listdir()

2005-02-24 Thread Serge Orlov
Duncan Booth wrote:
> Martin v. Löwis wrote:
>
> > Serge Orlov wrote:
> >> Shouldn't os.path.join do that? If you pass a unicode string
> >> and a byte string it currently tries to convert bytes to
> >> characters
> >> but it makes more sense to convert the unicode string to bytes
> >> and return two byte strings concatenated.
> >
> > Sounds reasonable. OTOH, this would be the only (one of a very
> > few?) occasion where Python combines byte+unicode => byte.
> > Furthermore, it might be that the conversion of the Unicode
> > string to a file name fails as well.
> >
> > That said, I still think it is a good idea, so contributions
> > are welcome.
> >
> It would probably mess up those systems where filenames really are
> unicode strings and not byte sequences.
>
> Windows (when using NTFS) stores all the filenames in unicode, and
> Python uses the unicode api to implement listdir (when given a
> unicode path). This means that the filename never gets encoded to
> a byte string either by the OS or Python. If you use a byte string
> path than the filename gets encoded by Windows and Python just
> returns what it is given.

Sorry for being not clear, but I meant posixpath.join since the whole
discussion is about posix systems.

  Serge.

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


Re: auto-completion history

2005-02-25 Thread Serge Orlov
porterboy wrote:
> Hi Folks,
>
> I have auto-completion set up in my python interpreter so that if I
> hit the tab key it will complete a variable or a python command*. eg.
> if I type
> >>> imp
> and if I then hit the tab key, the interpreter will complete it to...
> >>> import
>
> Now, I also use Matlab at the command line a lot and it has a nice
> additional auto-completion feature, whereby, if you type a few
> letters and hit the up-arrow, it will go back to the last command
> you typed > that began with those letters. If you keep hitting
> up-arrow it will cycle through all the commands you typed beginning
> with these letters. eg. if I type...
>
> Does a feature like this already exist in python???

It's not in python, it's in readline library. To read the documentation
do 'man readline'

readline.parse_and_bind('"\e[A": history-search-backward')

works for me. To find out what your up arrow key sends remove
\e[A and hit on your keyboard Control-v and then up arrow.

  Serge.

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


Re: variable declaration

2005-02-25 Thread Serge Orlov
Alexander Zatvornitskiy wrote:
> Hello All!
>
> I'am novice in python, and I find one very bad thing (from my point
> of view) in language. There is no keyword or syntax to declare
> variable, like 'var' in > Pascal, or special syntax in C. It can
> cause very ugly errors,like this:
>
> epsilon=0
> S=0
> while epsilon<10:
>   S=S+epsilon
>   epselon=epsilon+1
> print S
>
> It will print zero, and it is not easy to find such a bug!

I'm late to the party, but I found an interesting text by the Guinness
book
record-holder in typing. He claims that the python way of dealing with
typos is right. He doesn't write about python directly but the main
idea is to punish heavily for every typo. He also has "nice" words for
software industry and the backspace key. Read it here:
http://www.supremelearning.com/bookexcerpts.html

By the way if my reading of poor quality scan of his record certificate
http://www.supremelearning.com/image_certificate.html is correct, his
typing speed was 614 characters/minute. Impressive! There is also his
book in Russian language:
http://www.supremelearning.com/russianslbookpart1.html

As for me, typos have never been a big problem. They happen rarely.
As the Guinness book record-holder suggests: don't make typos!

  Serge.

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


Re: fdups: calling for beta testers

2005-02-26 Thread Serge Orlov
Peter Hansen wrote:
> Patrick Useldinger wrote:
>>> (9) Any good reason why the "executables" don't have ".py"
>>> extensions on their names?
>>
>> (9) Because I am lazy and Linux doesn't care. I suppose Windows does?
>
> Unfortunately, yes.  Windows has nothing like the "x" permission
> bit, so you have to have an actual extension on the filename and
> Windows (XP anyway) will check it against the list of extensions
> in the PATHEXT environment variable to determine if it should be
> treated like an executable.
>
> Otherwise you must type "python" and the full filename.

Or use exemaker, which IMHO is the best way to handle this
problem.

  Serge.


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


Re: Distributing applications

2005-03-02 Thread Serge Orlov
Jaime Wyant wrote:
> I chose not to use py2exe because it made updating my app a bit
> messier.  For instance, suppose I don't use the smtplib module in
> version 1 of my software.  Py2exe realizes that and doesn't 'package'
> smtplib with my executable.  Now, if I release version 1.1 which does
> use smtplib, then I'd have to figure out how to get the updates out
> without having the user redownload the entire application.  Granted,
> I didn't put much thought into an update mechanism, but it seemed to
> be messy at the time.

I don't follow you. How is that different compared to adding a module
to your application? Let's say version 1.1 of your software has
module1.py updated, module2.py added and it needs smtplib. You just
bundle three compiled files and unpack them let's say to
\program files\my software\module1.pyc
\program files\my software\module2.pyc
\program files\my software\python\smtplib.pyc

I don't see any mess.

>
>If I have my own distribution, I can simply give the users an "update"
> program that will query  my webserver which will download the latest
> version for them automagically.  Because my distribution has all of
> the modules already available, I don't have to worry about sending
> them any missing modules.  Simply download the latest version of my
> app and it works with my custom rolled distribution.
>
> But, this only works for Windows...

Why? As I understand "update" program was written by you, so what
prevents it from working on other platforms besides testing?

  Serge.

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


Re: Distributing applications

2005-03-02 Thread Serge Orlov
Phillip Mills wrote:
> First, thanks to all the people who have answered so far for the
> suggestions.
>
> In article <[EMAIL PROTECTED]>,
>  André Søreng <[EMAIL PROTECTED]> wrote:
>
> > Phillip Mills wrote:
>
> > > My problems are:
>
> [...]
>
> > http://starship.python.net/crew/theller/py2exe/
>
> Apparently I had more problems than I mentioned.  :-)  One of them
> being that a Windows-only solution is only a partial solution.

There is also py2app for Mac. Still partial? :) Then follow Jaime's
way: build and bundle python with your application.

>
> > >   - I also need the core part of the application to be reasonably

> > > protected.  I'm not looking to defeat hackers, but something
> > > equivalent to the way Java's class files stored in jars stay
> > > where they're supposed to be and aren't immediately readable.
> > >
> > Hmm, not sure about that one. You mean that those users who write
> > extensions should not be able to modify the core code you wrote?
>
> Partly that and partly a file management thing.  For most end users a

> .jar is one thing to deal with; it's the most recent one or it's not;

> it's present in the right location or it's not

Python byte code is like java byte code and python supports importing
from zip files like java. Since python comes with a liberal license
you can change the importing code to decrypt your modules with a
"secret" key. That will be much safer than java. Of course that won't
stop real hackers.

  Serge.

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


Re: Distributing applications

2005-03-02 Thread Serge Orlov
Jaime Wyant wrote:

> This becomes especially hairy when someone is updating from 1.0 to
> say 1.5.  Then I have to keep track of all the deltas between
> 1.0/1.5. My way is much simpler because I don't have to keep up with
> *anything*. As long as I test my code against my custom built
> distribution, it ought to JUST WORK.
>
> I don't trust myself to keep up with anything ;).

Now I follow you :) I agree that updating py2exe apps requires package
management utilities. I don't think they will be messy, it's just
more code to maintain compared to your way. You only need to track
one delta (1.0 -> 1.1 ... -> latest) and publish two files latest.exe
and update.zip

  Serge.

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


Re: Gordon McMillan installer and Python 2.4

2005-03-03 Thread Serge Orlov
Svein Brekke wrote:
> > Seriously, if you're only interested in Windows, just use py2exe,
> > or if you want Linux+Windows, try cx_Freeze.
>
> According to the command line help for cx_Freeze and py2exe, they
> cannot pack my program with additional installation files into one
> self-extracting .exe file (which is what I want to do).
>
> Am I wrong on this?

You're right, but that doesn't mean py2exe is not for you. Packing
a program, displaying a license, choosing installation directory
is not Python specific, just use a generic installer. They are better
because they have much more users than Python specific installers.
See for example http://nsis.sourceforge.net/features/featurelist/

Use py2exe to bundle python core, extentions and your program into
one directory, then use nsis to create the installator.

  Serge.

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


Re: i18n: looking for expertise

2005-03-03 Thread Serge Orlov
klappnase wrote:
> Hello all,
>
> I am trying to internationalize my Tkinter program using gettext and
> encountered various problems, so it looks like it's not a trivial
> task.

Considered that you decided to support old python versions, it's true.
Unicode support has gradually improved. If you choose to target old
python version, basically you're dealing with years old unicode
support.

> After some "research" I made up a few rules for a concept that I hope
> lets me avoid further encoding trouble, but I would feel more
> confident if some of the experts here would have a look at the
> thoughts I made so far and told me if I'm still going wrong somewhere
> (BTW, the program is supposed to run on linux only). So here is what
> I have so far:
>
> 1. use unicode instead of byte strings wherever possible. This can be
> a little tricky, because in some situations I cannot know in advance
> if a certain string is unicode or byte string; I wrote a helper
> module for this which defines convenience methods for fail-safe
> decoding/encoding of strings and a Tkinter.UnicodeVar class which I
> use to convert user input to unicode on the fly (see the code below).

I've never used tkinter, but I heard good things about it. Are you
sure it's not you who made it to return byte string sometimes?
Anyway, your idea is right, make IO libraries always return unicode.

> 3. make sure to NEVER mix unicode and byte strings within one
> expression

As a rule of thumb you should convert byte strings into unicode
strings at input and back to byte strings at output. This way
the core of your program will have to deal only with unicode
strings.

> 4. in order to maintain code readability it's better to risk excess
> decode/encode cycles than having one too few.

I don't think so. Either you need decode/encode or you don't.

> 5. file operations seem to be delicate;

You should be ready to handle unicode errors at file operations as
well as for example ENAMETOOLONG error. Any file system with path
argument can throw it, I don't think anything changed here with
introduction of unicode. For example access can return 11 (on
my linux system) error codes, consider unicode error to be twelveth.

> at least I got an error when I
> passed a filename that contains special characters as unicode to
> os.access(), so I guess that whenever I do file operations
> (os.remove(), shutil.copy() ...) the filename should be encoded back
> into system encoding before;

I think python 2.3 handles that for you. (I'm not sure about the
version)
If you have to support older versions, you have to do it yourself.


> 6. messages that are printed to stdout should be encoded first, too;
> the same with strings I use to call external shell commands.

If you use stdout as dump device just install the encoder in the
beginning of your program, something like

sys.stdout = codecs.getwriter(...) ...
sys.stderr = codecs.getwriter(...) ...


  Serge.

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


Re: Unicode error in wx_gdi ?

2005-03-04 Thread Serge Orlov
Erik  Bethke wrote:
> Hello All,
>
> I still shaking out my last few bugs in my tile matching game:
>
> I am now down to one stumper for me:
>  1) when I initialize wxPython
>  2) from an exe that I have created with py2exe
>  3) when the executable is located on the desktop as opposed to
> somewhere on C or D directly
>  4) when My Desktop is not written in ascii but instead Korean hangul
>
> I get this error:
>
> Traceback (most recent call last):
>   File "shanghai.py", line 13, in ?
>   File "wxPython\__init__.pyc", line 10, in ?
>   File "wxPython\_wx.pyc", line 3, in ?
>   File "wxPython\_core.pyc", line 15, in ?
>   File "wx\__init__.pyc", line 42, in ?
>   File "wx\_core.pyc", line 10994, in ?
>   File "wx\_gdi.pyc", line 2443, in ?
>   File "wx\_gdi.pyc", line 2340, in Locale_AddCatalogLookupPathPrefix
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xbf in position
> 26: ordinal not in range(128)
>
> Granted this may seem like an obscure error,

Thanks to your explanation, it doesn't look very obscure. I think
the code in wxpython either uses sys.path[0] or __file__. Python
still keeps byte strings in there because of backward compatibility.


> What do i do from here?  Do I go into wx_gdi.py and fix it so that it
> uses unicode instead of ascii?  I have not yet made any changes to
> other people's libraries...

You should contact wxpython people for proper cross platform fix,
meanwhile you can fix that particular error on windows
by changing sys.path[0] into
sys.path[0].decode(sys.getfilesystemencoding())
or do the same thing for __file__. If there are a lot of similar
problems, you can call sys.setdefaultencoding('mbcs') at the start of
your program as last resort. Don't tell anyone I suggested that :)
and remember that sys.setdefaultencoding is removed in site.py,
changing default encoding can mask encoding bugs and make those
bugs hard to trace.

  Serge.

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


Re: getting data with proper encoding to the finish

2005-03-14 Thread Serge Orlov
John Machin wrote:
> Ksenia Marasanova wrote:
>> Sorry, I meant: I use field of the type 'text' in a Postgres table to
>> store my data. The data is a XML string.
>>
>>> Instead of "print data", do "print repr(data)" and show us what you
>>> get. What *you* see on the screen is not much use for diagnosis;
>>> it's the values of the bytes in the file that matter.
>>
>> Thanks for this valuable tip. I take letter "é" as an example.
>>
>> "print repr(data)" shows this:
>> u'\xe9'
>
> That doesn't look like an "XML string" to me. Show the WHOLE contents
> of the field.
>
> Have you read the docs of the Perl module of which pyXLWrtiter is a
> docs-free port? Right down the end it mutters something about XML
> parsers returning UTF8 which will jam up the works if fed into an
> Excel spreadsheet ...

Looking at the following function in pyXLWriter
def _asc2ucs(s):
"""Convert ascii string to unicode."""
return "\x00".join(s) + "\x00"

I can guess several things:
a) pyXLWriter author is an ascii guy :)
b) unicode strings are not supported by pyXLWriter
c) excel keeps unicode text in utf-16le

Ksenia, try encoding unicode strings in utf-16le before passing them to
pyXLWriter . If that doesn't work that means pyXLWriter requires
changes to support unicode strings.

  Serge.


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


Re: Python becoming less Lisp-like

2005-03-15 Thread Serge Orlov
Torsten Bronger wrote:
> > Interesting.  I've never thought that.  What parts strike you as
> > "patchwork"?
>
> Well, with a little bit of experience in the field of programming
> languages, you can see which elements had been added later (ie years
> after Python's creation).  Properties surely would have looked
> *very* different 15 years ago.
>
> There would be keywords for static and class methods, no distinction
> between Unicode and non-Unicode

You couldn't do that 15 years ago because there were no Unicode that
time.

  Serge.

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


Re: Python becoming less Lisp-like

2005-03-15 Thread Serge Orlov
Fernando wrote:
> On Sun, 13 Mar 2005 18:23:05 GMT, Peter Seibel
<[EMAIL PROTECTED]>
> wrote:
>
> >Looks like the BDFL is planning to take lambda, reduce, filter, and
> >map out of Python in the next big rev of Python (so called Python
> >3000):
> >
> >  
>
> Basically, it says that it will get rid of the explicit map, filter
> and reduce and substitute them by some syntactic sugar that uses them
> implicitly. That's ok, and not a big deal.
>
> It will also get rid of lambda, and it's not a great loss, since
> python's version is so limited that it's almost useless. Besides,
> given the syntactic sugar used to replace map, reduce and filter,
> there's no real need for lambda in the most usual cases.
>
> The real problem with Python is that it has been very successful as a
> scripting language in the static-typing/C/C++ world. Those
> programmers, instead of adapting their evil ways to Python, and
> realizing the advantages of a dynamic language, are influencing
> Python's design and forcing it into the static-typing mold. Python is
> going the C++ way: piling feature upon feature, adding bells and
> whistles while ignoring or damaging its core design.

You're wrong about design: http://www.artima.com/intv/pyscale.html
Quoting Guido: The first sound bite I had for Python was, "Bridge
the gap between the shell and C." So I never intended Python to be
the primary language for programmers.


>
> The new 'perlified' syntax for decorators, the new static type bonds
> and the weird decision to kill lambda instead of fixing it are good
> examples that show that Python is going the wrong way. What used to
> be a cool language will soon be an interpreted C/C++ without any
> redeeming value. A real pity...

Yeah, that was a good time. After a nice bridge between the shell
and C was built they never ceased piling feature upon feature and
kept adding bells and wristles.

  Serge.

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


Re: unicode converting

2005-03-16 Thread Serge Orlov
Maxim Kasimov wrote:
> Christos TZOTZIOY Georgiou wrote:
> >
> > If unicode_data references your unicode data, all you have to send
is:
> >
> > unicode_data.encode('utf-16') # maybe utf-16be for network order
> >
> is utf-16 string the same ucs-2? my question is how to get string
> encoded as UCS-2

utf-16 is basically a superset of ucs-2. See here for more detail:
http://www.azillionmonkeys.com/qed/unicode.html
If you ensure that ord() of each output character is < 0x1
you'll get valid ucs-2 output if you use utf-16 encoding. If you
build python with --enable-unicode=ucs2 no character can be >= 0x1
so you don't have to check. On the other 1) you won't be able even to
input characters >= 0x1 into your application and 2) premature
optimization is bad and 3) There is a note in README: To compile
Python2.3 with Tkinter, you will need to pass --enable-unicode=ucs4
flag to ./configure

  Serge.

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


Re: getting data with proper encoding to the finish

2005-03-16 Thread Serge Orlov

Ksenia Marasanova wrote:
> John, Serge, thanks for your help!
>
> utf-16le  encoding didn't help. I had however to solve it yesterday,
> so I used csv module to create CSV file and then import it in Excel.
> Excel still had troubles with accented characters, but this is
another
> story: it seems that Office 2004 Excel (for Mac, but I assume the PC
> version is no better) cannot import UTF-8 encoded text files.

Right, I tried on windows xp, utf-8 csv file is imported as garbadge.
However, csv file saved in utf-16 encoding is imported correctly.

> Encoding
> CSV file with Latin1 encoding finally did work.
>
> Now back to the Excel story, I also think that there is something
> wrong with pyExcelWriter or the way I use it. CSV file generation was
> okay, so I think there is nothing wrong with my data,  or XML parser.
>
> I will resume in a few days with pyExcelWriter and will post the
> results here, but anyway, many thanks for your time and explanation!

I believe Microsoft Office has gone through byte strings to unicode
strings transformation between 1995 and 1997. I still remember times
when you could receive Microsoft Office file and couldn't view it.
I suspect pyExcelWriter writes strings in that old format so utf-16le
trick didn't work. You can try to contact pyExcelWriter author
and ask him about unicode support.

  Serge.

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


Re: unicode converting

2005-03-16 Thread Serge Orlov
Christos TZOTZIOY Georgiou wrote:
> On 16 Mar 2005 02:53:12 -0800, rumours say that "Serge Orlov"
> <[EMAIL PROTECTED]> might have written:
>
> >3) There is a note in README: To compile
> >Python2.3 with Tkinter, you will need to pass --enable-unicode=ucs4
> >flag to ./configure
>
> I thought this applied to Tkinter as pre-built on recent RedHat
> systems. Does it also apply to FreeBSD?

I don't know. I didn't notice that it was about RedHat.

> On Windoze, Mandrake and SuSE python has UCS-2
> unicode and Tkinter is working just fine.

Did you build python on Mandrake and SuSE yourself? I had an impression
that ucs-4 builds are prefered on Linux. At least python on RedHat EL3
and SUSE ES9 is built with --enable-unicode=ucs4.

  Serge.

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


Re: ConfigParser

2005-03-17 Thread Serge Orlov
Sergey wrote:
> Is there an alternative to standard module ConfigParser, which can
> use delimitier symbol other than ":" and "=", preferaby just space?
> I need to parse such configs:
>
> [Passwords]
> 2:5020/758 
> 2:5020/794 
>
> ConfigParser is not able to work with option names which contain
> symbol ':' It is not difficult to modify ConfigParser to resolve it,
> but may be another solution already exists?

In case you won't get a satisfying answer there is always python
package index: http://www.python.org/pypi Go to search and enter
"config" into the keyword field, you'll get seven results, looking at
description five of them are configuration file parsers.

  Serge.

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


Re: Import mechanism to support multiple Python versions

2005-03-18 Thread Serge Orlov
Nicolas Fleury wrote:
> Hi,
>   I'm trying to support two Python versions at the same time and I'm
> trying to find effective mechanisms to support modules compiled in
> C++ transparently.
>
> All my code in under a single package.  Is it possible to override
> the import mechanism only for modules under that package and
> sub-packages so that?:
>
> import cppmymodule
>
> would be equivalent to:
>
> if sys.version == "2.4":
>  import cppmymodule24 as cppmymodule
> elif sys.version == "2.3":
>  import cppmymodule23 as cppmymodule
>
> for all modules under the package and all modules with names
> beginning with cpp (or another way to identify them).

I used the following approach application-wide:
= The very start of main file ===
resolve_package_dependencies()
import package

def main():
...

# boilerplate at the end of main file
def resolve_package_dependencies():
if sys.version_info[0:2] == (2,5):
import package1
sys.modules["package"] = sys.modules["package1"]
else:
import package2
sys.modules["package"] = sys.modules["package2"]

=

I've never needed that for packages like you, but as far as I
remember package specific modules are stored like
"package.module" so aliasing "package45" with "package" in your
case will look like
sys.modules[__name__+".package"] = sys.modules[__name__+".package45"]

  Serge.

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


Re: How to pass parameter when importing a module?

2005-03-20 Thread Serge Orlov
Bo Peng wrote:
> Dear list,
>
> What I would like to do is something like:
>
> In myModule.py ( a wrapper module for different versions of the
> module),
>   if lib == 'standard':
> from myModule_std import *
>   elsif lib == 'optimized'
> from myModule_op import *
>
> but I do not know how to pass variable lib to myModule.py to achieve
> the following effect:
>
>   >>> lib = 'standard'
>   >>> from myModule import * # actually import myModule_std

[snip]

Take a look at wxPython versioning:
http://wiki.wxpython.org/index.cgi/MultiVersionInstalls

The most simple usage looks like

  import wxversion
  wxversion.select("2.4")
  import wx
  Serge. 


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


Re: IconvCodec, UTF-32 & P4 ?

2005-03-21 Thread Serge Orlov
Do Re Mi chel La Si Do wrote:
> Hi !
>
> Iconvcodec was good, for to work with UTF-32, with Python 2.3
> But, which tool, for the same use, with Python 2.4  ?
> Thanks for suggestions.

Do you mean it's impossible to build iconvcodec anymore?

  Serge.

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


Re: IconvCodec, UTF-32 & P4 ?

2005-03-21 Thread Serge Orlov
Do Re Mi chel La Si Do wrote:
> re-Hi
>
>
> When I look  http://cjkpython.i18n.org  I found only binaries for
> P2.1, P2.2 & P2.3  (I am on windows)
>
> If I run the P2.3's version, on my Python 2.4 config, the package
> said that he don't found Python2.3.
>
> And, I don't have compiler for work with source.
> If benefactor of humanity has do a binary for windows/Python 2.4,
> they would be fabulous.

OK, I've built it and it works. I'll send it to you and the author
this evening.

  Serge.

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


Re: UTF Questions

2005-03-21 Thread Serge Orlov
Fuzzyman wrote:
> I have a couple of questions about the UTF encodings.
>
> The codecs module has constants definded for the UTF32 encoding, yet
> this encoding isn't supported as a standard encoding. Why isn't it
> supported ?

Probably because there is little demand for it. The most widespread
unicode encodings are utf-8 and utf-16

>
> It possibly has something to do with my next question. I know that
> unicode has (recently?) been expanded to include new character sets.
> This means that the latest unicode standard can't be fully supported
> with 2 bytes per character. As far as I know though, Python doesn't
> (yet) support the extended version of unicode anyway ? Am I correct ?

Python does support them. PEP 261 has the answers for your questions.

  Serge.

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


Re: Save passwords in scripts

2005-03-22 Thread Serge Orlov
Florian Lindner wrote:
> Paul Rubin wrote:
>
>> - sort of similar: have a separate process running that knows the
>> password (administrator enters it at startup time).  That process
>> listens on a unix socket and checks the ID of the client.  It reveals
>> the password to authorized clients, i.e. your readable script running
>> under sudo.  This keeps the password from ever being stored on disk.
>>
>> - Modify the script itself to run as a long-running service instead
>> of as something that gets started and restarted all the time.  Have
>> an admin start it and type the password into it at startup time.
>> Users then connect to it (maybe with a web browser) and send it
>> commands.
>>
>> - Move the user operations from the script to server side database
>> procedures that do their own validity checking.  Then you don't need
>> a password.
>
> I'll evaluate the 3 ideas above further.

I'm surprised there are no building blocks for a sudo replacement
in the UNIX world, at least I googled and couldn't find them.
Basically you need to split you script into two parts: priveledged
server and user client. They can talk xml-rpc over unix socket.
If you need performance you can also open another socket
for sending huge binary objects.

With regards to clear text password and admin, you can only
obfuscate or make it hard to obtain the password. It's just to
keep honest admins honest. Same story on windows, btw.

  Serge.


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


Re: UTF Questions

2005-03-22 Thread Serge Orlov
Fuzzyman wrote:
> Thanks Serge.

You're welcome. While we at it, iconvcodec supports utf-32 and more. I have sent
a 2.4 windows build of iconvcodec module to the author. He promised to publish 
it
soon.

  Serge.


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


Re: cross platform use of set locale

2005-03-23 Thread Serge Orlov
Timothy Smith wrote:
> thats ok, but how do i get it to group thousands with a , ?
> and thats would mean i'd have to run everything through a formatter
> before i displayed it :/ it'd be nicer if i could just select a
> proper locale

I think you're misusing locale. There is no guarantee that any specific
locale will have properties (like grouping) set to a known value.
Are you trying to format money? Then you need a special class so that
you can say:

d = Dollars(100.01)
print "You have %s in your account" % d

and get

You have $1,000,000.01 in your account.

  Serge.

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


Re: cross platform use of set locale

2005-03-23 Thread Serge Orlov
Timothy Smith wrote:
> Serge Orlov wrote:
>
> >Timothy Smith wrote:
> >
> >
> >>thats ok, but how do i get it to group thousands with a , ?
> >>and thats would mean i'd have to run everything through a formatter
> >>before i displayed it :/ it'd be nicer if i could just select a
> >>proper locale
> >>
> >>
> >
> >I think you're misusing locale. There is no guarantee that any
> >specific locale will have properties (like grouping) set to a known
> >value. Are you trying to format money? Then you need a special class
> >so that you can say:
> >
> >d = Dollars(100.01)
> >print "You have %s in your account" % d
> >
> >and get
> >
> >You have $1,000,000.01 in your account.
> >
> >  Serge.
> >
> >
> >
> thats exactly what i'm trying to do, only having to do that for all
> my outputs is more work then i'd like :/

SUS has added numeric grouping

   For  some  numeric conversions a radix character (`decimal
   point') or thousands'  grouping  character  is  used.  The
   actual  character  used  depends on the LC_NUMERIC part of
   the locale. The POSIX locale uses `.' as radix  character,
   and does not have a grouping character.  Thus,
   printf("%'.2f", 1234567.89);
   results   in   `1234567.89'   in   the  POSIX  locale,  in
   `1234567,89' in the nl_NL locale, and in `1.234.567,89' in
   the da_DK locale.

but they hasn't added monetary grouping. I don't think you'll
get monetary grouping anytime soon. Besides as far as I understood
your question, you *always* want grouping, right?

Actually I don't think a cryptic flag is better than an explicit
formatter. What do you think is more clear for a maintainer of your
code?

print "%'.2f" % amount

or

print "%s" % dollars(amount)





> why is this a misuse of locale? it's exactly what locale is meant for
> isn't it?

I just reacted to your words "select a proper locale" and "how do i get
it to group thousands with a ,". It's just not a good idea to select
a locale and expect the grouping character to be "," or expect
grouping,
see nl_NL locale example above.

  Serge.

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


Re: Interface selection

2005-03-25 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
> Actually its not a server. I dont do any binding call, just a
connect.

Bind is not only for server sockets. Googling for "bind client socket"
reveals an example: http://woozle.org/~neale/papers/sockets.html

  Serge.

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


Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Serge Orlov
Michael Spencer wrote:
> > Still, this is fascinating going to have to spend some time
> > experimenting with groupby as soon as I get a chance
> >
> Experimenting is good.  So is the the documentation:
> http://docs.python.org/tut/tut.html

Reading documentation is a good idea, but I think your example would
be more clear for Jordan if you used function attributes:

def record(item):
 if len(item) > 20:
 record.seq +=1
 return record.seq
record.seq = 0

  Serge.

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


Re: Once again a unicode question

2005-03-26 Thread Serge Orlov
Nicolas Evrard wrote:
> Hello,
>
> I'm puzzled by this test I made while trying to transform a page in
> html to plain text. Because I cannot send unicode to feed, nor str so
> how can I do this ?

Seems like the parser is in the broken state after the first exception.
Feed only binary strings to it.

  Serge.


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


Re: Cross platform distribution of standalone executable

2005-03-27 Thread Serge Orlov
Mahesh wrote:
> Hi,
>
> One of my clients does not want the Python VM installed on his
> production machine (because it is not a supported IT language) so the
> only way I can program in Python and release the application to him is
> to make a standalone executable and deploy it. The last time I looked
> at something like this, Macmillan installer was a good contender but
> now that website seems to be AWOL.
>
> Are there any alternate installers out there? Googling didn't bring up
> any other maintained installer.
>
> This installer should be able to build on Windows, Linux and AIX.

Take a look at cx_Freeze:
http://starship.python.net/crew/atuining/cx_Freeze/

  Serge.


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


Re: Save passwords in scripts

2005-03-29 Thread Serge Orlov
Florian Lindner wrote:
> Serge Orlov wrote:
>
>> Florian Lindner wrote:
>>> Paul Rubin wrote:
>>>
>>>> - sort of similar: have a separate process running that knows the
>>>> password (administrator enters it at startup time).  That process
>>>> listens on a unix socket and checks the ID of the client.  It
>>>> reveals the password to authorized clients, i.e. your readable
>>>> script running under sudo.  This keeps the password from ever
>>>> being stored on disk.
>>>>
>>>> - Modify the script itself to run as a long-running service instead
>>>> of as something that gets started and restarted all the time.  Have
>>>> an admin start it and type the password into it at startup time.
>>>> Users then connect to it (maybe with a web browser) and send it
>>>> commands.
>>>>
>>>> - Move the user operations from the script to server side database
>>>> procedures that do their own validity checking.  Then you don't
>>>> need a password.
>>>
>>> I'll evaluate the 3 ideas above further.
>>
>> I'm surprised there are no building blocks for a sudo replacement
>> in the UNIX world, at least I googled and couldn't find them.
>> Basically you need to split you script into two parts: priveledged
>> server and user client. They can talk xml-rpc over unix socket.
>
> Can I find out the identity of the client (PID/UID) when using unix
> socket?

Paul Rubin has answered this question. And as far as I know, not all
unix OSes support that.  But you can do the following: create a security
group, add people to that group and create the socket that is owned
by the server process and accessible only by the people in that special
group.

  Serge.


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


Re: Secure scripts variables

2005-03-29 Thread Serge Orlov
Florian Lindner wrote:
> Hello,
> given the following situation:
>
> I have a script which is readable and executable by a user, but not
> writable.
> The users executes the scripts, it reads in a value and based on this
> value  it computes a result and stores it in a variable.
> Can the user read out the value of this variable?

Yes.

> If yes, can he be prevented to do so?

Only if the sensitive part of your script runs under different
user. See thread about storing passwords in a script:

http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/91e4c114c5114e92


> (It's a ordinary user on a Linux system with access to the python
> interpreter.)

If there is a will, there is a way :) I used to run a persistant server
on Solaris as ordinary user. The trick is to create an entry in crontab
that will periodically (every 10 minutes) check if your server is
running, if not, start it up. Note however, after that it's not a good
idea to keep sensitive files in your home directory (like your tax
forms or browsing history), because if you make an error in your server
and it will be hacked, then you risk exposing all your files.


  Serge.

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


Re: Problem in designing a global directory in python

2005-03-30 Thread Serge Orlov
Tian wrote:
> I have tried using "sysctx=None" instead of "global sysctx", but it
> doesn't work either.
> It seems my initialization work in the previous calling of init() has
> no persistent effect when "utils" is imported using "from
> myproj.utils import getContext".
>
> What's weird, when a module is in the same directory as utils.py,
> where I can simply use "utils" for importing, there is no such
> problem.
>
> Any other suggestions?

put the following print statement next to every "global sysctx"
replacing ... with the function name where the statement is located.

print "... globals are in %s" % __name__

  Serge.

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


Re: distutils: package data

2005-03-30 Thread Serge Orlov
Qiangning Hong wrote:
> ehh..  I did a little more reading and found that this function can
> be easily done by the new distutils parameter "package_data" in 2.4.
>
> However, I am using python2.3 :(
>
> So, my question becomes: how to emulate the package_data function in
> python 2.3?

There is distutils.sysconfig.get_python_lib() that works at least
since 2.2:

>>> from distutils import sysconfig
>>> sysconfig.get_python_lib()
'/usr/lib/python2.2/site-packages'

>>> from distutils import sysconfig
>>> sysconfig.get_python_lib()
'/usr/lib64/python2.3/site-packages'

>>> from distutils import sysconfig
>>> sysconfig.get_python_lib()
'c:\\python24\\Lib\\site-packages'

  Serge.

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


Re: LD_LIBRARY_PATH - how to set?

2005-03-31 Thread Serge Orlov
Roman Yakovenko wrote:
> Hi. I have small problem. I need to load extension module that
depends
> on shared library. Before actually importing module I tried to edit
> os.environ or to call directly to os.putenv without any success -
> shared library was not found. I tried to search the Internet for the
> answer. The only approach I saw was to set LD_LIBRARY_PATH before
> invoking python script. I don't like this solution.

Looks like it's glibc linker inflexibility:
http://hathawaymix.org/Weblog/2004-12-30
"""
There is no provision for modifying the library search path once your
program has started.
"""

Python does update enviromental variables if you change os.environ or
call os.putenv, but the linker ignores the changes.

  Serge.

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


Re: UnicodeEncodeError in string conversion

2005-03-31 Thread Serge Orlov

Maurice LING wrote:
> Hi,
>
> I'm working on a script that searches a public database and retrives
> results using SOAP interface. However, it seems that the results may
> contains unicodes. When I try to pump the results into Firebird
database
> using kinterbasdb module, some results will give me a
> UnicodeEncodeError. From what I've gathered, it looks like the
> conversion from the results from SOAP interface to string results in
the
> error.
>
> Is there any way to get thru this?

Have you read this FAQ entry:
http://kinterbasdb.sourceforge.net/dist_docs/usage.html#faq_fep_unicode
??

  Serge.

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


Re: Installing Python on a Windows 2000 Server

2005-04-02 Thread Serge Orlov
Mike Moum wrote:
> Hi,
>
> I'm a civil engineer who also doubles as chief programmer for
> technical applications at my company. Most of our software is written
> in Visual Basic because our VP in charge of I.T. likes to have
> "consistency", and at the moment we're a Microsoft shop. He has
> assigned me the task of developing an new application, the exact
> nature of which is not important for my question. I told him that, in
> my opinion, that Visual Basic was not the best choice for developing
> this application, and that I wanted to use Python. After a bit of
> discussion of the pros and cons, he said to go ahead. I managed to
> keep my jaw from hitting the floor. :>)
> We have a central server array running Windows Server 2000 (I think
> that's the right name; networking is not my specialty, but it's
> definately Windows). Some of our workstations run Windows 2000; others
> run Windows XP Pro. I would like to install Python on the server, and
> run the application that I'll be developing from the workstations,
> without having to install any Python components on the workstations
> themselves. In other words, the Python executable, and the various
> libraries, dll's, and what have you, as well as the application that
> I'm developing, should all reside on the server. The only thing on the
> workstations would be a shortcut to myapplication.py.
>
> Does anyone know whether it is possible to do this? I've done some
> Google searching, with no conclusive results, and poked about on
> python.org, but haven't really been able to find anything. Normally
> I'd be happy to just try it out and see what happens, but we're
> breaking new ground here (this is an amazingly big step for our
> hide-bound IS department!), so I'd like everything to go as smoothly
> as possible.

Try Movable Python http://www.voidspace.org.uk/python/movpy/
When you will be creating a shortcut to you application it shouldn't
point to yourapplication.py directly but rather at
\\yourserver\movpy\movpyw.exe \\yourserver\yourapp\yourapplication.py

  Serge.


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


Re: the bugs that try men's souls

2005-04-03 Thread Serge Orlov
Sean McIlroy wrote:
> This needs some background so bear with me.
>
> The problem: Suppose p is a permutation on {0...n} and t is the
> transposition that switches x and y [x,y in {0...n}]. A "stepup pair"
> (just a term I invented) for p is a pair (a,b) of integers in {0...n}
> with a of p iff (p(a),p(b)) is NOT a stepup pair. Now, if {a,b}={x,y}, then
> clearly (a,b) is an inversion of p iff it is NOT an inversion of pt
> (functional composition). Also, if {a,b} and {x,y} are disjoint, then
> (a,b) is an inversion of p iff it is an inversion of pt. The remaining
> cases are the ones where {a,b} and {x,y} have a single element in
> common, and of these, there are exactly as many inversions of p as
> there are of pt, though in general it is not the same set of stepup
> pairs for each function.
>
> The code below represents my attempt to apply python toward getting
> insight into why the number of inversions, with exactly one coordinate
> in {x,y}, is the same for p and pt. The problem with the code is that
> if, at the relevant line ("MYSTERIOUSLY BROKEN"), I use the
> commented-out expression instead of the expression that's actually
> there, then in some cases the script gives a DIFFERENT ANSWER to the
> question whether a given pair is or is not an inversion of p
> respectively pt.

[snip the code]

Can you post a unit test that fails? Otherwise it's not clear what you mean
by saying "mysteriously broken" and "different answer".

  Serge.


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


Re: redundant imports

2005-04-03 Thread Serge Orlov
Mike Meyer wrote:

> The semantic behavior of "include" in C is the same as "from module
> import *" in python. Both cases add all the names in the included
> namespace directly to the including namespace. This usage is
> depreciated in Python ...

 Did you mean discouraged? Or it's really slated for deprecation?

  Serge.


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


Re: why not in python 2.4.3

2006-05-28 Thread Serge Orlov
Rocco wrote:

> >>> import sys
> >>> sys.getdefaultencoding()
> 'latin_1'

Don't change default encoding. It should be always ascii.

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


Re: q - including manpages in setup.py

2006-05-28 Thread Serge Orlov
aum wrote:
> Hi,
>
> What is the best way to incorporate manpages in a distutils setup.py
> script?
>
> Is there any distro-independent way to find the most appropriate place to
> put the manpages?
> For instance, /usr/man/? /usr/share/man? /usr/local/man?
> /usr/local/share/man?

What do you mean distro? Linux? That should be /usr/local/man but AFAIK
some distros are misconfigured and their man doesn't search /usr/local
by default, YMMV.

> Also - I've got .html conversions of the manpages, for the benefit of OSs
> such as Windows which don't natively support manpages. What's the best
> place to put these?

your_tool --html-manual that uses os.start or webbrowser module to
invoke html viewer. Or your_tool --man that dumps plain text on the
screen.

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


Re: iteration over non-sequence ,how can I resolve it?

2006-05-28 Thread Serge Orlov
python wrote:
> To BJörn Lindqvist :
>  thank you . how to write the code specifically ?Could you give a
> example?

Use Queue module:

import threading
from Queue import Queue

class PrintThread(threading.Thread):
  def __init__(self, urlList, results_queue):
threading.Thread.__init__(self)
urllist=[]
self.urllist=urlList
self.results_queue = results_queue
  def run(self):
urllink=[self.urllist] * 2
self.results_queue.put(urllink)

results = Queue()
threadList = []
for i in range(0,2):
thread=PrintThread("Thread"+str(i), results)
threadList.append(thread)
thread.start()

for i in threadList:
linkReturned = results.get()
for j in linkReturned:
print j

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


Re: why not in python 2.4.3

2006-05-29 Thread Serge Orlov
Rocco wrote:
> Also with ascii the function does not work.

Well, at least you fixed misconfiguration ;)

Googling for 1F8B (that's two first bytes from your strange python 2.4
result) gives a hint: it's a beginning of gzip stream. Maybe urllib2 in
python 2.4 reports to the server that it supports compressed data but
doesn't decompress it when receives the reply?

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


Re: saving settings

2006-05-29 Thread Serge Orlov
SuperHik wrote:
> aum wrote:
> > On Mon, 29 May 2006 09:05:36 +0200, SuperHik wrote:
> >
> >> Hi,
> >>
> >> I was wondering how to make a single .exe file, say some kind od clock,
> >> and be able to save some settings (alarm for example) into the same
> >> file? Basically make code rewrite it self...
> >>
> >> thanks!
> >
> > Yikes!!!
> >
> > I'd strongly suggest you read the doco for ConfigParser, and load/save
> > your config file to/from os.path.join(os.path.expanduser("~")).
> >
> > Another option - save your stuff in the Windows Registry
> >
>
> but if I copy this file on the other computer settings will be lost...

Put your program in a writable folder and save configuration right into
that folder. Then your can transfer the whole folder. Tip: sys.path[0]
always contains the path to the directory where "__main__" module is
located.

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


Re: why not in python 2.4.3

2006-05-29 Thread Serge Orlov
John Machin wrote:
> On 29/05/2006 10:47 PM, Serge Orlov wrote:
> > Maybe urllib2 in
> > python 2.4 reports to the server that it supports compressed data but
> > doesn't decompress it when receives the reply?
> >
>
> Something funny is happening here. Others reported it working with 2.4.3
> and Rocco's original code as posted in this thread -- which works for me
> on 2.4.2, Windows XP.

It "works" for me too, returning raw uncompressed data.

> There was one suss thing about Rocco's problem description:
> First message ended with  d=takefeed(url)
> But next message said print rss
> Is rss == d?

Nope. If you look at html tags, 2.3 code returns   ...
whereas 2.4 code returns... That may
explain why 2.3 result is not compressed and 2.4 result is compressed,
but that doesn't explain why 2.4 *is* compressed. I looked at python
2.4 httplib, I'm sure it's not a problem, quote from httplib:

# we only want a Content-Encoding of "identity" since we
don't
# support encodings such as x-gzip or x-deflate.

I think there is a web accellerator sitting somewhere between Rocco and
Google server that is confused that Rocco is "misinforming" web server
saying he's using Firefox, but at the same time claiming that he cannot
handle compressed data. That's why they teach little kids: don't lie :)

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


Re: Is anybody knows about a linkable, quick MD5/SHA1 calculator library ?

2006-05-30 Thread Serge Orlov
DurumDara wrote:
> Hi !
>
> I need to speedup my MD5/SHA1 calculator app that working on
> filesystem's files.
> I use the Python standard modules, but I think that it can be faster if
> I use C, or other module for it.
>
> I use FSUM before, but I got problems, because I "move" into "DOS area",
> and the parameterizing of outer process maked me very angry (not working).
> You will see this in this place:
> http://mail.python.org/pipermail/python-win32/2006-May/004697.html

FWIW I looked at what is the problem, apparently fsum converts the name
back to unicode, tries to print it and silently corrupts the output.
You give it short name XA02BB~1 of the file xAÿ and fsum prints xA

Use python module or try another utility.

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


Re: Are ActivePython scripts compatible with Linux?

2006-05-31 Thread Serge Orlov
A.M wrote:
> I am planning to develop python applications on windows and run them on
> Linux.

> "Larry Bates" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Short answer: yes

A.M wrote:
> Thanks alot Larry for your comprehensive answer.

Small addition: test, test, test. This is the only way to make sure
your program works on another platform. VMware is offering now free
virtual machine emulator, vmplayer. You have no excuse not to install
linux! :) If you have dual-core processor or an idle machine you can
even setup http://buildbot.sf.net to continuously test your source code
changes.

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


Re: py2exe & qt4/qimage

2006-06-01 Thread Serge Orlov
aljosa wrote:
> i'm trying to convert python (image resizer script using PyQt4) script
> to exe but support for jpeg and tiff image formats is located in
> Qt4.1\plugins\imageformats (dll files) and when script is converted
> exe file doesn't support jpeg and tiff.
>
> i tryed using all file formats in
> script:
> tmp1 = QImage('images/type.bmp')
> tmp2 = QImage('images/type.gif')
> tmp3 = QImage('images/type.jpg')
> tmp4 = QImage('images/type.png')
> tmp5 = QImage('images/type.tif')
>
> but it doesn't work when i convert script to exe.
> any tips on howto include jpeg and tiff image formats support in exe?

You need bundle the plugins as data files:
http://docs.python.org/dist/node12.html

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


Re: struct: type registration?

2006-06-01 Thread Serge Orlov
Giovanni Bajo wrote:
> John Machin wrote:
> > I am an idiot, so please be gentle with me: I don't understand why you
> > are using struct.pack at all:
>
> Because I want to be able to parse largest chunks of binary datas with custom
> formatting. Did you miss the whole point of my message:
>
> struct.unpack("3liiSiiShh", data)

Did you want to write struct.unpack("Sheesh", data) ? Seriously, the
main problem of struct is that it uses ad-hoc abbreviations for
relatively rarely[1] used functions calls and that makes it hard to
read.

If you want to parse binary data use pyconstruct


[1] Relatively to regular expression and string formatting calls.

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


Re: struct: type registration?

2006-06-02 Thread Serge Orlov
John Machin wrote:
> On 2/06/2006 4:18 AM, Serge Orlov wrote:
> > If you want to parse binary data use pyconstruct
> > <http://pyconstruct.wikispaces.com/>
> >
>
> Looks promising on the legibility and functionality fronts. Can you make
> any comment on the speed?

I don't know really. I used it for small data parsing, its performance
was acceptable. As I understand it is implemented right now as pure
python code using struct under the hood. The biggest concern is the
lack of comprehensive documentation, if that scares you, it's not for
you.

> Reason for asking is that Microsoft Excel
> files have this weird "RK" format for expressing common float values in
> 32 bits (refer http://sc.openoffice.org, see under "Documentation"
> heading). I wrote and support the xlrd module (see
> http://cheeseshop.python.org/pypi/xlrd) for reading those files in
> portable pure Python. Below is a function that would plug straight in as
> an example of Giovanni's custom unpacker functions. Some of the files
> can be very large, and reading rather slow.

I *guess* that the *current* implementation of pyconstruct will make
parsing slightly slower. But you have to try to find out.

> from struct import unpack
>
> def unpack_RK(rk_str): # arg is 4 bytes
>  flags = ord(rk_str[0])
>  if flags & 2:
>  # There's a SIGNED 30-bit integer in there!
>  i, = unpack('  i >>= 2 # div by 4 to drop the 2 flag bits
>  if flags & 1:
>  return i / 100.0
>  return float(i)
>  else:
>  # It's the most significant 30 bits
>  # of an IEEE 754 64-bit FP number
>  d, = unpack('  if flags & 1:
>  return d / 100.0
>  return d

I had to lookup what < means :) Since nobody except this function cares
about internals of RK number, you don't need to use pyconstruct to
parse at bit level. The code will be almost like you wrote except you
replace unpack('http://mail.python.org/mailman/listinfo/python-list


Re: Freezing a static executable

2006-06-05 Thread Serge Orlov
Will Ware wrote:
> I am trying to freeze a static executable. I built a static Python
> executable this way:
> ./configure --disable-shared --prefix=/usr/local
> make
> make install
> Even that didn't give me a really static executable, though:

AFAIK it's not supported because the interpreter won't be able to load
C extensions if compiled statically. There is a bootstrap issue, to
build a static python executable you need extensions built but to build
extensions you need python, so you need unconventional build procedure.

After python build is finished you get static library libpython2.4.a.
Then you need all extensions you're going to use built as .a files (I'm
not even sure there is a standard way to do it). Then you need to write
a loader like in py2exe, exemaker, pyinstaller, etc that will
initialize python interperter and extensions. Those three pieces
(libpython2.4.a, extensions, loader) can be linked as a static
executable.


> What stupid thing am I doing wrong?

You are just trying to do something nobody was really interested to
implement.

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


Re: is it possible to find which process dumped core

2006-06-05 Thread Serge Orlov
su wrote:
> to find which process dumped core at the promt we give
>
> $ file core.28424
>
> core.28424: ELF 32-bit LSB core file of 'soffice.bin' (signal 11),
> Intel 80386, version 1 (SYSV), from 'soffice.bin'
>
> from this command we know 'soffice.bin' process dumped core. Now can i
> do the same using python i.e. finding which process dumped core?  if so
> how can i do it?

Parse a core file like the file command does?

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


Re: Get EXE (made with py2exe) path directory name

2006-06-05 Thread Serge Orlov

Andrei B wrote:
> I need to get absolute path name of a file that's in the same dir as
> the exe, however the Current Working Directory is changed to somthing
> else.
>

Use sys.path[0]

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


Re: Getting start/end dates given week-number

2006-06-09 Thread Serge Orlov
Tim Chase wrote:
> I've been trying to come up with a good algorithm for determining
> the starting and ending dates given the week number (as defined
> by the strftime("%W") function).

I think you missed %U format, since later you write:

> My preference would be for a Sunday->Saturday range rather than a
> Monday->Sunday range.  Thus,

> Any thoughts/improvements/suggestions would be most welcome.

If you want to match %U:

def weekBoundaries(year, week):
 startOfYear = date(year, 1, 1)
 week0 = startOfYear - timedelta(days=startOfYear.isoweekday())
 sun = week0 + timedelta(weeks=week)
 sat = sun + timedelta(days=6)
 return sun, sat

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


Re: Intermittent Failure on Serial Port

2006-06-10 Thread Serge Orlov
H J van Rooyen wrote:
> Traceback (most recent call last):
>   File "portofile.py", line 232, in ?
> ret_val = main_routine(port, pollstruct, pfifo)
>   File "portofile.py", line 108, in main_routine
> send_nak(port, timeout)  # so bad luck - comms error
>   File "/home/hvr/Polling/lib/readerpoll.py", line 125, in send_nak
> port.flush()
> IOError: [Errno 29] Illegal seek
> close failed: [Errno 29] Illegal seek
>


> Where can I find out what the Errno 29 really means?
> Is this Python, the OS or maybe hardware?

It is from kernel: grep -w 29 `locate errno`
/usr/include/asm-generic/errno-base.h: #define   ESPIPE  29
 /* Illegal seek */

man lseek:

ERRORS:
ESPIPE fildes is associated with a pipe, socket, or FIFO.

RESTRICTIONS:
Linux  specific  restrictions:  using  lseek  on  a  tty device
returns ESPIPE.

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


Re: Intermittent Failure on Serial Port

2006-06-11 Thread Serge Orlov
H J van Rooyen wrote:
> Serge Orloff wrote:
>
> | H J van Rooyen wrote:
> | > Traceback (most recent call last):
> | >   File "portofile.py", line 232, in ?
> | > ret_val = main_routine(port, pollstruct, pfifo)
> | >   File "portofile.py", line 108, in main_routine
> | > send_nak(port, timeout)  # so bad luck - comms error
> | >   File "/home/hvr/Polling/lib/readerpoll.py", line 125, in send_nak
> | > port.flush()
> | > IOError: [Errno 29] Illegal seek
> | > close failed: [Errno 29] Illegal seek
> | >
> |
> |
> | > Where can I find out what the Errno 29 really means?
> | > Is this Python, the OS or maybe hardware?
> |
> | It is from kernel: grep -w 29 `locate errno`
> | /usr/include/asm-generic/errno-base.h: #define   ESPIPE  29
> |  /* Illegal seek */
> |
> | man lseek:
> |
> | ERRORS:
> | ESPIPE fildes is associated with a pipe, socket, or FIFO.
> |
> | RESTRICTIONS:
> | Linux  specific  restrictions:  using  lseek  on  a  tty device
> | returns ESPIPE.
>
>
> Thanks for the info - so the Kernel sometimes bombs me out - does anybody know
> why the python flush sometimes calls lseek?

I thought it was your own flush method. If it is file.flush method that
makes the issue more complicated, since stdlib file.flush doesn't call
lseek method. I suggest you run your program using strace to log system
calls, without such log it's pretty hard to say what's going on. The
most interesting part is the end, but make sure you have enough space
for the whole log, it's going to be big.

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


Re: Intermittent Failure on Serial Port (Trace Result)

2006-06-12 Thread Serge Orlov
H J van Rooyen wrote:

> Note that the point of failure is not the same place in the python file, but 
> it
> is according to the traceback, again at a flush call...

Yes, traceback is bogus. Maybe the error is raised during garbage
collection, although the strace you've got doesn't show that. The main
reason of the failure seems to be a workaround in python's function
new_buffersize, it doesn't clear errno after lseek and then this errno
pops up somewhere else. There are two places I can clearly see that
don't clear errno: file_dealloc and get_line. Obviously this stuff
needs to be fixed, so you'd better file a bug report. I'm not sure how
to work around this bug in the meantime, since it is still not clear
where this error is coming from. Try to pin point it. For example, if
your code relies on garbage collection to call file.close, try to close
all files in your program explicitly. It seems like a good idea anyway,
since your program is long running, errors during close are not that
significant. Instead of standard close I'd call something like this:

def soft_close(f):
try:
f.close()
except IOError, e:
print >>stderr, "Hmm, close of file failed. Error was: %s" %
e.errno

> The "close failed" is explicable - it seems to happen during closedown, with 
> the
> port already broken..,

It is not clear who calls lseek right before close. lseek is called by
new_buffersize that is called by file.read. But who calls file.read
during closedown?

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


Re: embedded python and windows multi threading, can't get it to work

2006-06-13 Thread Serge Orlov
freesteel wrote:
> I am trying to run a python programme embedded from C++. I want to run
> the same python code concurrently in several threads. I read the manual
> on embedding, especially chapter 8, and searched for relevant info on
> google all afternoon, but I can't get this to work. What am I doing
> wrong? I use python2.4 and vc++7 (.net). The first thread seems to work
> okay, the 2nd thread crashes, but the exception information is not very
> useful:
> (An unhandled exception of type 'System.NullReferenceException'
> occurred in pyembed_test.exe

Running one iterpreter in more than one thread is not supported. You
need to create one interpreter per thread using Py_NewInterpreter
(don't forget to read "Bugs and caveats" paragraph). I hope you also
realize the interpreters won't share objects.

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


[OT] Re: Python open proxy honeypot

2006-06-13 Thread Serge Orlov
Alex Reinhart wrote:
> Being deluged by spam like nearly all of us (though fortunately I have a
> very good spam filter), I also hate spam as much as almost everybody. I
> know basic Python (enough to make a simple IRC bot) and I figured a good
> project to help learn Python would be to make a simple "proxypot."
>
> I've done some research and found one already existing, written in Perl
> (http://www.proxypot.org/). However, I prefer the syntax and ease of
> Python (and Proxypot is no longer maintained, as far as I can see), so I
> decided to write my own. I have just one question:
>
> Is running Python's built-in smtpd, pretending to accept and forward all
> messages, enough to get me noticed by a spammer, or do I have to do
> something else to "advertise" my script as an open proxy?
>
> I'm hoping to make this proxy script "distributed", in that several
> honeypots are run on different servers, and the results are then
> collected on a central server that provides statistics and a listing of
> all spammers caught. So, just out of curiosity, I'd like to know how
> many people would actually be willing to run a honeypot on their server,
> and how many are opposed to the idea (just so I know if the concept is
> even valid).

IMHO it's pretty useless, spammers are starting to use botnets, and the
more you make inconvenient to them use open proxies, the more of them
will move to closed botnets.

My spam folder at gmail is not growing anymore for many months (it is
about 600-700 spams a month). Have spammers given up spamming gmail.com
only or is it global trend?

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


  1   2   3   >