[Tutor] Encoding question

2009-09-09 Thread Oleg Oltar
Hi!

One of my tests returned following text ()

The test:
from django.test.client import Client
 c = Client()
resp = c.get("/")
resp.content

In [25]: resp.content
Out[25]: '\r\n\r\n\r\nhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>\r\n\r\nhttp://www.w3.org/1999/xhtml";>\r\n  \r\n\r\n
\r\n\nJapanese innovation |
\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f
\xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8\n\r\n
\n\n\n\r\n\r\n

Is there a way I can convert it to normal readable text? (I need for example
to find a string of text in this response to check if my test case Pass or
failed)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Threads very simple examle

2009-09-10 Thread Oleg Oltar
Hi!

I have a question.
I want to create simple load test for my web application.

Consider the following script:

while 1:
urllib2.urlopen("www.example.com")

How can I make it running in several threads?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Threads very simple examle

2009-09-10 Thread Oleg Oltar
On Thu, Sep 10, 2009 at 12:43 PM, Alan Gauld wrote:

> "Oleg Oltar"  wrote
>
>  I want to create simple load test for my web application.
>> Consider the following script:
>>
>> while 1:
>>   urllib2.urlopen("www.example.com")
>>
>
> Just a small caveat.
> If you try a load test like this from a single PC you might get very
> surprising (and non representative) results. Remember that each request will
> be sharing a single network connection, so the performance bottleneck
> can very quickly become the network interface not the server. It depends of
> course on what you are measuring and how many threads you want to run. Just
> be aware of the full architecture that you are testing to make sure what you
> measure is what you mean to measure.
>
> Load testing is a very complex task, frought with potential
> for false results. I've seen far more erroneous load tests than I've seen
> valid ones!If you on;y want to test for 3 or 4 connections then it is
> probably OK but if you try running dozens of concurrent tests it will almost
> certainly fail to reflect reality. The same applies to the server of course,
> if it only has one network connection then it may bottleneck there too. But
> most servers (in a data center environment) have at least two network
> interfaces running so its usually  less of an issue.
>
>  How can I make it running in several threads?
>>
>
> I'll leave the threading part to someone else.
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


Yes, I use tsung to make massive tests, but I just wanted to make some small
test runner for approx 10-20 threads

Here what I've done:


import
urllib2

from threading import
Thread





def
btl_test():

while
True:

page = urllib2.urlopen("example.com")
print
page.code



for i in
range(120):

t = Thread(target =
btl_test)


t.start()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Getting list of attributes from list of objects

2009-09-10 Thread Oleg Oltar
Hi!

I have the following list

l= [ a, b, c]

Where a,b,c are objects created from one class, e.g. each has title
attribute.
What I want to have is a list of titles, e.g. [a.title, b.title, c.title]

Is there a quick way to do it? Or I should use loops (looping through each
element, and generating list)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using command line tool with python script

2009-10-05 Thread Oleg Oltar
Hi!

I want to try to use a command line script with my python application. The
task is the following, my database stores some initial data for the script
and
I need to execute a command line application in a following way:

$ application -parameter1 -file1

where file 1 is a file which contains my initial data, and parameter1 is
unrelated parameter

the workflow as I see it know is following

initial_data = get_initial_data_from_db()
file = open('temp.txt', 'w+')
file.write(initial_data)
file.save()
os.popen4("application -parameter1 -file temp.txt")

I wonder if that possible to execute this script (called application)
without writing the file with initial data to the hard disk?


Thanks,
Oleg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unittest traceback

2008-04-04 Thread Oleg Oltar
Hi!
I am trying to use unittest in python first time. But have a strange
traceback each time I run my sample tests.
Can you please explain why I have it. No info about it in the doc.
e.g. the code is

import unittest
import squaren

class TestCases(unittest.TestCase):
def setUp(self):
pass

def testsmall(self):
self.assertEqual(True, True)



if __name__ == '__main__':
unittest.main()

And the traceback is

--
Ran 1 test in 0.000s

OK
Traceback (most recent call last):
  File "/tmp/py359hJx", line 14, in 
unittest.main()
  File "/opt/local/lib/python2.5/unittest.py", line 768, in __init__
self.runTests()
  File "/opt/local/lib/python2.5/unittest.py", line 806, in runTests
sys.exit(not result.wasSuccessful())
SystemExit: False
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: Unittest traceback

2008-04-04 Thread Oleg Oltar
-- Forwarded message --
From: Oleg Oltar <[EMAIL PROTECTED]>
Date: Fri, Apr 4, 2008 at 2:49 PM
Subject: Re: [Tutor] Unittest traceback
To: Kent Johnson <[EMAIL PROTECTED]>


Yes! Tried in command line. works fine there. Not sure howto customize my
IDE correctly. I use Emacs.

Thanks,
Oleg


On Fri, Apr 4, 2008 at 2:36 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:

> Oleg Oltar wrote:
>
> > Hi!
> > I am trying to use unittest in python first time. But have a strange
> > traceback each time I run my sample tests.
> >
>
> How are you running the test? My guess is that you are running it in an
> IDE or something that shows the normal system exit exception.
>
> Calling sys.exit() raises the SystemExit exception with a result code.
> Normally this is not shown by the runner.
>
> In Python False == 0 so your program is exiting normally with a code of 0
> (no error). It is probably the program runner that is showing the traceback.
>
> Try running the program from the command line.
>
> Kent
>
>
>  Can you please explain why I have it. No info about it in the doc. e.g.
> > the code is
> >
> > import unittest
> > import squaren
> >
> > class TestCases(unittest.TestCase):
> >def setUp(self):
> >pass
> >
> >def testsmall(self):
> >self.assertEqual(True, True)
> >
> >
> >
> > if __name__ == '__main__':
> >unittest.main()
> >
> > And the traceback is
> > --
> > Ran 1 test in 0.000s
> >
> > OK
> > Traceback (most recent call last):
> >  File "/tmp/py359hJx", line 14, in 
> >unittest.main()
> >  File "/opt/local/lib/python2.5/unittest.py", line 768, in __init__
> >self.runTests()
> >  File "/opt/local/lib/python2.5/unittest.py", line 806, in runTests
> >sys.exit(not result.wasSuccessful())
> > SystemExit: False
> >
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Error with incorrect encoding

2008-04-15 Thread Oleg Oltar
I am trying to parse an html page. Have following error while doing that


 src = sel.get_html_source()
links = re.findall(r'', src)
for link in links:
print link



==
ERROR: test_new (__main__.NewTest)
--
Traceback (most recent call last):
  File "", line 19, in test_new
UnicodeEncodeError: 'ascii' codec can't encode character u'\xae' in
position 90: ordinal not in range(128)

--
Ran 1 test in 6.345s
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web programming tutorials?

2008-04-17 Thread Oleg Oltar
OK. take a look on the pages:

 1. http://www.djangobook.com/
 2. Official docs on http://www.djangoproject.com/
 3. Dive into python (http://diveintopython.org/)
 4. And the last one (but the best) showmedo: http://showmedo.com/

On Fri, Apr 18, 2008 at 6:20 AM, Che M <[EMAIL PROTECTED]> wrote:

>  [I thought I sent a similar msg to this list 2 days ago, but now I'm not
> sure it went through, so sorry if I've doubled]
>
> Can someone point me to a start-from-dead-scratch tutorial about the
> basics of web programming?  I've been learning wxPython for GUI programming,
> but web programming (that is, making web applications) seems like another
> world entirely.  I'm aware of *names*--Django, Pylons, CherryPy, TurboGears,
> Zope, Webpy, etc.--but I have a poor sense of what all this means,  and so I
> am sort of 'pre-Python' in my understanding.  I've scanned the archives of
> this list, but so far haven't found pointers to tutorials that assume very
> little knowledge.
>
> I was kind of hoping Alan Gauld's project would be updated for the
> tempting but not yet existent section on web programming.  Any word on that,
> Alan?  In lieu of that, can anyone recommend books/online tutorials/words of
> advice?
>
> Thanks,
> Che
>
>
> --
> Pack up or back up–use SkyDrive to transfer files or keep extra copies. Learn
> how.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web programming tutorials?

2008-04-18 Thread Oleg Oltar
Hi Che!

Use django, don't use Zope and everything will be fine. Django is a new very
powerful web framework. Many cool web applications was created using django!
e.g. you can take a look on our project: www.mydeco.com

Use django and let the Power be with you :)
Thanks,
Oleg

On Fri, Apr 18, 2008 at 9:44 AM, Norman Khine <[EMAIL PROTECTED]> wrote:

> Hi Che,
> I started with python web programming using Zope, but this was because I
> needed a quick CMS application for a small project I did and Zope's CMF
> fitted the bill nicely.
>
> Now I use itools (http://ikaaro.org/itools) it is relatively easy to
> setup and is 99% python (the parser is now in C) the latest version has
> two packages, the core itools is a python library and ikaaro is the CMS.
>
> Here are the docs, http://download.ikaaro.org/doc/itools/index.html
>
> Hope this helps.
> Good luck.
>
> Che M wrote:
> > [I thought I sent a similar msg to this list 2 days ago, but now I'm not
> > sure it went through, so sorry if I've doubled]
> >
> > Can someone point me to a start-from-dead-scratch tutorial about the
> > basics of web programming?  I've been learning wxPython for GUI
> > programming, but web programming (that is, making web applications)
> > seems like another world entirely.  I'm aware of *names*--Django,
> > Pylons, CherryPy, TurboGears, Zope, Webpy, etc.--but I have a poor sense
> > of what all this means,  and so I am sort of 'pre-Python' in my
> > understanding.  I've scanned the archives of this list, but so far
> > haven't found pointers to tutorials that assume very little knowledge.
> >
> > I was kind of hoping Alan Gauld's project would be updated for the
> > tempting but not yet existent section on web programming.  Any word on
> > that, Alan?  In lieu of that, can anyone recommend books/online
> > tutorials/words of advice?
> >
> > Thanks,
> > Che
> >
> >
> > 
> > Pack up or back up–use SkyDrive to transfer files or keep extra copies.
> > Learn how.
> > <
> http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_Refresh_skydrive_packup_042008
> >
> >
> >
> > 
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> --
> Norman Khine
> 24 rue de la Madeleine, 3, Nîmes, France
> tel +33 (0) 466 267 064 e-fax +44 7006 009 324
>
> %>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-83)%26)
> for c in ",adym,*)&uzq^zqf" ] )
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web programming tutorials?

2008-04-18 Thread Oleg Oltar
Introduction into CGI in Russian
http://www.intuit.ru/department/internet/cgi/

Please give alternative link on English variant

On Fri, Apr 18, 2008 at 10:53 AM, Alan Gauld <[EMAIL PROTECTED]>
wrote:

>
> "Che M" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> > I was kind of hoping Alan Gauld's project would be updated
> > for the tempting but not yet existent section on web programming.
>
> I have been working on two web programming topics
> (one client side, one server side) for over a year now.
>
> UInfortunately I'm in the middle of a classic death march project
> at work and just don't have any spare time to work on the tutorial
> topics.
>
> I wioll send you the introductory material that explains the
> theory and a bit about parsing HTML, but for the server side
> I don't have anything worth readiong yet.
>
> That having been said one problem you face is that although
> all of the server side frameworks share a lot of concepts
> they all do things very differently. You really need to
> understand the most basic CGI mechanism first but
> then just pick a framework and work through its tutorials.
>
> To understand CGI there are a lot of web tutorial, although
> not in Python. But once you understand the concepts
>  - which are pretty suimple - you can read the Python CGI
> HowTo article and then move on to a framework.
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unittest. Run test case independently

2008-07-16 Thread Oleg Oltar
Is that possible to run test cases independently (without unittest.main) and
how to do it

E.g. I tried it this way:

import random
import unittest

class TestSequenceFunctions(unittest.TestCase):

def setUp(self):
self.seq = range(10)

def testshuffle(self):
# make sure the shuffled sequence does not lose any elements
random.shuffle(self.seq)
self.seq.sort()
self.assertEqual(self.seq, range(10))


def testchoice(self):
element = random.choice(self.seq)
self.assert_(element in self.seq)

def testsample(self):
self.assertRaises(ValueError, random.sample, self.seq, 20)
for element in random.sample(self.seq, 5):
self.assert_(element in self.seq)

if __name__ == '__main__':
a = TestSequenceFunctions().testchoice().run()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unittest

2008-07-16 Thread Oleg Oltar
Hi I am using unittest framework with selenium.

When I tried this code (my verification point)

self.assertEqual(True, sel.is_text_present(u"Извените пароли не
совпадают"), "System didn't give a correct warning about the password
misstype")

Where u"Извените пароли не совпадают" is russian = "Sorry passwords aren't
> equal", and sel.is_text_present - searches text string on the page


The output I get in case of failure was:


Traceback (most recent call last):
  File "./newaccount/Password_matching.py", line 50, in test_passwordMatching
self.assertEqual(True, sel.is_text_present(u"Извените
пароли не совпадают"), "System didn't give a correct
warning about the password misstype")
AssertionError: System didn't give a correct warning about the password misstype

Is there any way to get normal russian text instead of these strange D
chars "Изве"


Thanks,
Oleg
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unittest

2008-07-16 Thread Oleg Oltar
Seems need help there. Start getting

Traceback (most recent call last):
  File "./newaccount/Same_domain_name.py", line 56, in
test_create_account_to_check
print sel.get_text("check_username_block")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4:
ordinal not in range(128)


when trying to get the text of one of the elements.

How to solve it?

On Thu, Jul 17, 2008 at 5:11 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:

> OK,
>
> I just run the program from terminal. OS: OS X, IDLE = Emacs:).
>
> Yep used the string "# -*- coding: utf-8 -*-" to setup encoding
>
>
> On Thu, Jul 17, 2008 at 4:14 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:
>
>> Another possibility - do you have a coding declaration in your source
>> file, something like
>> # -*- coding:  -*-
>>
>> If so, does the coding declaration match the actual encoding of the file?
>>
>> Kent
>>
>> On Wed, Jul 16, 2008 at 5:11 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:
>> > On Wed, Jul 16, 2008 at 2:40 PM, Oleg Oltar <[EMAIL PROTECTED]>
>> wrote:
>> >> Hi I am using unittest framework with selenium.
>> >>
>> >> When I tried this code (my verification point)
>> >>
>> >> self.assertEqual(True, sel.is_text_present(u"Извените пароли не
>> >> совпадают"), "System didn't give a correct warning about the password
>> >> misstype")
>> >>
>> >>> Where u"Извените пароли не совпадают" is russian = "Sorry passwords
>> aren't
>> >>> equal", and sel.is_text_present - searches text string on the page
>> >>
>> >> The output I get in case of failure was:
>> >>
>> >>
>> >> Traceback (most recent call last):
>> >>
>> >>   File "./newaccount/Password_matching.py", line 50, in
>> >> test_passwordMatching
>> >> self.assertEqual(True, sel.is_text_present(u"Извените
>> >> пароли не Ñ Ð¾Ð²Ð¿Ð°Ð´Ð°ÑŽÑ‚"), "System didn't give a correct
>> >> warning about the password misstype")
>> >>
>> >> AssertionError: System didn't give a correct warning about the password
>> >> misstype
>> >>
>> >> Is there any way to get normal russian text instead of these strange D
>> chars
>> >> "Изве"
>> >
>> > I don't have the solution but maybe I can give you a useful clue. The
>> > D characters are most likely the utf-8 encoding of the Russian text,
>> > when displayed as if it is latin-1. So something in the system is
>> > converting the text to utf-8 and your console probably has latin-1 or
>> > cp1252 encoding.
>> >
>> > Some details might help - how are you running the program - console,
>> > IDLE...? What OS? What are the values of sys.getdefaultencoding() and
>> > sys.stdout.encoding?
>> >
>> > Kent
>> >
>>
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unittest

2008-07-16 Thread Oleg Oltar
In [1]: import sys

In [2]: sys.getdefaultencoding()
Out[2]: 'ascii'

In [3]: sys.stdout.encoding
Out[3]: 'US-ASCII'

On Thu, Jul 17, 2008 at 6:29 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:

> Seems need help there. Start getting
>
> Traceback (most recent call last):
>   File "./newaccount/Same_domain_name.py", line 56, in
> test_create_account_to_check
> print sel.get_text("check_username_block")
> UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4:
> ordinal not in range(128)
>
>
> when trying to get the text of one of the elements.
>
> How to solve it?
>
>
> On Thu, Jul 17, 2008 at 5:11 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:
>
>> OK,
>>
>> I just run the program from terminal. OS: OS X, IDLE = Emacs:).
>>
>> Yep used the string "# -*- coding: utf-8 -*-" to setup encoding
>>
>>
>> On Thu, Jul 17, 2008 at 4:14 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:
>>
>>> Another possibility - do you have a coding declaration in your source
>>> file, something like
>>> # -*- coding:  -*-
>>>
>>> If so, does the coding declaration match the actual encoding of the file?
>>>
>>> Kent
>>>
>>> On Wed, Jul 16, 2008 at 5:11 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:
>>> > On Wed, Jul 16, 2008 at 2:40 PM, Oleg Oltar <[EMAIL PROTECTED]>
>>> wrote:
>>> >> Hi I am using unittest framework with selenium.
>>> >>
>>> >> When I tried this code (my verification point)
>>> >>
>>> >> self.assertEqual(True, sel.is_text_present(u"Извените пароли
>>> не
>>> >> совпадают"), "System didn't give a correct warning about the password
>>> >> misstype")
>>> >>
>>> >>> Where u"Извените пароли не совпадают" is russian = "Sorry passwords
>>> aren't
>>> >>> equal", and sel.is_text_present - searches text string on the page
>>> >>
>>> >> The output I get in case of failure was:
>>> >>
>>> >>
>>> >> Traceback (most recent call last):
>>> >>
>>> >>   File "./newaccount/Password_matching.py", line 50, in
>>> >> test_passwordMatching
>>> >> self.assertEqual(True, sel.is_text_present(u"Извените
>>> >> пароли не Ñ Ð¾Ð²Ð¿Ð°Ð´Ð°ÑŽÑ‚"), "System didn't give a correct
>>> >> warning about the password misstype")
>>> >>
>>> >> AssertionError: System didn't give a correct warning about the
>>> password
>>> >> misstype
>>> >>
>>> >> Is there any way to get normal russian text instead of these strange D
>>> chars
>>> >> "Изве"
>>> >
>>> > I don't have the solution but maybe I can give you a useful clue. The
>>> > D characters are most likely the utf-8 encoding of the Russian text,
>>> > when displayed as if it is latin-1. So something in the system is
>>> > converting the text to utf-8 and your console probably has latin-1 or
>>> > cp1252 encoding.
>>> >
>>> > Some details might help - how are you running the program - console,
>>> > IDLE...? What OS? What are the values of sys.getdefaultencoding() and
>>> > sys.stdout.encoding?
>>> >
>>> > Kent
>>> >
>>>
>>
>>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unittest

2008-07-16 Thread Oleg Oltar
>
> The code

 # -*- coding: utf-8 -*-
#!/usr/bin/python


"""

This test case check how system works in the situation, when user tries to
use already
used username (domain)

We are creating two accounts with such parameters:
1. Sex = Femle
2. Name1=Name2 = foobar%S
3. Pass1 = Name
4. Pass2 = Name
5. Email address1 = Email address2 =  [EMAIL PROTECTED]


In the test we use verification point - warning message about incorrect
input of domain name and the
sugestion message

"""

from selenium import selenium
import unittest, time, re
import HTMLTestRunner
import config
import Creating_account_basic




class Same_domain_name(unittest.TestCase):

def setUp(self):
self.name = "foobar"
self.email = self.name + "@meta.ua"
self.verificationErrors = []
self.selenium = selenium("localhost", ,config.browser,
config.link)
self.selenium.start()

def test_create_account_to_check(self):
"""Creating sample account for next test"""
sel = self.selenium
sel.open("/")
sel.click(u"link=Регистрация")
sel.wait_for_page_to_load("7")
sel.click("id_gender_1")
sel.type("id_first_name", self.name)
sel.type("id_last_name", self.name)
sel.type("id_email", self.email)
sel.type("id_username",  self.name)

#sel.wait_for_condition(sel.is_element_present("check_username_block"),
7)
time.sleep(10)
print "!!!", sel.is_element_present("check_username_block")
sel.type("id_password",  self.name)
print sel.get_text("check_username_block").decode('cp-1252')
sel.type("id_password2", self.name)
sel.click(u"//[EMAIL PROTECTED]'Зарегистрироваться']")
sel.wait_for_page_to_load("7")
if config.debugMode is True:
    time.sleep(5)


def tearDown(self):
self.selenium.stop()
print self.verificationErrors
self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":

unittest.main()
#HTMLTestRunner.main()



On Thu, Jul 17, 2008 at 6:47 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:

> In [1]: import sys
>
> In [2]: sys.getdefaultencoding()
> Out[2]: 'ascii'
>
> In [3]: sys.stdout.encoding
> Out[3]: 'US-ASCII'
>
>
> On Thu, Jul 17, 2008 at 6:29 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:
>
>> Seems need help there. Start getting
>>
>> Traceback (most recent call last):
>>   File "./newaccount/Same_domain_name.py", line 56, in
>> test_create_account_to_check
>> print sel.get_text("check_username_block")
>> UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4:
>> ordinal not in range(128)
>>
>>
>> when trying to get the text of one of the elements.
>>
>> How to solve it?
>>
>>
>> On Thu, Jul 17, 2008 at 5:11 AM, Oleg Oltar <[EMAIL PROTECTED]>
>> wrote:
>>
>>> OK,
>>>
>>> I just run the program from terminal. OS: OS X, IDLE = Emacs:).
>>>
>>> Yep used the string "# -*- coding: utf-8 -*-" to setup encoding
>>>
>>>
>>> On Thu, Jul 17, 2008 at 4:14 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:
>>>
>>>> Another possibility - do you have a coding declaration in your source
>>>> file, something like
>>>> # -*- coding:  -*-
>>>>
>>>> If so, does the coding declaration match the actual encoding of the
>>>> file?
>>>>
>>>> Kent
>>>>
>>>> On Wed, Jul 16, 2008 at 5:11 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:
>>>> > On Wed, Jul 16, 2008 at 2:40 PM, Oleg Oltar <[EMAIL PROTECTED]>
>>>> wrote:
>>>> >> Hi I am using unittest framework with selenium.
>>>> >>
>>>> >> When I tried this code (my verification point)
>>>> >>
>>>> >> self.assertEqual(True, sel.is_text_present(u"Извените пароли
>>>> не
>>>> >> совпадают"), "System didn't give a correct warning about the password
>>>> >> misstype")
>>>> >>
>>>> >>> Where u"Извените пароли не совпадают" is russian = "Sorry passwords
>>>> aren't
>>>> >>> equal", and sel.is_text_present - searches text string on the page
>>>> >>
&g

Re: [Tutor] Unittest

2008-07-16 Thread Oleg Oltar
And in case:
# coding: utf-8

import traceback
try:
raise Exception(u'Зрегиться')
except Exception,e:
print traceback.format_exc().decode('utf-8').encode('cp437', 'replace')


Getting

beryl:~ oleg$ python ./wish/newaccount/reg.py
Traceback (most recent call last):
  File "./wish/newaccount/reg.py", line 5, in 
raise Exception(u'?')
Exception: 



My console settings:

In [1]: import sys

In [2]: sys.getdefaultencoding()
Out[2]: 'ascii'

In [3]: sys.stdout.encoding
Out[3]: 'US-ASCII'


On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:

> OK
> the output:
>
> # coding: utf-8
>>
>> import traceback
>> try:
>> raise Exception(u'Зрегиться')
>> except Exception,e:
>> print traceback.format_exc().decode('utf-8')
>>
>
>
> >>> Traceback (most recent call last):
>   File "/var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT", line
> 7, in 
> print traceback.format_exc().decode('utf-8')
> UnicodeEncodeError: 'ascii' codec can't encode characters in position
> 148-156: ordinal not in range(128)
>
>
>
>
> On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen <[EMAIL PROTECTED]<[EMAIL 
> PROTECTED]>>
> wrote:
>
>>  The Exception is output in the encoding of the source file.  If the
>> terminal you are displaying the exception on is in a different encoding, it
>> will be garbled.  I'm not familiar with OS X's terminal.  Try running python
>> and printing sys.stdout.encoding.
>>
>> Alternatively, wrap your code in a try/except handler and translate the
>> exception yourself.
>>
>> # coding: utf-8
>> import traceback
>> try:
>> raise Exception(u'Зарегистрироваться')
>> except Exception,e:
>> print traceback.format_exc().decode('utf-8')
>>
>> The last line translates the utf-8 traceback into Unicode.  Printing
>> Unicode will encode the output with the terminal's decoding.  If there are
>> characters it can't display, you'll still get an error, though.  You can be
>> more explicit however:
>>
>> print traceback.format_exc().decode('utf-8').encode('cp437','replace')
>>
>> In this case you'll get ? whenever a character can't be represented in the
>> selected encoding.  cp437, for example, can't display any russian
>> characters, so for me (on Windows) I just get all ???.  When I tried
>> it with a character string that could be displayed in cp437, it worked fine:
>>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File "t4.py", line 4, in 
>> raise Exception('MàΓ£ΦΘΩδ')
>> Exception: MàΓ£ΦΘΩδ
>>
>> Another option is to redirect the output to a file and read the file with
>> an editor that can display utf-8 (such as Notepad on Windows).
>>
>> python testfile.py 2>error.txt  # this redirects stderr to a
>> file.
>>
>> Hope that helps,
>> Mark
>>
>> "Oleg Oltar" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>
>>> The code
>>
>>  # -*- coding: utf-8 -*-
>> #!/usr/bin/python
>>
>>
>> """
>>
>> This test case check how system works in the situation, when user tries to
>> use already
>> used username (domain)
>>
>> We are creating two accounts with such parameters:
>> 1. Sex = Femle
>> 2. Name1=Name2 = foobar%S
>> 3. Pass1 = Name
>> 4. Pass2 = Name
>> 5. Email address1 = Email address2 =  [EMAIL PROTECTED]
>>
>>
>> In the test we use verification point - warning message about incorrect
>> input of domain name and the
>> sugestion message
>>
>> """
>>
>> from selenium import selenium
>> import unittest, time, re
>> import HTMLTestRunner
>> import config
>> import Creating_account_basic
>>
>>
>>
>>
>> class Same_domain_name(unittest.TestCase):
>>
>> def setUp(self):
>> self.name = "foobar"
>> self.email = self.name + "@meta.ua"
>> self.verificationErrors = []
>> self.selenium = selenium("localhost", ,config.browser,
>> config.link)
>> self.selenium.start()
>>
>> def test_create_account_to_check(self):
>

Re: [Tutor] Unittest

2008-07-16 Thread Oleg Oltar
Ok, seems it's my console setting. Tried console with koi8-r (from
http://vak.ru/doku.php/macosx-russian), and it looks ok there. Mean the
satndard output, but still getting "D" chars instead of russian when trying
to convert it to html via HTMLTestRunner (see
http://tungwaiyip.info/software/HTMLTestRunner.html)

On Thu, Jul 17, 2008 at 9:33 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:

>
> And in case:
> # coding: utf-8
>
> import traceback
> try:
> raise Exception(u'Зрегиться')
> except Exception,e:
> print traceback.format_exc().decode('utf-8').encode('cp437', 'replace')
>
>
> Getting
>
> beryl:~ oleg$ python ./wish/newaccount/reg.py
> Traceback (most recent call last):
>   File "./wish/newaccount/reg.py", line 5, in 
> raise Exception(u'?')
> Exception: 
>
>
>
> My console settings:
>
> In [1]: import sys
>
> In [2]: sys.getdefaultencoding()
> Out[2]: 'ascii'
>
> In [3]: sys.stdout.encoding
> Out[3]: 'US-ASCII'
>
>
> On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:
>
>> OK
>> the output:
>>
>> # coding: utf-8
>>>
>>> import traceback
>>> try:
>>> raise Exception(u'Зрегиться')
>>> except Exception,e:
>>> print traceback.format_exc().decode('utf-8')
>>>
>>
>>
>> >>> Traceback (most recent call last):
>>   File "/var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT",
>> line 7, in 
>> print traceback.format_exc().decode('utf-8')
>> UnicodeEncodeError: 'ascii' codec can't encode characters in position
>> 148-156: ordinal not in range(128)
>>
>>
>>
>>
>> On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen <[EMAIL PROTECTED]<[EMAIL 
>> PROTECTED]>>
>> wrote:
>>
>>>  The Exception is output in the encoding of the source file.  If the
>>> terminal you are displaying the exception on is in a different encoding, it
>>> will be garbled.  I'm not familiar with OS X's terminal.  Try running python
>>> and printing sys.stdout.encoding.
>>>
>>> Alternatively, wrap your code in a try/except handler and translate the
>>> exception yourself.
>>>
>>> # coding: utf-8
>>> import traceback
>>> try:
>>> raise Exception(u'Зарегистрироваться')
>>> except Exception,e:
>>> print traceback.format_exc().decode('utf-8')
>>>
>>> The last line translates the utf-8 traceback into Unicode.  Printing
>>> Unicode will encode the output with the terminal's decoding.  If there are
>>> characters it can't display, you'll still get an error, though.  You can be
>>> more explicit however:
>>>
>>> print
>>> traceback.format_exc().decode('utf-8').encode('cp437','replace')
>>>
>>> In this case you'll get ? whenever a character can't be represented in
>>> the selected encoding.  cp437, for example, can't display any russian
>>> characters, so for me (on Windows) I just get all ???.  When I tried
>>> it with a character string that could be displayed in cp437, it worked fine:
>>>
>>> Traceback (most recent call last):
>>>   File "", line 1, in 
>>>   File "t4.py", line 4, in 
>>> raise Exception('MàΓ£ΦΘΩδ')
>>> Exception: MàΓ£ΦΘΩδ
>>>
>>> Another option is to redirect the output to a file and read the file with
>>> an editor that can display utf-8 (such as Notepad on Windows).
>>>
>>> python testfile.py 2>error.txt  # this redirects stderr to a
>>> file.
>>>
>>> Hope that helps,
>>> Mark
>>>
>>> "Oleg Oltar" <[EMAIL PROTECTED]> wrote in message
>>> news:[EMAIL PROTECTED]
>>>
>>>> The code
>>>
>>>  # -*- coding: utf-8 -*-
>>> #!/usr/bin/python
>>>
>>>
>>> """
>>>
>>> This test case check how system works in the situation, when user tries
>>> to use already
>>> used username (domain)
>>>
>>> We are creating two accounts with such parameters:
>>> 1. Sex = Femle
>>> 2. Name1=Name2 = foobar%S
>>> 3. Pass1 = Name
>>> 4. Pass2 = Name
>>> 5.

Re: [Tutor] Unittest

2008-07-17 Thread Oleg Oltar
beryl:~ oleg$ env
MANPATH=/usr/share/man:/usr/local/share/man:/usr/X11/man
TERM_PROGRAM=Apple_Terminal
TERM=xterm-color
SHELL=/bin/bash
TMPDIR=/var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/
Apple_PubSub_Socket_Render=/tmp/launch-UNXiC6/Render
TERM_PROGRAM_VERSION=237
USER=oleg
COMMAND_MODE=unix2003
SSH_AUTH_SOCK=/tmp/launch-hfpsIl/Listeners
__CF_USER_TEXT_ENCODING=0x1F6:0:0
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
PWD=/Users/oleg
LANG=ru_RU.UTF-8
SHLVL=1
HOME=/Users/oleg
PYTHONPATH=:/Users/oleg/Documents/wishes_Test
LOGNAME=oleg
DISPLAY=/tmp/launch-1kgALC/:0
SECURITYSESSIONID=a206d0


On Thu, Jul 17, 2008 at 9:58 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:

> See previous message (sent it few seconds ago)
>
>
> On Thu, Jul 17, 2008 at 9:55 AM, Mark Tolonen <[EMAIL PROTECTED]<[EMAIL 
> PROTECTED]>>
> wrote:
>
>>  OK, your console is set to 'ascii' ('cp437' was my example and is the
>> Windows console encoding).  'ascii' won't be able to display Russian.
>> It shouldn't have displayed the "ИзвениÑ" characters either.
>> Are you still running on the same terminal that display those
>> characters?  Can you change your terminals encoding preference via an
>> environment variable?
>> --
>> Mark
>>
>> "Oleg Oltar" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>
>> And in case:
>> # coding: utf-8
>>
>> import traceback
>> try:
>> raise Exception(u'Зрегиться')
>> except Exception,e:
>> print traceback.format_exc().decode('utf-8').encode('cp437',
>> 'replace')
>>
>>
>> Getting
>>
>> beryl:~ oleg$ python ./wish/newaccount/reg.py
>> Traceback (most recent call last):
>>   File "./wish/newaccount/reg.py", line 5, in 
>> raise Exception(u'?')
>> Exception: 
>>
>>
>>
>> My console settings:
>>
>> In [1]: import sys
>>
>> In [2]: sys.getdefaultencoding()
>> Out[2]: 'ascii'
>>
>> In [3]: sys.stdout.encoding
>> Out[3]: 'US-ASCII'
>>
>>
>> On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar <[EMAIL PROTECTED]>
>> wrote:
>>
>>> OK
>>> the output:
>>>
>>>  # coding: utf-8
>>>>
>>>> import traceback
>>>> try:
>>>> raise Exception(u'Зрегиться')
>>>> except Exception,e:
>>>> print traceback.format_exc().decode('utf-8')
>>>>
>>>
>>>
>>> >>> Traceback (most recent call last):
>>>   File "/var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT",
>>> line 7, in 
>>> print traceback.format_exc().decode('utf-8')
>>> UnicodeEncodeError: 'ascii' codec can't encode characters in position
>>> 148-156: ordinal not in range(128)
>>>
>>>
>>>
>>>
>>> On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen <[EMAIL PROTECTED]<[EMAIL 
>>> PROTECTED]>>
>>> wrote:
>>>
>>>>  The Exception is output in the encoding of the source file.  If the
>>>> terminal you are displaying the exception on is in a different encoding, it
>>>> will be garbled.  I'm not familiar with OS X's terminal.  Try running 
>>>> python
>>>> and printing sys.stdout.encoding.
>>>>
>>>> Alternatively, wrap your code in a try/except handler and translate the
>>>> exception yourself.
>>>>
>>>> # coding: utf-8
>>>> import traceback
>>>> try:
>>>> raise Exception(u'Зарегистрироваться')
>>>> except Exception,e:
>>>> print traceback.format_exc().decode('utf-8')
>>>>
>>>> The last line translates the utf-8 traceback into Unicode.  Printing
>>>> Unicode will encode the output with the terminal's decoding.  If there are
>>>> characters it can't display, you'll still get an error, though.  You can be
>>>> more explicit however:
>>>>
>>>> print
>>>> traceback.format_exc().decode('utf-8').encode('cp437','replace')
>>>>
>>>> In this case you'll get ? whenever a character can't be represented in
>>>> the selected encoding.  cp437, for example, can't display any russian
>>>> characte

Re: [Tutor] Unittest

2008-07-17 Thread Oleg Oltar
And also:

Getting this in console when trying to generate report via HTMLTestRunner
(it displayed text correctly when tried simple unittest.main)
pass
output_list['pt1.1'] =
'!!! True\nÐ"омен \'foobar\' занят. Рекомендованные
свободные домены: ffoobar foobar.foobar foofoo
fofo\n[]\n';





On Thu, Jul 17, 2008 at 10:01 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:

> beryl:~ oleg$ env
> MANPATH=/usr/share/man:/usr/local/share/man:/usr/X11/man
> TERM_PROGRAM=Apple_Terminal
> TERM=xterm-color
> SHELL=/bin/bash
> TMPDIR=/var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/
> Apple_PubSub_Socket_Render=/tmp/launch-UNXiC6/Render
> TERM_PROGRAM_VERSION=237
> USER=oleg
> COMMAND_MODE=unix2003
> SSH_AUTH_SOCK=/tmp/launch-hfpsIl/Listeners
> __CF_USER_TEXT_ENCODING=0x1F6:0:0
> PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
> PWD=/Users/oleg
> LANG=ru_RU.UTF-8
> SHLVL=1
> HOME=/Users/oleg
> PYTHONPATH=:/Users/oleg/Documents/wishes_Test
> LOGNAME=oleg
> DISPLAY=/tmp/launch-1kgALC/:0
> SECURITYSESSIONID=a206d0
>
>
>
> On Thu, Jul 17, 2008 at 9:58 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:
>
>> See previous message (sent it few seconds ago)
>>
>>
>> On Thu, Jul 17, 2008 at 9:55 AM, Mark Tolonen <[EMAIL PROTECTED]<[EMAIL 
>> PROTECTED]>>
>> wrote:
>>
>>>  OK, your console is set to 'ascii' ('cp437' was my example and is the
>>> Windows console encoding).  'ascii' won't be able to display Russian.
>>> It shouldn't have displayed the "ИзвениÑ" characters either.
>>> Are you still running on the same terminal that display those
>>> characters?  Can you change your terminals encoding preference via an
>>> environment variable?
>>> --
>>> Mark
>>>
>>> "Oleg Oltar" <[EMAIL PROTECTED]> wrote in message
>>> news:[EMAIL PROTECTED]
>>>
>>> And in case:
>>> # coding: utf-8
>>>
>>> import traceback
>>> try:
>>> raise Exception(u'Зрегиться')
>>> except Exception,e:
>>> print traceback.format_exc().decode('utf-8').encode('cp437',
>>> 'replace')
>>>
>>>
>>> Getting
>>>
>>> beryl:~ oleg$ python ./wish/newaccount/reg.py
>>> Traceback (most recent call last):
>>>   File "./wish/newaccount/reg.py", line 5, in 
>>> raise Exception(u'?')
>>> Exception: 
>>>
>>>
>>>
>>> My console settings:
>>>
>>> In [1]: import sys
>>>
>>> In [2]: sys.getdefaultencoding()
>>> Out[2]: 'ascii'
>>>
>>> In [3]: sys.stdout.encoding
>>> Out[3]: 'US-ASCII'
>>>
>>>
>>> On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar <[EMAIL PROTECTED]>
>>> wrote:
>>>
>>>> OK
>>>> the output:
>>>>
>>>>  # coding: utf-8
>>>>>
>>>>> import traceback
>>>>> try:
>>>>> raise Exception(u'Зрегиться')
>>>>> except Exception,e:
>>>>> print traceback.format_exc().decode('utf-8')
>>>>>
>>>>
>>>>
>>>> >>> Traceback (most recent call last):
>>>>   File "/var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT",
>>>> line 7, in 
>>>> print traceback.format_exc().decode('utf-8')
>>>> UnicodeEncodeError: 'ascii' codec can't encode characters in position
>>>> 148-156: ordinal not in range(128)
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen <[EMAIL PROTECTED]<[EMAIL 
>>>> PROTECTED]>>
>>>> wrote:
>>>>
>>>>>  The Exception is output in the encoding of the source file.  If the
>>>>> terminal you are displaying the exception on is in a different encoding, 
>>>>> it
>>>>> will be garbled.  I'm not familiar with OS X's terminal.  Try running 
>>>>> python
>>>>> and printing sys.stdout.encoding.
>>>>>
>>>>> Alternatively, wrap your code in a try/except handler and translate the
>>>>> exception yourself.
>>>>>
>>>>> # coding: utf-8
>>>>> import 

[Tutor] Import modeuls

2008-07-20 Thread Oleg Oltar
Hi
I need to import several modules from many folders which has subfolders

~/folder/tests/sampletest.py
~/folder/suites/samplesuit.py

a suit uses tests from tests folder. I need to import them somehow from
tests folder. I added ~/folder to PYTHONPATH in my test_runner:


import sys
import os

sys.path.insert(0, "~/folder")
os.popen("python2.5 %s" %sys.argv[1])

But when trying to import module in the samplesuite file:

from tests.sampletest.EmailWithoutA import EmailWithoutA
>

But I getting ImportError: No module named 

Please help
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Import modeuls

2008-07-21 Thread Oleg Oltar
If I am adding, __init__.py it still doesn't import anything.
Do I have add the import (from sampletest import EmailWithoutA) in my init
file?


On Mon, Jul 21, 2008 at 1:28 AM, arsyed <[EMAIL PROTECTED]> wrote:

> On Sun, Jul 20, 2008 at 12:46 PM, Oleg Oltar <[EMAIL PROTECTED]>
> wrote:
>
>> Hi
>> I need to import several modules from many folders which has subfolders
>>
>> ~/folder/tests/sampletest.py
>> ~/folder/suites/samplesuit.py
>>
>> a suit uses tests from tests folder. I need to import them somehow from
>> tests folder. I added ~/folder to PYTHONPATH in my test_runner:
>>
>>
>> import sys
>> import os
>>
>> sys.path.insert(0, "~/folder")
>> os.popen("python2.5 %s" %sys.argv[1])
>>
>> But when trying to import module in the samplesuite file:
>>
>> from tests.sampletest.EmailWithoutA import EmailWithoutA
>>>
>>
>> But I getting ImportError: No module named 
>>
>> Please help
>>
>>
>
> Do you have an __init__.py file in the tests and suites directories?
>
> More on that here:
>
> http://docs.python.org/tut/node8.html
>
> "The __init__.py files are required to make Python treat the directories
> as containing packages; this is done to prevent directories with a common
> name, such as "string", from unintentionally hiding valid modules that
> occur later on the module search path. In the simplest case, __init__.pycan 
> just be an empty file, but it can also execute initialization code for
> the package or set the __all__ variable, described later."
>
>
>
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Import modeuls

2008-07-21 Thread Oleg Oltar
They want me to do one test runner which runs any test... And ideally it
should work on any platform

When I added something to $PYTHONPATH, they told me to remove it...



On Mon, Jul 21, 2008 at 12:11 PM, arsyed <[EMAIL PROTECTED]> wrote:

> On Mon, Jul 21, 2008 at 4:46 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote:
>
>> Anyway. another related question. I run tests using the runner.py
>>
>> It has following syntax
>> sys.path.insert(path)
>> os.popen("python module to run")
>>
>> Will the python runned from the file see new path?
>>
>>
>>
> I'm not sure but I don't think so. Try and see what happens.
>
> I think to get that behavior, you want to set the PYTHONPATH environment
> variable instead. Then, I believe the child process will inherit the parent
> process's environment variable. If that doesn't work, look into the
> subprocess module which takes an explicit env parameter for the Popen class
> in order to accomplish this.
>
> It's probably easier just to set PYTHONPATH in your shell and then run your
> scripts so all programs will have access to it.
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Threading

2008-09-11 Thread Oleg Oltar
Hi!

I need to open about 1200 urls from my database. And to check that those
urls are really exists.

I used urllib2.urlopen for it. But it's a little bit slow. I thought that
it's might be a good idea to do it in a threads. So it can add some
performance to my code.

Unfortunately I can't get started with the treading module.  There are no
simple examples in the python docs. Not sure how to start.


What I want to have:
for my list of urls I want to start few threads, each one of them should do
some validation.

My code without threads:

def queryDb(query, db_name = sys.argv[1]):
db = MySQLdb.connect(db = db_name, read_default_file="~/.my.cnf")
c = db.cursor()
c.execute(query)
return c


def openUrl(url):
error = ''

try:
urllib2.urlopen(url)
except (urllib2.URLError, urllib2.HTTPError,httplib.BadStatusLine),
error:
pass

return str(error)

def isValuePresent(dbField):
if str(dbField).find('None') is not -1:
return False
else:
return True

def displayResults(resultTable):
for query in resultTable:
print query

def processUrl(url, guid, parent_guid):


def testUrls():
error = ''
resultTable = []
errorTable = ['None']
products = queryDb(query = """SELECT url, guid, parent from product;""")
i = 0

for product in products.fetchall():

url = product[0]
guid = product[1]
parent_guid = product[2]
error_code = ''
#resultTable = {}

#print product[0]


if isValuePresent(url) is False:
#print "!", "this one is none", product[0]

"""Checking if this is a variant and it has parent with url"""
if isValuePresent(parent_guid) is True:
#print parent_guid, isValuePresent(parent_guid)
for parent in queryDb(query="""SELECT url from product where
guid = '%s';""" %parent_guid).fetchall():
#print parent[0]
'''Checking if parent product contains url'''
if isValuePresent(parent[0]) is True:
url = guid + "the parent url is: " + parent[0]
error = openUrl(parent[0])
else:

error = 'The variant with guid ' + guid + ' and his
parent do not contain urls!'
"""So the product is parent, and it's expected that it's child
will contain guids"""
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Decoding from strange symbols

2011-01-19 Thread Oleg Oltar
Hi,

I am trying to decode a string I took from file:

file = open ("./Downloads/lamp-post.csv", 'r')
data = file.readlines()
data[0]

'\xff\xfeK\x00e\x00y\x00w\x00o\x00r\x00d\x00\t\x00C\x00o\x00m\x00p\x00e\x00t\x00i\x00t\x00i\x00o\x00n\x00\t\x00G\x00l\x00o\x00b\x00a\x00l\x00
\x00M\x00o\x00n\x00t\x00h\x00l\x00y\x00
\x00S\x00e\x00a\x00r\x00c\x00h\x00e\x00s\x00\t\x00D\x00e\x00c\x00
\x002\x000\x001\x000\x00\t\x00N\x00o\x00v\x00
\x002\x000\x001\x000\x00\t\x00O\x00c\x00t\x00
\x002\x000\x001\x000\x00\t\x00S\x00e\x00p\x00
\x002\x000\x001\x000\x00\t\x00A\x00u\x00g\x00
\x002\x000\x001\x000\x00\t\x00J\x00u\x00l\x00
\x002\x000\x001\x000\x00\t\x00J\x00u\x00n\x00
\x002\x000\x001\x000\x00\t\x00M\x00a\x00y\x00
\x002\x000\x001\x000\x00\t\x00A\x00p\x00r\x00
\x002\x000\x001\x000\x00\t\x00M\x00a\x00r\x00
\x002\x000\x001\x000\x00\t\x00F\x00e\x00b\x00
\x002\x000\x001\x000\x00\t\x00J\x00a\x00n\x00
\x002\x000\x001\x000\x00\t\x00A\x00d\x00
\x00s\x00h\x00a\x00r\x00e\x00\t\x00S\x00e\x00a\x00r\x00c\x00h\x00
\x00s\x00h\x00a\x00r\x00e\x00\t\x00E\x00s\x00t\x00i\x00m\x00a\x00t\x00e\x00d\x00
\x00A\x00v\x00g\x00.\x00
\x00C\x00P\x00C\x00\t\x00E\x00x\x00t\x00r\x00a\x00c\x00t\x00e\x00d\x00
\x00F\x00r\x00o\x00m\x00 \x00W\x00e\x00b\x00
\x00P\x00a\x00g\x00e\x00\t\x00L\x00o\x00c\x00a\x00l\x00
\x00M\x00o\x00n\x00t\x00h\x00l\x00y\x00
\x00S\x00e\x00a\x00r\x00c\x00h\x00e\x00s\x00\n'

How do I convert this to something human readable?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor