[Tutor] Real time reading

2004-12-05 Thread Øyvind
I would like to analyze a maillog. The maillog is automatically generated
and every mail sent is added to the log. I would like to check if someone
send more than 5 mails pr minute (spams) and if so, get Python to send a
warningmail to the mailmaster.

How would I in the best way read the log? To open the file and close it
every second sounds like a bad idea? Is there some function to analyze the
file, and automatically extract additions to the file?

Thanks in advance.

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Port 43 whois.ripe.net

2005-03-15 Thread Øyvind
Hello.

I need to query the whois at Ripe.net. It tells me to connect to port 43.
I have found a description how to connect with .Net.
http://www.aspheute.com/english/2825.asp I am not very familiar with
network protocols, but assume this will be no big problem with Python. Can
someone point me in the right direction to what modules I would use in
Python to connect to the whois-server. I would also appriciate if someone
had a link to a 'dummies' tutorial/manual/faq for the networking theory I
need, or any hints about the direction I should look...

Thanks in advance


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] FTP retrieve

2005-03-15 Thread Øyvind
I have opened an FTP connection, and use the following to download a logfile:

f = open('c:///web.log','w')
ftp.retrlines('RETR ex050202.log', f.write)

I have also tried with f.writelines.

It works, but not as well as I would like. All the \n's are removed. How
can I download an exact copy, so that each line actually ends up being on
a separate line?

Thanks in advance...



-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Mouseclick

2005-04-05 Thread Øyvind
I am creating a little application that demonstrates some tasks on the
screen for the user, but cannot seem to click the left mousebutton.

I have moved the cursor to the correct position by

>>> from ctypes import *
>>> windll.user32.SetCursorPos(100, 400)

and would like to click the left mousebutton at that position. Is that
possible? I have just been able to find ways to click the button on
buttons that I can name such as:

def findAButtonCalledOK(hwnd, windowText, windowClass): # Define a
function to find our button
return windowClass == "Button" and windowText == "OK"
okButton = findControl(optDialog, findAButtonCalledOK)
click(okButton)

or how to track if a button is pressed. But neither of those are what I
need. I need to press the button at a specific coordinate... Can I do that
with Python? If so, how? 3 hours of Googling didn't help me

Thanks in advance...

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Password

2005-05-18 Thread Øyvind
Hello.

I am trying to make a loginbox for a program, and need to make a somewhat
safe passwordroutine.

Will this work?

import md5
h = md5.new()
h.update(password)
h.hexdigest()

The user enters a password first. These lines will create a string:
'12c0faae657b3d068c0f19b71f5b43bc' This string will be stored in the file
settings.txt

Then, I will do the same where the password is entered in a GUI-box. Then
I will do the same, and compare. If file.readline == h.hexdigest() the
user will be accepted. Is this a good way to do this?

And a second question. I have made a tkinter box with two entry-fields. Is
there a way to make the letters in the second entrybox appear as  as
the user types his password? Is there some built in function in the
Tkinter Entry that does this?

Thanks in advance

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Corrupt files

2005-08-02 Thread Øyvind
Hello.

I have created a program that automatically downloads some files I need.
It can be .zip, .jpg, .mpg or .txt. However, a lot of the time urlretrieve
downloads the file, gives no error, but the downloaded file is corrupted.
I use a simple check for the size of the file. If it is way too small, I
automatically remove it. The files are ok on the server.

Is there some function/modulte that checks a files integrity wheter or not
the file is corrupt or not?

Thanks in advance.

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Lots of variables

2005-08-06 Thread Øyvind
Hello.

I am trying to write a gui that has a lot of checkboxes. It is over 200
different ones. I use a for statement to generate:

ver = 200
for i in ['Car','House','Boat','Plane']:
self.fra26_che01p = Checkbutton (self.fra26)
self.fra26_che01p.place(in_=self.fra26,x=5,y=ver)
self.fra26_che01p.configure(text=i)
self.getattr(self,i)1 = IntVar()
self.fra26_che01p.configure(variable=getattr(self,i))
self.fra26_che01v = Checkbutton (self.fra26)
self.fra26_che01v.place(in_=self.fra26,x=70,y=ver)
#self.fra26_che01v.configure(text="1p")
self.getattr(self,i)2 = IntVar()
self.fra26_che01v.configure(variable=getattr(self,i))
ver = ver + 17

The variable does not work for obvious reasons. I need to change variable
for each new creation. If I had made the variables manually, I would have
written (variable=self.car1)/(variable=self.car2) and so forth. Is there
some way I can make lots of variables without declaring them up front?

Thanks in advance

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Increase speed

2007-10-09 Thread Øyvind
Hello.

I have written a simple application that does a number of simple
calculations. In psudo-code it looks something like below.

The program works fine. However, it seems like I need a supercomputer to
finish the resultwithin a reasonable timeframe, as the var.txt contains a
lot of variables that has to be computed. And, since my budget doesn't
include a supercomputer, I need to optimize the script. I have been able
to half the running-time by flushing the file more seldom, and a little
more by try and fail. However, half is still a looong time. I would like
to increase the speed even more.

Does anyone have any suggestions of what I should do? Is Stackless Python
an option? Is there some other steps I could take? Some basic steps?

Thanks in advance,
Øyvind

class start:

filles = open("var.txt","r") into memory

def oppned(self):
return randint(0,1)

def verdier(self):
increase variable x and y

def verdi(self):
for i in filles:
generate random from oppned
simple calculation

if result 1:
 write result

if result 2:
 generate new random, calculate more
 write result

if result 3:
 write result, use new variable

if __name__ == '__main__':
n = start()
for x in range(0,1):
n.verdier()
for y in range(0,100):
n.verdi()

n.fil.write(result)
if variable x > 0.32:
break



-- 
This email has been scanned for viruses & spam by Domenebutikken - 
www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - 
www.domenebutikken.no

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


[Tutor] Run a cmd program

2005-08-09 Thread Øyvind
Hello.

I need to run a program
(http://www.microsoft.com/ntserver/nts/downloads/management/uptime/default.asp)
thru Python. It is normally run such as "uptime AUTO-SRV-001 /s
/d:04/01/2005" in the command prompt. Is it possible to run a already
compiled exe file in Python and thereafter get the result out? What
module/command should I look for to run another program? Googling have
only given me results about how to run Python..

Thanks in advance.

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


Re: [Tutor] Run a cmd program

2005-08-09 Thread Øyvind
Thanks a lot. However, it didn't work. I got an error stating something
along: "Is not recognized as an internal or external command, executable
program or .. file" (I don't know how to translate the word . to
english).

But, when I looked in the manual about the commands module, I found this:
"Availability: Unix." That might explain. However, in the manual I also
found two other commands to try. 'Execl' which made PythonWin 2.3.5 crash
regardless how I used it, and os.popen. The latter worked perfectly.

Have a great day



>>>> import commands
>>>> commands.getoutput("uptime AUTO-SRV-001 /s /d:04/01/2005")
>
> that should do it
>
> On 8/9/05, Øyvind <[EMAIL PROTECTED]> wrote:
>>
>> Hello.
>>
>> I need to run a program
>> (
>> http://www.microsoft.com/ntserver/nts/downloads/management/uptime/default.asp
>> )
>> thru Python. It is normally run such as "uptime AUTO-SRV-001 /s
>> /d:04/01/2005" in the command prompt. Is it possible to run a already
>> compiled exe file in Python and thereafter get the result out? What
>> module/command should I look for to run another program? Googling have
>> only given me results about how to run Python..
>>
>> Thanks in advance.
>>
>> --
>> This email has been scanned for viruses & spam by Decna as -
>> www.decna.no<http://www.decna.no>
>> Denne e-posten er sjekket for virus & spam av Decna as -
>> www.decna.no<http://www.decna.no>
>>
>> ___
>> Tutor maillist - Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> --
> This email has been scanned for viruses & spam by Decna as - www.decna.no
> Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no
>
>


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] wxPython problem

2005-09-26 Thread Øyvind
Hello.

I have been reading the
http://wiki.wxpython.org/index.cgi/Getting_20Started manual and are
running the program there. (Enclosed below).

When I run it, it works fine. But, when I run it again, I get the error
PyNoAppError: The wx.App object must be created first! I assume I have
killed the object and have to create it again. But how would I do that?
reload(MainWindow) does not work. Any suggestions?

Thanks in advance.


-
import os
import wx
ID_ABOUT=101
ID_EXIT=110
class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,wx.ID_ANY, title, size = ( 200,100),

style=wx.DEFAULT_FRAME_STYLE|
wx.NO_FULL_REPAINT_ON_RESIZE)
self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A StatusBar in the bottom of the window
# Setting up the menu.
filemenu= wx.Menu()
filemenu.Append(ID_ABOUT, "&About"," Information about this program")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the
MenuBar
self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event
ID_ABOUT to the
   # method
self.OnAbout
wx.EVT_MENU(self, ID_EXIT, self.OnExit)   # attach the menu-event
ID_EXIT to the
   # method
self.OnExit
self.Show(True)
def OnAbout(self,e):
d= wx.MessageDialog( self, " A sample editor \n"
" in wxPython","About Sample Editor", wx.OK)
# Create a message dialog box
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Close(True)  # Close the frame.
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop()

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


Re: [Tutor] wxPython problem

2005-09-26 Thread Øyvind
Sorry... Forgot all about that.

Using WinXP, ActiveState Python 2.3 and wx-version 2.6.1.0.

I run it in ActiveStates Interactive Window, which is IDLE (I think).

Thanks in advance



http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unicode trouble

2005-11-30 Thread Øyvind
Hello.

I am writing a program that reads in a text file, extracts each of the
words and replaces a different document with the words. It works great
until it encounter a non-english letter.

I have tried the following:

self.f = codecs.open(ordliste, 'r', 'utf-8')
where I open the first file.

And
en = unicode(en)
en = en.encode('utf-8')

as well as
en = en.decode('iso-8859-1')

where
each word is entered from the document.

But, still, I get this error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 17:
ordinal not in range(128)

As well as this:
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 168-170:
invalid data
if I skips the second part.

What is wrong? How can I fix this? I am using ActiveState Python 2.3 and
WinXp.

Thanks in advance...


This is the whole source:

from win32com.client import Dispatch
import time
import codecs

class oversett:
def __init__(self, ordliste, dokument):
objWord = Dispatch("Word.Application")
self.f = codecs.open(ordliste, 'r', 'utf-8')
#self.f = open(ordliste)
objDoc =  objWord.Documents.Open(dokument)
self.objSelection = objWord.Selection

def kjor(self):
s = time.clock()
wdReplaceAll = 2
wdFindContinue = 1
t = 1
for i in self.f.readlines():
en = i.split('\t')[0]
#en = str(en).decode('iso-8859-1')
#en = en.decode('iso-8859-1')
en = unicode(en)
en = en.encode('utf-8')
print en
to = i.split('\t')[1]
#to = str(to).decode('iso-8859-1')
#to = to.decode('iso-8859-1')
to = unicode(to)
to = to.encode('utf-8')
t = t + 1
if t % 1000 == 0:
print t
try:
self.objSelection.Find.Execute(en, False, True, False,
False, True, True, wdFindContinue, True, to, wdReplaceAll,
False, False, False, False)
except UnicodeEncodeError:
print 'pokker'
except:
pass

print time.clock() - s

if __name__ == '__main__':
n = oversett('c:/ordliste.txt','c:/foo.doc')
n.kjor()


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Unicode trouble

2005-11-30 Thread Øyvind


>Where are you getting these errors (what line of the program)? Do you
know >what kind of strings objSelection.Find.Execute() is expecting?
>
>Kent

The program stops working and gives me these errors when I try to run it
when it encounters a non-english letter.

This is the full error:
Traceback (most recent call last):
  File
"C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
  File "C:\Python\BA\Oversett.py", line 47, in ?
  File "C:\Python\BA\Oversett.py", line 23, in kjor
en = i.split('\t')[0]
  File "C:\Python23\lib\codecs.py", line 388, in readlines
return self.reader.readlines(sizehint)
  File "C:\Python23\lib\codecs.py", line 314, in readlines
return self.decode(data, self.errors)[0].splitlines(1)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 168-170:
invalid data

and

Traceback (most recent call last):
  File
"C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
  File "C:\Python\BA\Oversett.py", line 49, in ?
  File "C:\Python\BA\Oversett.py", line 33, in kjor
if t % 1000 == 0:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 17:
ordinal not in range(128)

objSelection.Find.Execute() is supposed to accept any kind of string. (It
is the function Search & Replace in MS Word).



-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Unicode trouble

2005-11-30 Thread Øyvind
Øyvind wrote:
>
>>Where are you getting these errors (what line of the program)? Do you
>
> know >what kind of strings objSelection.Find.Execute() is expecting?
>
>>Kent
>
>
>> The program stops working and gives me these errors when I try to run it
>> when it encounters a non-english letter.
>
>> This is the full error:
>> Traceback (most recent call last):
>>   File
>> "C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
>> line 310, in RunScript
>> exec codeObject in __main__.__dict__
>>   File "C:\Python\BA\Oversett.py", line 47, in ?
>>   File "C:\Python\BA\Oversett.py", line 23, in kjor
>> en = i.split('\t')[0]
>>   File "C:\Python23\lib\codecs.py", line 388, in readlines
>> return self.reader.readlines(sizehint)
>>   File "C:\Python23\lib\codecs.py", line 314, in readlines
>> return self.decode(data, self.errors)[0].splitlines(1)
>> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 168-170:
>> invalid data

>This is fairly strange as the line
>  en = i.split('\t')[0]
>should not call any method in codecs. I don't know how you can get such a
>stack trace.

The file f where en comes from does contain lots of lines with one english
word followed by a tab and a norwegian one. (Approximately 25000 lines) It
can look like this: core\tkjærne
So en is supposed to be the english word that the program need to find in
MS Word, and to is the replacement word. So wouldn't that be a string that
should be handeled by codecs?

for i in self.f.readlines():
en = i.split('\t')[0]

>Maybe try deleting all the .pyc files to make sure they are in sync with
>the source and try again?

This didn't seem to help.

>The actual error indicates that the input data is not valid utf-8. Are
you >sure that is the correct encoding for the input file? If the file is
utf-8 >and has bad characters you could pass error='ignore' or
error='replace' as >a parameter to codecs.open() to change the error
handling style to >something more forgiving.

Is not valid utf-8? I have tried with latin-1 as well. No avail. The
letters that are the problem is æøå. They shouldn't be that exotic?

>> Traceback (most recent call last):
>>   File
>> "C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
>> line 310, in RunScript
>> exec codeObject in __main__.__dict__
>>   File "C:\Python\BA\Oversett.py", line 49, in ?
>>   File "C:\Python\BA\Oversett.py", line 33, in kjor
>> if t % 1000 == 0:
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 17:
>> ordinal not in range(128)

>Again this stack trace doesn't make sense, the indicated line doesn't do
>any string operation.

>This error message normally occurs when a non-ascii string is converted
to >unicode using the default encoding (which is 'ascii'). Often the
>conversion is implicit in some other operation but I don't see any such
>operation here.

But regardless, shouldn't 'ascii' be excluded here? Since I tell the
program to change to utf-8, not only once but twice?

>> objSelection.Find.Execute() is supposed to accept any kind of string. (It
>> is the function Search & Replace in MS Word).

>It has to make some assumption about the type of the string. Does it want
>unicode or encoded bytes? If encoded bytes, what encoding does it
expect?

I think the letters should be accepted. The pythonscript here is written
to replace abot 25000 MS Word-macros, so all the letters have been
accepted by MS Word when feeded by Visual Basic. All I have done now is to
extract the words from the macros and put them in a file.




-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Unicode trouble

2005-12-01 Thread Øyvind
Michael Lange wrote:

>> I haven't read all of this thread, but maybe you are trying to pass a
>> non-utf8 string to the utf8 codec?

>Yes, I guess that much is pretty clear - there is some data in the source
>file that is not valid utf-8.

I tried the error='replace' as you suggested and the program made it thru
the list. However, here are some results:

the gjenoppl�et gjenoppl�
from
the gjenoppløst det gjenoppløste

kan v� konsentrert
from
kan være konsentrert

I did check the site http://www.columbia.edu/kermit/utf8.html and the
letters that is the problem here are a part of the utf-8.

Is there anything else I could try?

Thanks in advance



-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Unicode trouble

2005-12-01 Thread Øyvind

>The important question is, what is actual encoding of your source data?
>>
>> Is there anything else I could try?

>Understand why the above question is important, then answer it. Until you
do >you are just thrashing around in the dark.

The source is a text-document that as far as I know only contains English
and Norwegian letters. It can be opened with Notepad and Excel. I tried to
run thru it in Python by:

f = open('c://file.txt')

for i in f:
print f

and that doesn't seem to give any problem. It prints all characters
without any trouble.

How would I find what encoding the document is in? All I can find is by
opening Notepad, selecting Font/Script and it says 'Western'.

Might the problem only be related to Win32com, not Python since Python
prints it without trouble?
>Do you know what a character encoding is? Do you understand the
difference >between utf-8 and latin-1?

Earlier characters had values 1-255. (Ascii). Now, you have a wider
choice. In our part of the world we can use an extended version which
contains a lot more, latin-1. UTF-8 is a part of Unicode and contains a
lot more characters than Ascii.

My knowledge about character encoding doesn't go much farther than this.
Simply said, I understand that the document that I want to read includes
characters beyond Ascii, and therefore I need to use UTF-8 or Latin-1. Why
I should use one instead of the other, I have no idea.



-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Unicode trouble

2005-12-04 Thread Øyvind

>> Might the problem only be related to Win32com, not Python since Python
>> prints it without trouble?

>That's another issue. First you need to know what you are starting with.

>You really should read this:
>The Absolute Minimum Every Software Developer Absolutely, Positively Must
>Know About Unicode and Character Sets (No Excuses!)
>http://www.joelonsoftware.com/articles/Unicode.html

>Kent

Thanks a lot for your help. I did actually get it to work. It didn't have
to do with the characters, but the flags that I set for Word. But, I did
learn a few things about characters in the process as well


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Socket connection

2005-12-04 Thread Øyvind
Hello.

I need to get some whois-info from whois.ripe.net. I have been able to
connect and get the info that I need, but I would like to know what is the
most 'polite' way of doing so. I need to do quite a few whois lookups
(from my server logs) and don't want to risk creating more hassle for
their server than necessary. So, what I would like to know, is what is the
best way of doing lots of requests?

This works like a dream:
>>> from socket import *
>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(('whois.ripe.net', 43))
>>> s.send("%s \n\n" % 'vg.no')
14
>>> data = s.recv(8196)

But if I thereafter do this:
>>> s.send("%s \n\n" % 'dagbladet.no')
11
>>> data = s.recv(8196)
Traceback (most recent call last):
  File "", line 1, in ?
error: (10053, 'Software caused connection abort')

It doesn't go quite as well. I saw on
http://www.amk.ca/python/howto/sockets/ that the socket is supposed to get
destroyed after one use.

But, if I try to connect again:
>>> s.connect(('whois.ripe.net', 43))
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 1, in connect
error: (10056, 'Socket is already connected')

It is already connected.

So it seems like I have to start again at the beginning:
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(('whois.ripe.net', 43))
..

But, I have 300 requests. Should I do this 300 times? And thereafter end
with:

>>> s.shutdown(1)
>>> s.close()

Or should I do this each time?

Or is there some other way to keep it open so that I can ask 300 times?

Thanks in advance


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] List-question

2005-12-19 Thread Øyvind
I have one function that finds some values. Then I want that function to
find new values based on the values it found first. However, by just
looping, it starts on an eternal job.

As illustrated in:
>>> list = [1,2,3]
>>> list2 = list
>>> list2
[1, 2, 3]
>>> for i in list:
... print i
... list2.append(4)
...
1
2
3
4
4
4 and it will forever continue with 4's.

Why would list be expanded with the values of list2? How can I copy the
result from one list, and do things with the list without getting it to
expand?


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Web-log, not blog

2006-01-06 Thread Øyvind
Hello.

I am trying to find some Pythonmodules to work with some webserver logs. I
have found http://www.mnot.net/python/WebLog/, but it is very old (from
1999).   And when I try to serach in Google and so forth, all I get is
Python weblogs as in blogs. Do you have some suggestions of other sites
about analyzing webtraffic with Python?

Thanks in advance


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Whois

2006-01-15 Thread Øyvind
Hello.

I am trying to write a module that lets me check whois-info of ip-adresses:

import socket

class whois:
pass

def ip(self, adresse):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.connect(('whois.ripe.net', 43))
#self.s.connect(('whois.norid.no', 43))
self.s.send("%s \n\n" % adresse)
self.data = self.s.recv(8196)
self.page = ''
self.page = self.page + self.data
return self.page

If I run the module I get the following:
>>import whois
>>from whois import *
>>n = whois()
>>n.ip('193.12.32.16')
'% This is the RIPE Whois query server #2.\n% The objects are in RPSL
format.\n%\n% Note: the default output of the RIPE Whois server\n% is
changed. Your tools may need to be adjusted. See\n%
http://www.ripe.net/db/news/abuse-proposal-20050331.html\n% for more
details.\n%\n% Rights restricted by copyright.\n% See
http://www.ripe.net/db/copyright.html\n\n'

This is just the first part of the whois-info.

However, if I don't write it into a function:

>>import socket
>>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>s.connect(('whois.ripe.net', 43))
>>s.send("%s \n\n" % '193.12.32.16')
15
>>data = s.recv(8196)
>>page = ''
>>page = page + data
>>page
'% This is the RIPE Whois query server #2.\n% The objects are in RPSL
format.\n%\n% Note: the default output of the RIPE Whois server\n% is
changed. Your tools may need to be adjusted. See\n%
http://www.ripe.net/db/news/abuse-proposal-20050331.html\n% for more
details.\n%\n% Rights restricted by copyright.\n% See
http://www.ripe.net/db/copyright.html\n\n% Note: This output has been
filtered.\n%   To receive output for a database update, use the "-B"
flag\n\n% Information related to \'193.12.32.0 -
193.12.39.255\'\n\ninetnum:  193.12.32.0 - 193.12.39.255\nnetname:
 SE-CLAVISTER-NET\ndescr:Clavister AB/\xd6vikshem KabelTV\n   
  tidigare Enternet Sweden AB\n  \xd6rnsk\xf6ldsvik\n 
\n  In case of
improper use, please mail\n  [EMAIL PROTECTED] or
[EMAIL PROTECTED] so forth.

Now I get everything, not only the first part as I did above. Why? And
what should I do with the module in order to get all the info?

Thanks in advance.


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] wxPython

2006-01-30 Thread Øyvind
Hello.

I have made some programs using wxPython (PythonCard). They all seem to
have one common nominator. When the program are doing something unrelated
unrelated to the graphics (for example, ftp's, works with a document or a
file), the graphics freezes. It does unfreeze afterwards, but since the
working with the other files might take a few minutes, the user assumes my
program has crashed. How can I avoid that the graphics freeze.

Thanks in advance


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Bits

2006-04-04 Thread Øyvind
Hello.

Is it possible to read the bits (the 0's and 1's) of a string or a file
with Python? What module would I use?

Thanks in advance,
Øyvind


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Webbrowser

2006-04-11 Thread Øyvind
Hello.

I have recently discovered the Webbrowser module, and have started using
it instead of just using IE thru win32com. But, have a few questions:

1) Is it possible to give it an adress, and if the browser gets a redirect
to a different adress, I can override it? For example, I tell the browser
to open a site. The browser tries, but gets redirected to a spam-site. I
would therefore like to send the user somewhere else. Is it possible?

2) It doesn't seem like open(url[, new=0][, autoraise=1]) new and
autoraise work with Firefox. I have tried all possible comboes, but the
site is opened in a new tab in Firefox regardless. Any suggestions?

Thanks in advance,
Øyvind


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


Re: [Tutor] doubt plz help

2006-06-06 Thread Øyvind
Try to rephrase that question. I don't think I was the only one not
understanding what you are asking?


>how do i clear the scseer ??
>suppose i have two pages to display one
>after the other ,how should i do it ?




-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] elif

2006-06-06 Thread Øyvind
Hello.

I need to make a program that does certain things every 5 minutes
mon-friday. I have started writing it like this:

if strftime('%w') == 1:
if strftime('%M') % 5 == 0:
n.start()

elif strftime('%w') == 2:
if strftime('%M') % 5 == 0:
n.start()



This seems kind of a redundant way of writing the code.

I haven't gotten any statement like this to work:
if strftime('%w') == 1 or 2 or 3:
or
for strftime('%w') in range(1,5):

What would be a more efficient way of writing it without writing it
several times?

Thanks in advance,
Øyvind


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] Threading

2006-06-28 Thread Øyvind
Hello.

I am trying to learn threading, and found a good example at:
http://effbot.org/librarybook/queue.htm (Using the Queue module with a
maximum size).

It works like a dream as is. But, I added it to a downloading-script I
have made before. The difference is that in my version it has a
wxPython-gui and download files. The module I use to download works great,
so does the gui.

So, when I start the downloading, the thread-example downloads from 20-80
files, and a box comes up, saying that Python has crashed. It ask if I
would like to shut down or debug. (On Win XP).

However, I can see the program run in the background as if nothing has
happened. What does cause an error like that? Two threads write to same
memoryspace?

And, does anyone know of some great sites where I can learn more about
threads? I have found a lot, but they are not basic enough. I have no idea
what a 'lock' is, as most all sites assumes one should. So, the simpler
the better...

Thanks in advance,
Øyvind


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] IP-range

2006-08-31 Thread Øyvind
Hello.

I have a database where I have some IP-ranges. Then I have some logs over
IPs from customers and need to connect the two.

So, for example:

Range 1:
123.132.122.4-123.132.122.255

How do I check if IP 123.132.122.58 is a part of that? I have thought
about 4 if statements:

split(.)
if ip[0] in iprange_from[0] and iprange_to[0]:
  if ip[1] in iprange_from[1] and iprange_to[1]:
if ip[2] in iprange_from[2] and iprange_to[2]:
  if ip[3] in iprange_from[3] and iprange_to[3]:
then ok

But that seems silly. Is there some better way?

Thanks in advance


-- 
This email has been scanned for viruses & spam by Domenebutikken - 
www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - 
www.domenebutikken.no

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


[Tutor] Patches

2007-01-04 Thread Øyvind
Hello.

I need to access SMTP with SSL and found this patch:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1567274&group_id=5470

But, I cannot find anything with Google or in the Python documentation
about how to apply a patch.

Ok, one slight modification. I did find something:

5.2   How do I apply a patch?

For the general case, to apply a patch go to the directory that the patch
was created from (usually /dist/src/) and run:

patch -p0 < name_of_the_patch.diff

The -p option specifies the number of directory separators ("/" in the
case of UNIX) to remove from the paths of the files in the patch. -p0
leaves the paths alone.

from http://www.python.org/dev/faq/#how-do-i-apply-a-patch

But, that didn't tell me anything. I am using Windows, and tried both to
enter that command in the CMD-window, as well as in the Python-IDLE. No
avail.

Is patch a program I have to download somewhere? Or can only patches be
used in Linux?

Thanks in advance.


-- 
This email has been scanned for viruses & spam by Domenebutikken - 
www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - 
www.domenebutikken.no

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


[Tutor] Webform

2007-03-26 Thread Øyvind
Hello.

I am trying to fill in a webform, and have tried using
Clientform/mechanize, but cannot seem to get it right. Here is the code:

from urllib2 import urlopen
import ClientForm
from ClientForm import ParseResponse

response =
urlopen("http://www.datateam.no/boc/bocadresse.nsf/wMedlemsoek?OpenForm&Seq=1";)
forms = ParseResponse(response, backwards_compat=False)
form = forms[0]
print form

form["QueryField"] = """980213250"""

print urlopen(form.click()).read()

It just gives me feedback that the form is processed, but I can't seem to
get the result I get if I manually enter the value with the browser.

Thanks in advance


-- 
This email has been scanned for viruses & spam by Domenebutikken - 
www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - 
www.domenebutikken.no

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


[Tutor] Sloooooow SQL

2007-03-30 Thread Øyvind
Hello.

I have been writing some scripts that gets data from a MSSQL-database.
However, it is very slow. If I use the script, the retrieving of data and
displaying in html takes close to 30 seconds. If I use the SQL Server
Management Query, the same query takes a second or two. Why this enormous
difference? Below is the top of one of the scripts.

Thanks in advance.


from win32com.client import Dispatch
import MSSQL
import cgitb, cgi, os, urllib
cgitb.enable()

print "Content-type: text/html"

print """

SQL
"""

form = cgi.FieldStorage()
db = MSSQL.connect('10.10.10.10','admin','admin','MYDB')
cursor = db.cursor()

ejfirma = """select x_firmanavn from ad_kopi order by x_firmanavn"""
cursor.execute(ejfirma)
result = cursor.fetchall()


-- 
This email has been scanned for viruses & spam by Domenebutikken - 
www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - 
www.domenebutikken.no

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


[Tutor] Some questions.

2007-04-13 Thread Øyvind
>One question is whats the best GUI library to build from?

WxPython is a very good one. However, you should look into Pythoncard
(http://pythoncard.sourceforge.net/) which lets you build WxPython even
easier.


-- 
This email has been scanned for viruses & spam by Domenebutikken - 
www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - 
www.domenebutikken.no

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Read same instance twice

2008-10-27 Thread Øyvind
Hello.

I am trying to gather some information from a webpage:

side = urlopen("http://www.website.no";)
rawstr = r"""spy.target="_top">(.*?)$"""
rawstr2 = r"""spy.target2="_top">(.*?)$"""

compile_obj = re.compile(rawstr,  re.IGNORECASE| re.MULTILINE| re.VERBOSE
| re.UNICODE)
compile_obj2 = re.compile(rawstr2,  re.IGNORECASE| re.MULTILINE|
re.VERBOSE | re.UNICODE)

liste = self.compile_obj.findall(side.read())

liste = self.compile_obj2.findall(side.read())

It works like a dream getting the first info, but the second doesn't work.
The instance is empty.

I have tried
side2 = side
side2 = side[:]
side2 = deepcopy(side)
side2 = copy(side)
and even side2 = cStringIO.StringIO(side)

But nothing works.

How can I easiest pick up more information from the site without opening
it more than once?

Thanks


-- 
This email has been scanned for viruses & spam by Domenebutikken - 
www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - 
www.domenebutikken.no

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


[Tutor] Web-log, not blog

2006-01-09 Thread Øyvind Dale Spørck



Hello and thank you
for your help. 
 
Scratchy seems like
a really good product...
 
Have a nice
day,
Øyvind
 
Øyvind wrote:
> Hello.
>
> I am trying to find some Pythonmodules to work with some webserver logs. I
> have found http://www.mnot.net/python/WebLog/, but it is very old (from
> 1999).   And when I try to serach in Google and so forth, all I get is
> Python weblogs as in blogs. Do you have some suggestions of other sites
> about analyzing webtraffic with Python?

Googling "+python webserver log analyze" and checking PyPI yielded a few
more choices:
http://mithrandr.moria.org/code/sisynala/
http://www.phil-schwartz.com/scratchy.spy

Kent

-
The information contained in this message may be CONFIDENTIAL 
and is intended for the addressee only. Any unauthorised use, 
dissemination of the information or copying of this message is prohibited. 
If you are not the addressee, please notify the sender immediately by return 
e-mail and delete this message.
Thank you.
Intility
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Microsoft Exchange

2007-04-13 Thread Øyvind Dale Spørck
Hello.

I need to get the mailbox size out from Exchange. I have been googling and
all I have found is how to get the size from my personal mailbox. But,
that is not what I need. I need to find the sizes of the mailboxes for all
users.

Does anyone know of any modules that works towards the central
Exchange-server or any example scripts that can give me any hints?

Thanks in advance


-- 
This email has been scanned for viruses & spam by Domenebutikken - 
www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - 
www.domenebutikken.no

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor