Re: Regular expression

2008-06-19 Thread Soltys

Hi,
Your post is not about re, but about encoding, next time
be more careful when choosing topic for your post!
Did you check what pep0263 says about encoding?
One of the first thins it says is:

"(...)
Defining the Encoding
Python will default to ASCII as standard encoding if no other
encoding hints are given.
(...)"

So when you're using non ASCII characters you should always
specify encoding. Here again, read pep0263 for how this can
be done, especially section Defining Encoding, where there
are multiple ways of doing that.


Sallu pisze:

Hi All,
here i have on textbox in which i want to restrict the user to not
enter the 'acent character' like ( é )
i wrote the program

import re
value="this is Praveen"
#value = 'riché gerry'
if(re.search(r"^[A-Za-z0-9]*$",value)):
  print "Not allowed accent character"
else:
  print "Valid"

output :

sys:1: DeprecationWarning: Non-ASCII character '\xc3' in file regu1.py
on line 3, but no encoding declared; see 
http://www.python.org/peps/pep-0263.html
for details
Valid

when i make comment #value="this is Praveen" and released comment
value = 'riché gerry'
but still i am getting same output even it have accent character.



--
Soltys

"Free software is a matter of liberty not price"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression

2008-06-20 Thread Soltys

Duncan Booth pisze:

Sallu <[EMAIL PROTECTED]> wrote:

string = 'riché'

...

unicode(string)).encode('ASCII', 'ignore')

...

Output :

sys:1: DeprecationWarning: Non-ASCII character '\xc3' in file regu.py
on line 4, but no encoding declared; see
http://www.python.org/peps/pep-0263.html for details
riché
Traceback (most recent call last):
  File "regu.py", line 13, in ?
msg=strip_accents(string)
  File "regu.py", line 10, in strip_accents
return unicodedata.normalize('NFKD',
unicode(string)).encode('ASCII', 'ignore')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
4: ordinal not in range(128)


The problem is the expression: unicode(string) which is equivalent to 
saying string.decode('ascii')


The string contains a non-ascii character so the decode fails. You should 
specify whatever encoding you used for the source file. From the error 
message it looks like you used utf-8, so "string.decode('utf-8')" should 
give you a unicode string to work with.





Or just specify source encoding like that:
#!/usr/bin/python
# -*- coding: utf-8 -*-

or

#!/usr/bin/python
# coding=utf-8



--
Soltys

"Free software is a matter of liberty not price"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for Conferences/Events on Django, Python, MySQL, etc in Europe 2008?

2008-04-08 Thread Soltys
> Greetings!
> 
> I'm looking for conferences or events about Python, Django, Dabatases,
> Mysql,
> PHP, Ruby in Europe (or nearby locations like north africa and middle
> east) in 2008.
> Do you have any suggestions?
> 
> Thanks a lot!

Hello,

Every year starting from 2007 in April there's a RuPy (www.rupy.eu)
conference in Poznan (Poland). Unfortunately this year's registration
has already finished (on April 7th). Nevertheless you could always
give it a try and contact organizers :)

And of course there's EuroPython in Vilnius (Lithuania), more
can be found on http://www.europython.org/community

Any other information can be found on
http://www.python.org/community/workshops/

Regards,
Soltys
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: about a head line

2008-04-17 Thread Soltys
Penny Y. pisze:
>  I saw some scripts have a line at its begin:
> 
> # encoding:gb2312
> 
> what's this? Why need it? thanks.
> 

Have a look at PEP-0263 (http://www.python.org/dev/peps/pep-0263/)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set proxy for a python script to run

2008-04-18 Thread Soltys
Adam pisze:
> Hi, everyone, I am using /usr/share/system-config-language/
> language_gui.py in Python.
> For some reason I have to bypass the firewall using a proxy. I read
> the urllib reference and set http_proxy="my proxy". But it didn't
> work. Is there anyway that we can set the proxy?


I did sth. like this:

proxy_url = "http://user:[EMAIL PROTECTED]:8080"
proxy_support = urllib2.ProxyHandler({'http': proxy_url})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
src = urllib2.urlopen(url)

now you can easily read from src.

-- 
Soltys

"Free software is a matter of liberty not price"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to log messages _only once_ from all modules ?

2009-11-24 Thread Soltys

Barak, Ron pisze:

Hi,

I'm trying to add the logging module to my application, but I seem to be 
missing something.
My application (a wxPython one) has a main script that calls various helper 
classes.
I want the log messages from all modules to go to one central log file.

When I implement logging, I think that due to preparation, I get the same 
message more than once.

Here's an example:

$ cat -n server.py
 1  import logging
 2  import logging.handlers
 3
 4  class Server():
 5  def __init__(self):
 6  self.client_logger = logging.getLogger("client")
 7  self.client_logger.setLevel(logging.DEBUG)
 8  h = logging.FileHandler("client.log")
 9  h.setLevel(logging.DEBUG)
10  formatter = logging.Formatter("%(asctime)s %(name)-12s 
%(levelname)-8s %(message)s")
11  h.setFormatter(formatter)
12  self.client_logger.addHandler(h)
13
14  def util(self):
15  self.client_logger.warning('This message comes from Server 
module')

$ cat -n client.py
 1  import logging
 2  import logging.handlers
 3  from server import Server
 4
 5  class Client():
 6  def __init__(self):
 7  self.client_logger = logging.getLogger("client")
 8  self.client_logger.setLevel(logging.DEBUG)
 9  h = logging.FileHandler("client.log")
10  h.setLevel(logging.DEBUG)
11  formatter = logging.Formatter("%(asctime)s %(name)-12s 
%(levelname)-8s %(message)s")
12  h.setFormatter(formatter)
13  self.client_logger.addHandler(h)
14
15  def client_test(self):
16  self.client_logger.warning("This message comes from Client 
module")
17
18  if __name__ == "__main__":
19  ser = Server()
20  cli = Client()
21  ser.util()
22  cli.client_test()
$ rm client.log ; python client.py ; cat client.log
2009-11-24 14:40:39,762 client   WARNING  This message comes from Server 
module
2009-11-24 14:40:39,762 client   WARNING  This message comes from Server 
module
2009-11-24 14:40:39,762 client   WARNING  This message comes from Client 
module
2009-11-24 14:40:39,762 client   WARNING  This message comes from Client 
module
Googling and reading http://docs.python.org/library/logging.html didn't 
enlighten me.

Could you suggest what should I change in the above scripts so that the log 
messages would appear only once ?

Thanks,
Ron.




Have a look at http://docs.python.org/library/logging.html#logger-objects
First thing mentioned is Logger.propagate which is, what I believe, you're
looking for ;)

--
Soltys

"Free software is a matter of liberty not price"
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to log messages _only once_ from all modules ?

2009-11-24 Thread Soltys

Ron Barak pisze:

On Nov 24, 3:45 pm, Soltys  wrote:

Barak, Ron pisze:






Hi,
I'm trying to add the logging module to my application, but I seem to be 
missing something.
My application (a wxPython one) has a main script that calls various helper 
classes.
I want the log messages from all modules to go to one central log file.
When I implement logging, I think that due to preparation, I get the same 
message more than once.
Here's an example:
$ cat -n server.py
 1  import logging
 2  import logging.handlers
 3
 4  class Server():
 5  def __init__(self):
 6  self.client_logger = logging.getLogger("client")
 7  self.client_logger.setLevel(logging.DEBUG)
 8  h = logging.FileHandler("client.log")
 9  h.setLevel(logging.DEBUG)
10  formatter = logging.Formatter("%(asctime)s %(name)-12s 
%(levelname)-8s %(message)s")
11  h.setFormatter(formatter)
12  self.client_logger.addHandler(h)
13
14  def util(self):
15  self.client_logger.warning('This message comes from Server 
module')
$ cat -n client.py
 1  import logging
 2  import logging.handlers
 3  from server import Server
 4
 5  class Client():
 6  def __init__(self):
 7  self.client_logger = logging.getLogger("client")
 8  self.client_logger.setLevel(logging.DEBUG)
 9  h = logging.FileHandler("client.log")
10  h.setLevel(logging.DEBUG)
11  formatter = logging.Formatter("%(asctime)s %(name)-12s 
%(levelname)-8s %(message)s")
12  h.setFormatter(formatter)
13  self.client_logger.addHandler(h)
14
15  def client_test(self):
16  self.client_logger.warning("This message comes from Client 
module")
17
18  if __name__ == "__main__":
19  ser = Server()
20  cli = Client()
21  ser.util()
22  cli.client_test()
$ rm client.log ; python client.py ; cat client.log
2009-11-24 14:40:39,762 client   WARNING  This message comes from Server 
module
2009-11-24 14:40:39,762 client   WARNING  This message comes from Server 
module
2009-11-24 14:40:39,762 client   WARNING  This message comes from Client 
module
2009-11-24 14:40:39,762 client   WARNING  This message comes from Client 
module
Googling and readinghttp://docs.python.org/library/logging.htmldidn't enlighten 
me.
Could you suggest what should I change in the above scripts so that the log 
messages would appear only once ?
Thanks,
Ron.

Have a look athttp://docs.python.org/library/logging.html#logger-objects
First thing mentioned is Logger.propagate which is, what I believe, you're
looking for ;)

--
Soltys

"Free software is a matter of liberty not price"- Hide quoted text -

- Show quoted text -


Hi Soltys,
I actually tried that, without any noticeable effects, viz.:

$ cat server.py
import logging
import logging.handlers

class Server():
def __init__(self):
self.client_logger = logging.getLogger("client")
self.client_logger.setLevel(logging.DEBUG)
h = logging.FileHandler("client.log")
h.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s %(name)-12s %
(levelname)-8s %(message)s")
h.setFormatter(formatter)
self.client_logger.addHandler(h)
self.client_logger.propagate = 0

def util(self):
self.client_logger.warning('This message comes from Server
module')

$ cat client.py
import logging
import logging.handlers
from server import Server

class Client():
def __init__(self):
self.client_logger = logging.getLogger("client")
self.client_logger.setLevel(logging.DEBUG)
h = logging.FileHandler("client.log")
h.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s %(name)-12s %
(levelname)-8s %(message)s")
h.setFormatter(formatter)
self.client_logger.addHandler(h)
self.client_logger.propagate = 0

def client_test(self):
self.client_logger.warning("This message comes from Client
module")

if __name__ == "__main__":
ser = Server()
cli = Client()
ser.util()
cli.client_test()

$ rm client.log ; python client.py ; cat client.log
2009-11-24 16:06:35,710 client   WARNING  This message comes from
Server module
2009-11-24 16:06:35,710 client   WARNING  This message comes from
Server module
2009-11-24 16:06:35,710 client   WARNING  This message comes from
Client module
2009-11-24 16:06:35,710 client   WARNING  This message comes from
Client module

$



Rename logger in server.py to server:
self.client_logger = logging.getLogger("server")

Rerun, you should get sth. like this:
$ cat clie

PyChecker under python's virtualenv

2010-02-03 Thread soltys

Hi Everybody,
I've been doing some test on pythons' virtualenv and recently I've
decided to run PyChecker. But I'm having some difficulties with importing
modules available only on virtualenv by pychecker. As if it was
trying to use systemwide python.
I've googled about it, and found nothing in this area.
I installed pychecker using python setup.py install
from virtualenv. I looked at pychecker script - it uses correct python.

Any help appreciate,
Soltys

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


Re: GAE + recursion limit

2010-07-05 Thread Soltys
On 2 Lip, 22:49, Paul McGuire  wrote:
> > Does anyone have any clue what that might be?
> > Why the problem is onGAE(even when run locally), when command line
> > run works just fine (even withrecursionlimitdecreased)?
>
> Can't explain why you see different behavior onGAEvs. local, but it
> is unusual for a "small" translator to flirt withrecursionlimit.  I
> don't usually see parsers come close to this with fewer than 40 or 50
> sub-expressions.  You may have some left-recursiongoing on.  Can you
> post your translator somewhere, perhaps on pastebin, or on the
> pyparsing wiki Discussion page (pyparsing.wikispaces.com)?
>
> -- Paul

@David, thanks for the advice, I did ask on GAE list, id not get
answer till now though.

@Paul, I think I solved it. I did extensive test during weekend and
it
appears that my regular translator almost reaches 1000 recursion
limit.
Probably the last time I've tried to increase the recursion limit for
GAE
app I did it in the wrong place. (For future, if you'd like to do it,
the best
and working is to set that right before call to
run_wsgi_app(application)).
The only think that remains is, I need to review the grammar and how
processing
happens that I reach that limit with GAE.

Thanks guys,
Soltys
-- 
http://mail.python.org/mailman/listinfo/python-list