[issue1541] Bad OOB data management when using asyncore with select.poll()

2007-12-02 Thread billiejoex

New submission from billiejoex:

asyncore's module readwrite() function, used when invoking
asyncore.loop(use_poll=1), erroneously calls handle_read_event() when
receiving OOB (Out Of Band) data. handle_expt_event() should be called
instead.
The patch in attachment does that.


In addition I strongly think that POLLERR, POLLHUP and POLLNVAL events
handling is incorrect too.
As far as I read from here:
http://www.squarebox.co.uk/cgi-squarebox/manServer/usr/share/man/man0p/poll.h.0p
...they refers to the following events:

POLLERR An error has occurred (revents only).
POLLHUP Device has been disconnected ( revents only).
POLLNVALInvalid fd member (revents only).

They are actually associated to handle_expt_event() and this is
incorrect since it should be called only when receiving OOB data.

if flags  (select.POLLERR | select.POLLHUP | select.POLLNVAL):
obj.handle_expt_event()

I'm not sure what should be called instead, if handle_read_event or
handle_read or handle_error.

I tried to take a look at how Twisted manages the thing but it seems
that OOB is not even supported.
Maybe someone with more experience in using select.poll could clarify that.

--
components: Library (Lib)
files: asyncore.diff
messages: 58093
nosy: billiejoex
severity: normal
status: open
title: Bad OOB data management when using asyncore with select.poll()
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file8854/asyncore.diff

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1541
__

asyncore.diff
Description: Binary data
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1519] async_chat.__init__() parameters

2007-11-30 Thread billiejoex

billiejoex added the comment:

+1.
Another inconsistency are the argument names used in __init__ methods,
one called sock and the other called conn:

asyncore:
def __init__(self, sock=None, map=None):

asynchat:
def __init__ (self, conn=None):

--
nosy: +billiejoex

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1519
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1736190] asyncore/asynchat patches

2007-11-15 Thread billiejoex

billiejoex added the comment:

The current implementation of asynchat.async_chat.initiate_send method
doesn't look at what is specified in ac_out_buffer_size attribute which
represents the buffer size of the outgoing data defaulting to a maximum
of 4096 bytes to send in a single socket.send() call.

Note that this only happens when sending the data by using a producer
through the use of the push_with_producer method.
This happens because while the older asynchat version used slicing for
buffering:

 num_sent = self.send(self.ac_out_buffer[:obs]) # obs == ac_out_buffer_size

...the newer version just calls self.send using the entire data as
argument without caring of what ac_out_buffer_size thinks about it:

 num_sent = self.send(first)

What is specified in ac_out_buffer_size when using a producer is just
ignored and the only way to have control over the outgoing data buffer
is to operate directly on the producer.

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1736190
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1376] uu module catches a wrong exception type

2007-11-02 Thread billiejoex

New submission from billiejoex:

uu module on line 53 erroneously tries to catch an AttributeError
exception type.

try:
mode = os.stat(in_file).st_mode
except AttributeError:
pass

This is not correct since os.stat(), as far as I know, should raise
OSError exceptions only.
This would turn in an error in case we pass a broken symlink as
in_file argument.

--
components: Library (Lib)
messages: 57077
nosy: billiejoex
severity: normal
status: open
title: uu module catches a wrong exception type
type: behavior
versions: Python 2.5

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1376
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1364] os.lstat documentation error

2007-11-01 Thread billiejoex

billiejoex added the comment:

What about other platforms?
I think it should be an alias for all platforms which does not support
symbolic links, not only Windows.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1364
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1364] os.lstat documentation error

2007-11-01 Thread billiejoex

billiejoex added the comment:

Thanks.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1364
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1345] Fix for test_netrc on Windows

2007-10-30 Thread billiejoex

Changes by billiejoex:


__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1345
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1364] os.lstat documentation error

2007-10-30 Thread billiejoex

New submission from billiejoex:

os module documentation says about lstat():

 lstat( path) 
 
 Like stat(), but do not follow symbolic links. 
 Availability: Macintosh, Unix. 

This is not true since os.lstat() is also available under Windows
(tested under Win XP sp, Python 2.5).

Moreover, wouldn't it be better having os.lstat() available on all
platforms and turn it into an alias of os.stat on those platforms which
do not support symbolic links?

--
components: Documentation
messages: 56982
nosy: billiejoex
severity: normal
status: open
title: os.lstat documentation error
versions: Python 2.5

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1364
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1745035] DoS smtpd vulnerability

2007-10-21 Thread billiejoex

billiejoex added the comment:

 What does this do when a line longer than 4096 bytes 
 is found?  Does it report an error to the SMTP client?  
 That's my only concern.

Sorry for replying so late. 
No, it does not report the error and this is bad.
I've searched through RFCs and I found that RFC 821 and RFC 2821 at
chapter 4.2.2 say that a 500 Syntax error, command unrecognized
response could be used to report errors such as command lines too long.

Modified smtpd.py in attachment. It should be definitively fine for
inclusion now.

--
severity: normal - urgent
type:  - security
Added file: http://bugs.python.org/file8586/smtpd.py

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1745035
_#! /usr/bin/env python
An RFC 2821 smtp proxy.

Usage: %(program)s [options] [localhost:localport [remotehost:remoteport]]

Options:

--nosetuid
-n
This program generally tries to setuid `nobody', unless this flag is
set.  The setuid call will fail if this program is not run as root (in
which case, use this flag).

--version
-V
Print the version number and exit.

--class classname
-c classname
Use `classname' as the concrete SMTP proxy class.  Uses `PureProxy' by
default.

--debug
-d
Turn on debugging prints.

--help
-h
Print this message and exit.

Version: %(__version__)s

If localhost is not given then `localhost' is used, and if localport is not
given then 8025 is used.  If remotehost is not given then `localhost' is used,
and if remoteport is not given, then 25 is used.



# Overview:
#
# This file implements the minimal SMTP protocol as defined in RFC 821.  It
# has a hierarchy of classes which implement the backend functionality for the
# smtpd.  A number of classes are provided:
#
#   SMTPServer - the base class for the backend.  Raises NotImplementedError
#   if you try to use it.
#
#   DebuggingServer - simply prints each message it receives on stdout.
#
#   PureProxy - Proxies all messages to a real smtpd which does final
#   delivery.  One known problem with this class is that it doesn't handle
#   SMTP errors from the backend server at all.  This should be fixed
#   (contributions are welcome!).
#
#   MailmanProxy - An experimental hack to work with GNU Mailman
#   www.list.org.  Using this server as your real incoming smtpd, your
#   mailhost will automatically recognize and accept mail destined to Mailman
#   lists when those lists are created.  Every message not destined for a list
#   gets forwarded to a real backend smtpd, as with PureProxy.  Again, errors
#   are not handled correctly yet.
#
# Please note that this script requires Python 2.0
#
# Author: Barry Warsaw [EMAIL PROTECTED]
#
# TODO:
#
# - support mailbox delivery
# - alias files
# - ESMTP
# - handle error codes from the backend smtpd

import sys
import os
import errno
import getopt
import time
import socket
import asyncore
import asynchat

__all__ = [SMTPServer,DebuggingServer,PureProxy,MailmanProxy]

program = sys.argv[0]
__version__ = 'Python SMTP proxy version 0.2'


class Devnull:
def write(self, msg): pass
def flush(self): pass


DEBUGSTREAM = Devnull()
NEWLINE = '\n'
EMPTYSTRING = ''
COMMASPACE = ', '



def usage(code, msg=''):
print  sys.stderr, __doc__ % globals()
if msg:
print  sys.stderr, msg
sys.exit(code)



class SMTPChannel(asynchat.async_chat):
COMMAND = 0
DATA = 1

def __init__(self, server, conn, addr):
asynchat.async_chat.__init__(self, conn)
self.__server = server
self.__conn = conn
self.__addr = addr
self.__line = []
self.__in_buffer_len = 0
self.__state = self.COMMAND
self.__greeting = 0
self.__mailfrom = None
self.__rcpttos = []
self.__data = ''
self.__fqdn = socket.getfqdn()
self.__peer = conn.getpeername()
print  DEBUGSTREAM, 'Peer:', repr(self.__peer)
self.push('220 %s %s' % (self.__fqdn, __version__))
self.set_terminator('\r\n')

# Overrides base class for convenience
def push(self, msg):
asynchat.async_chat.push(self, msg + '\r\n')

# Implementation of base class abstract method
def collect_incoming_data(self, data):
self.__line.append(data)
self.__in_buffer_len += len(data)
if self.__in_buffer_len  998:
self.push('500 Line too long')
self.__line = []
self.__in_buffer_len = 0

# Implementation of base class abstract method
def found_terminator(self):
line = EMPTYSTRING.join(self.__line)
print  DEBUGSTREAM, 'Data:', repr(line)
self.__line = []
self.__in_buffer_len = 0
if self.__state == self.COMMAND:
if not line:
self.push('500 Error: bad syntax')
return
method

[issue1745035] DoS smtpd vulnerability

2007-10-21 Thread billiejoex

Changes by billiejoex:


Added file: http://bugs.python.org/file8587/smtpd.diff

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1745035
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



How can I test 'warnings' from testsuite?

2007-09-10 Thread billiejoex
Hi there,
into a module of mine I 'warn' a message if a certain situation
occurs:


def add_anonymous_user(permissions=('r'):
  if 'w' in p:
  import warnings
  warnings.warn(it's not rencommended assigning 'w'
permission to anonymous user., RuntimeWarning, stacklevel=2)


I'd like to test such event from test suite (fail test if warn is not
raised) but don't know how.

Any suggestion?

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


Re: How can I test 'warnings' from testsuite?

2007-09-10 Thread billiejoex
On 10 Set, 17:15, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 On Sep 10, 7:08 am, billiejoex [EMAIL PROTECTED] wrote:

  Hi there,
  into a module of mine I 'warn' a message if a certain situation
  occurs:

  def add_anonymous_user(permissions=('r'):
if 'w' in p:
import warnings
warnings.warn(it's not rencommended assigning 'w'
  permission to anonymous user., RuntimeWarning, stacklevel=2)

  I'd like to test such event from test suite (fail test if warn is not
  raised) but don't know how.

  Any suggestion?

 You can (temporarily) change warnings to exceptions
 for the purposes of testing; see filterwarnings in
 the warnings module.  E.g.,

 import warnings
 import unittest

 def foo():
 warnings.warn(Foo, RuntimeWarning, stacklevel=2)

 class testWarn(unittest.TestCase):
 def setUp(self):
 warnings.filterwarnings(error)
 def test_1(self):
 self.assertRaises(RuntimeWarning, foo)
 def tearDown(self):
 warnings.resetwarnings()

 s = unittest.TestSuite()
 s.addTest(unittest.makeSuite(testWarn))

 if __name__ == '__main__':
 import sys
 sys.argv.append('-v')
 unittest.TextTestRunner(verbosity=2).run(s)

 --
 Hope this helps,
 Steven

This is exactly what I was searching for.
Thank you very much.

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


distutils question

2007-09-10 Thread billiejoex
Hi there,
I'm having problems with creating an installer for a module of mine by
using distutils. I'll try to explain my problem as clear as I can
(sorry but English is not my first language).
This is the structure of my module:


setup.py
mypackage/
__init__.py
module.py
demo/
script.py
test/
 test_script.py
test
 test_module.py


By using distutils in such way a 'mypackage' directory within
'module.py' is created in python's 'site-packages' directory:

from distutils.core import setup
setup(
...
packages = ['mypackage'],
)


The problem is that I can't find a way for including demo and test
directories (along with files contained in them) into site-packages/
mypackage directory.
The only way I found is *moving* 'demo' and 'test' directories into
'mypackage' but I would want to avoid that, if possible.

Could someone point me in the right direction? I passed the entire
night without finding a clue...

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


os.sep and os.path.sep

2007-09-09 Thread billiejoex
 import os
 hasattr(os, 'sep')
True
 hasattr(os.path, 'sep')
True

By chance I noticed it.
Are there differences (I think not...)?
IMHO, if there are no differences os.path.sep should be removed since
it may be confusing.

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


Re: tempfile.mkstemp and os.fdopen

2007-08-29 Thread billiejoex
Gabriel Genellina wrote:

 As someone already suggested, why don't you use TemporaryFile or
 NamedTemporaryFile and avoid such problems?

Because I don't want file to be removed after closing.

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


tempfile.mkstemp and os.fdopen

2007-08-28 Thread billiejoex
Hi there.
I'm trying to generate a brand new file with a unique name by using
tempfile.mkstemp().
In conjunction I used os.fdopen() to get a wrapper around file
properties (write  read methods, and so on...) but 'name' attribute
does not contain the correct file name. Why?

 import os
 import tempfile
 fileno, name = tempfile.mkstemp(prefix='ftpd.', dir=os.getcwd())
 fd = os.fdopen(fileno, 'wb')
 fd.name
fdopen

Moreover, I'd like to know if I'm doing fine. Does this approach avoid
race conditions or other types of security problems?

Thanks in advance

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


Re: tempfile.mkstemp and os.fdopen

2007-08-28 Thread billiejoex
Thanks all.
Another question: I have to open file for writing ('wb') but I noticed
that both tempfile.mkstemp() and os.fdopen() accept a mode argument.
It's not clear *when* do I have to specify such mode. When using
tempfile.mkstemp?

 fileno, name = tempfile.mkstemp(text=False)
 fd = os.fdopen(fileno)

...or when using os.fdopen()?

 fileno, name = tempfile.mkstemp()
 fd = os.fdopen(fileno, mode='wb')

Moreover, what happens if I specify text mode when using mkstemp and
binary mode when using fdopen?

 fileno, name = tempfile.mkstemp(text=True)
 fd = os.fdopen(fileno, 'wb')


PS - I think that tempfile.mkstemp docstring should be enhanced to
cover such and other questions (e.g. I find reasonable that every user
using tempfile.mkstemp() should use also os.fdopen() in conjunction
but this isn't mentioned).

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


[issue1053] bogus attributes reported in asyncore doc

2007-08-28 Thread billiejoex

New submission from billiejoex:

http://docs.python.org/lib/module-asyncore.html

asyncore documentation erroneously report ac_in_buffer_size and
ac_out_buffer_size attributes which does not exist in
asyncore.dispatcher class. They're used in asynchat.async_chat class,
instead.
Moreover, asynchat documentation does not mention them.

--
components: Documentation
messages: 55396
nosy: billiejoex, josiahcarlson
severity: normal
status: open
title: bogus attributes reported in asyncore doc
versions: Python 2.5

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1053
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: tarfile module for version 2.2.3

2007-08-24 Thread billiejoex
On 24 Ago, 09:57, Antoon Pardon [EMAIL PROTECTED] wrote:
 I have to write a little program that has to run on a number of hosts.
 Versions of python range from 2.2.3. to 2.4.2.

 The easiest way to implement the necessary behaviour seems to me to
 use the tarfile module. However that was only introduced in 2.3
 I had a look in the code and at first sight couldn't find anything
 that would cause problems if I used this module with python 2.2.3.

 Could someone confirm that the tarmodule is compatible with python 2.2.
 I will try some tests myself but it would be nice to have confirmation
 from elsewhere.

 --
 Antoon Pardon

Try also the test suite (Lib/test/test_tarfile.py).

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


Re: Impersonate another user temporarily (Unix and Windows)

2007-08-23 Thread billiejoex
On 23 Ago, 10:38, Tim Golden [EMAIL PROTECTED] wrote:
 billiejoex wrote:
  Hi there. I'm writing a modification for a FTP server library I'm
  maintaining.
  Depending on the system I'd want to temporarily impersonate the logged
  user to perform actions on filesystem.
  Something like:

  try:
  change_user('user', 'password')
  os.rmdir('dir')
  except:
  print some error
  finally:
  change_user('old_user', 'password')

  On Unix I took at look at os.seteuid() and os.setegid() functions and
  I noticed they could be useful for my purpose.
  On Windows I have no idea about how could I emulate a similar
  behaviour.
  Could someone please point me in the right direction?

 (Warning: not tried, but at least gives you the things to Google for!)

 You need the win32security module from the pywin32 extensions. [1]
 In particular, you want to look at the LogonUser and
 ImpersonateLoggedOnUser functions.

 TJG

 [1]http://pywin32.sf.net- Nascondi testo tra virgolette -

 - Mostra testo tra virgolette -

Thanks for suggestion.
I made it.

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


Re: Impersonate another user temporarily (Unix and Windows)

2007-08-23 Thread billiejoex
On 23 Ago, 13:13, Chris Mellon [EMAIL PROTECTED] wrote:
 On 8/23/07, billiejoex [EMAIL PROTECTED] wrote:





  On 23 Ago, 10:38, Tim Golden [EMAIL PROTECTED] wrote:
   billiejoex wrote:
Hi there. I'm writing a modification for a FTP server library I'm
maintaining.
Depending on the system I'd want to temporarily impersonate the logged
user to perform actions on filesystem.
Something like:

try:
change_user('user', 'password')
os.rmdir('dir')
except:
print some error
finally:
change_user('old_user', 'password')

On Unix I took at look at os.seteuid() and os.setegid() functions and
I noticed they could be useful for my purpose.
On Windows I have no idea about how could I emulate a similar
behaviour.
Could someone please point me in the right direction?

   (Warning: not tried, but at least gives you the things to Google for!)

   You need the win32security module from the pywin32 extensions. [1]
   In particular, you want to look at the LogonUser and
   ImpersonateLoggedOnUser functions.

   TJG

   [1]http://pywin32.sf.net-Nascondi testo tra virgolette -

   - Mostra testo tra virgolette -

  Thanks for suggestion.
  I made it.

 Note that running your process as a user with enough priviledges to
 impersonate another user pretty much eliminates all the benefits of
 running as a low-priviledged user in the first place. Consider
 re-thinking your application model and having an ftp user instead.- 
 Nascondi testo tra virgolette -

 - Mostra testo tra virgolette -

Could you be more precise?
Why it's not a good idea?
I was thinking of starting ftpd as limited user ('nobody'/'ftp' on
unix, 'Guest' on Windows), then temporary switching to another user
when I got to perform actions on file system.
Maybe you're saying that as limited user I can't do such switching?

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


Re: Impersonate another user temporarily (Unix and Windows)

2007-08-23 Thread billiejoex
On 23 Ago, 23:20, Steve Holden [EMAIL PROTECTED] wrote:
 billiejoex wrote:
  On 23 Ago, 13:13, Chris Mellon [EMAIL PROTECTED] wrote:
 [...]
  Note that running your process as a user with enough priviledges to
  impersonate another user pretty much eliminates all the benefits of
  running as a low-priviledged user in the first place. Consider
  re-thinking your application model and having an ftp user instead.- 
  Nascondi testo tra virgolette -

  - Mostra testo tra virgolette -

  Could you be more precise?
  Why it's not a good idea?
  I was thinking of starting ftpd as limited user ('nobody'/'ftp' on
  unix, 'Guest' on Windows), then temporary switching to another user
  when I got to perform actions on file system.
  Maybe you're saying that as limited user I can't do such switching?

 That's exactly what he's saying.

 regards
   Steve
 --
 Steve Holden+1 571 484 6266   +1 800 494 3119
 Holden Web LLC/Ltd  http://www.holdenweb.com
 Skype: holdenweb  http://del.icio.us/steve.holden
 --- Asciimercial --
 Get on the web: Blog, lens and tag the Internet
 Many services currently offer free registration
 --- Thank You for Reading -- Nascondi testo tra 
 virgolette -

 - Mostra testo tra virgolette -

Uhm... I'm confused.
Which kind of aproach is generally adopted in such cases?

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


Re: Extracting the traceback

2007-08-22 Thread billiejoex
On 22 Ago, 03:11, Evan Klitzke [EMAIL PROTECTED] wrote:
 On 8/21/07, codesite-noreply [EMAIL PROTECTED] wrote:





  On 22 Ago, 02:09, Evan Klitzke [EMAIL PROTECTED] wrote:
   On 8/21/07, billiejoex [EMAIL PROTECTED] wrote:

Hi there,
I'm facing a case where I need to get the traceback outptut when
occurring an exception.
I solved such problem by using traceback module in conjunction with
StringIO:

import StringIO, traceback
try:
raise Exception
except:
f = StringIO.StringIO()
traceback.print_exc(file=f)
print f.getvalue()

... but this seems a little poor to me since I first put output into
the StringIO.StringIO(), then I get it back by using getvalue() on
it.
Is there a way to avoid the use of StringIO and get such output
without using such (useless) additional step?

   If you just want to print the output (as in your example), you can use
   file=sys.stdout or file=sys.stderr in the call to print_exc. If you
   want to store the traceback into a string for some other purpose (e.g.
   logging, email notifications) I believe that you must use a StringIO
   object.

   --
   Evan Klitzke [EMAIL PROTECTED]

  Unfortunately I have to pass the output to a function which prints the
  passed string both on screen and into a log file.
  Anyway, not too much important. I'll use StringIO if there's no other
  solution.

 Turns out I was wrong -- you can just get the string, using format_exc
 rather than print_exc.

 --
 Evan Klitzke [EMAIL PROTECTED]- Nascondi testo tra virgolette -

 - Mostra testo tra virgolette -

Thanks

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


Impersonate another user temporarily (Unix and Windows)

2007-08-22 Thread billiejoex
Hi there. I'm writing a modification for a FTP server library I'm
maintaining.
Depending on the system I'd want to temporarily impersonate the logged
user to perform actions on filesystem.
Something like:

try:
change_user('user', 'password')
os.rmdir('dir')
except:
print some error
finally:
change_user('old_user', 'password')

On Unix I took at look at os.seteuid() and os.setegid() functions and
I noticed they could be useful for my purpose.
On Windows I have no idea about how could I emulate a similar
behaviour.
Could someone please point me in the right direction?


Thanks in advance

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


Re: libgmail failure

2007-08-21 Thread billiejoex
On 21 Ago, 23:07, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 Hey all,

 I've been using libgmail to send out automated notification emails for
 my company's nightly regression testing.  Last night these emails
 started failing, though the python code has not changed.  I updated to
 the latest libgmail, but that isn't helping.  I've logged in to the
 email account directly, and the account is still working fine.

 The error I get is HTTP Error 400: Bad Request when using
 gmailAccount.login().  This doesn't throw an exception, just prints
 the error.  The code crashes outright when it tries to send mail.

 This code has been up and running for several months and just started
 failing last night.  Does anyone have an idea what's going on?

 The code and error follow (fairly short :-)

 Thanks much,
 James

 Code:
 ---­
 def send(TO_LIST,SUBJECT,MESSAGE):
 GA = libgmail.GmailAccount([EMAIL PROTECTED],xxx)
 try:
 print Logging in
 GA.login()
 except libgmail.GmailLoginFailure:
 print \nLogin failed. (Wrong username/password?)
 else:
 print Log in successful.\n
 for RX in TO_LIST:
 MSG = libgmail.GmailComposedMessage(RX,SUBJECT,MESSAGE)
 if GA.sendMessage(MSG):
 print Message successfully sent to `%s` . % RX
 else:
 print Could not send message.
 ---­

 Output:
 ---­
 Logging in
 HTTP Error 400: Bad Request
 Log in successful.

 No messages found
 Traceback (most recent call last):
   File C:\projects\physware\testCases\PythonTestScripts
 \SendEmail.py, line 58, in module
 main()
   File C:\projects\physware\testCases\PythonTestScripts
 \SendEmail.py, line 55, in main
 send(TO_LIST,SUB,MSG)
   File C:\projects\physware\testCases\PythonTestScripts
 \SendEmail.py, line 39, in send
 if GA.sendMessage(MSG):
   File C:\projects\physware\testCases\PythonTestScripts\libgmail.py,
 line 588, in sendMessage
 U_ACTION_TOKEN: self._getActionToken(),
   File C:\projects\physware\testCases\PythonTestScripts\libgmail.py,
 line 563, in _getActionToken
 at = self._cookieJar._cookies[ACTION_TOKEN_COOKIE]
 KeyError: 'GMAIL_AT'
 ---­

Don't know if it's for the same reason since I can't remember if the
error was the same, but some times ago I had a similar problem.
I used libgmail for copying a lot of mails from a google mail box to
another and I've been black-listed after a while for flooding.
After that I wasn't neither able to access my account from browser for
a certain amount of time (one or two days).
Try to do same operation 'manually' (by using a browser try to log-in
by using your account, then send a mail) and see if you're able to do
so.

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

Extracting the traceback

2007-08-21 Thread billiejoex
Hi there,
I'm facing a case where I need to get the traceback outptut when
occurring an exception.
I solved such problem by using traceback module in conjunction with
StringIO:

import StringIO, traceback
try:
raise Exception
except:
f = StringIO.StringIO()
traceback.print_exc(file=f)
print f.getvalue()

... but this seems a little poor to me since I first put output into
the StringIO.StringIO(), then I get it back by using getvalue() on
it.
Is there a way to avoid the use of StringIO and get such output
without using such (useless) additional step?

Thanks in advance

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


Re: IDE for Python

2007-08-21 Thread billiejoex
On 21 Ago, 22:36, Brad Johnson [EMAIL PROTECTED] wrote:
 Joel Andres Granados joel.granados at gmail.com writes:



  Hello list:

  I have tried various times to use an IDE for python put have always been
  disapointed.

 Not sure which platform you're on, but I've really liked PyScripter for the
 Windows platform.

+1
I'm a satisfied user too.

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


tempfile behavior

2007-08-09 Thread billiejoex
Hi all,
I would like to use tempfile module to generate files having unique
names excepting that I don't want them to be removed after closing.
Does it is possible?

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


Re: tempfile behavior

2007-08-09 Thread billiejoex
On 9 Ago, 20:31, [EMAIL PROTECTED] wrote:
 On Aug 9, 11:21 am, billiejoex [EMAIL PROTECTED] wrote:

  Hi all,
  I would like to use tempfile module to generate files having unique
  names excepting that I don't want them to be removed after closing.
  Does it is possible?

 Looks like tempfile.mkstemp() will do what you want.

 '''Unlike TemporaryFile(), the user of mkstemp() is responsible for
 deleting the temporary file when done with it.'''

 ~Sean

Thank you, it seems good.
Just another question:

 fd, filename = tempfile.mkstemp()
 type(fd)
type 'int'

I would expect a file descriptor, not and integer.
How do I have to use it?

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


Re: Unable to abort a FTP command?

2007-07-25 Thread billiejoex
On 25 Lug, 09:48, [EMAIL PROTECTED] wrote:
 Hi,
 I write the following script to retrieve a part of a large file
 from a FTP site:

 import ftplib

 class ftp_getter(object):

 def __init__(self):
 self.handle = ftplib.FTP('ftp_server_address')
 self.handle.set_debuglevel(2)
 self.login()

 def login(self):
 self.handle.login('user', 'pass')
 self.handle.cwd('/temp1/')

 def quit(self, is_close = False):
 self.handle.quit()
 if is_close:
 self.handle.close()
 print 'ftp handle closed'

 def getpart_callback(self, received):
 print received a packet
 if self.cnt = 0:
 if not self.outf.closed:
 self.outf.close()
 if not self.aborted:
 try:
 self.handle.abort()
 self.aborted = True
 except Exception,ex:
 pass
 else:
 print 'received packet, [0] = %x' % ord(received[0])
 self.outf.write(received)
 self.cnt -= len(received)

 def getpart(self, ftp_filename, rest, cnt, out_filename):
 self.outf = open(out_filename, 'wb')
 self.cnt = cnt
 self.aborted = False
 self.handle.retrbinary('RETR ' + ftp_filename,
 self.getpart_callback, 8192, rest)
 if not self.outf.closed:
 self.outf.close()

 if __name__ == '__main__':
 g = ftp_getter()
 g.getpart('FILE_TO_RETRIEVE.DAT', 5, 20, 'out.dat')
 g.quit(True)
 print all done.

 As the last four lines shown, I want to connect to my FTP server,
 retrieve 20 bytes starting at offset 5 from FILE_TO_RETRIEVE.DAT,
 and stop retrieving after more than 20 bytes have been received. It's
 quite simple, but to my suprise, this code does not work.
 self.handle.abort() have been executed and I got the expected
 response from server(426),  but the RETR command does not seem to stop
 at all. More and more data are received and getpart_callback method is
 called again and again.
 Why the RETR command is not actually aborted? Can anyone help me?

 Thanks

 Xu Wang

I would *strongly* rencommend avoid using ABOR.
The easiest way to abort the data transfer is to simply close the data
connection.
Instead of using ftp.retrbinary you could 'handle' the data connetion
('manually') by yourself.
The code below starts RETRieving a file, and quit when more than 2^19
bytes are transmitted (not tested).
Hope this helps.


fd = open('retrieved_file', 'wb')

ftp = ftplib.FTP()
ftp.connect(host=host, port=port)
ftp.login(user=user, passwd=pwd)

# use binary transfer type
ftp.voidcmd('TYPE I')
conn = ftp.transfercmd('retr 1.tmp', rest=None)
bytes_recv = 0
while 1:
chunk = conn.recv(8192)
# stop transfer while it isn't finished yet
if bytes_recv = 524288: # 2^19
break
elif not chunk:
break
fd.write(chunk)
bytes_recv += len(chunk)
conn.close()
# here we should get a 426 response
ftp.voidresp()
fd.close()
ftp.close()

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


How to tell when a socket is closed on the other end?

2007-07-25 Thread billiejoex
Hi there.
I'm setting up test suite for a project of mine.
From test suite, acting as a client, I'd like to know, in certain
situations, if the socket is closed on the other end or not.
I noticed that I can detect such state if a call to socket.read()
returns 0 but it seems a little poor to me. :-\
Is there a reliable way to test such socket 'state'?

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


Re: How to tell when a socket is closed on the other end?

2007-07-25 Thread billiejoex
On 25 Lug, 16:37, Roy Smith [EMAIL PROTECTED] wrote:

 This isn't really a Python question, it's a Berkeley Socket API question.  
 You don't say, but I assume you're talking about a TCP (i.e. SOCKSTREAM)
 connection?

Yes.

 The answer is you can use the select() system call to detect exceptional
 conditions on a socket.  Python's select module provides this
 functionality, but to understand how to use it, you need to study the
 underlying API.

 On the other hand, socket.read() returning 0 works too.  What do you find
 poor about that?  What do you want to know about the connection being
 closed that you don't find out by getting 0 back from read()?

'poor' because it's 'tricky', since that send/write() and recv/read()
should be used for other tasks...
As far as I can tell this works on Linux and Windows, but I don't know
on other platforms.

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


asyncore and OOB data

2007-07-11 Thread billiejoex
Hi there,
In an asyncore based FTP server I wrote I should be able to receive
OOB data from clients.
A client sending such kind of data should act like this:

 import socket
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.connect(('127.0.0.1', 21))
 s.sendall('hello there\r\n', socket.MSG_OOB)

According to asyncore documentation I should handle this kind of event
in handle_expt method of dispatcher class, that should be called
when OOB is received by the underlying socket. I've tried to override
handle_expt method in such way:

def handle_expt(self):
print OOB data arrived
data = self.socket.recv(1024, socket.MSG_OOB)
print data

...but, even if it is called, data contains only a \n character
instead of the entire string (hello there\r\n).
Why does this happen? Should I have to use a different approach?

Thanks in advance.

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


Re: asyncore and OOB data

2007-07-11 Thread billiejoex
If it could be useful I attach the complete server application I used
for doing tests:


 code 

import asyncore, asynchat, socket, os

class Handler(asynchat.async_chat):
def __init__(self, sock_obj):
asynchat.async_chat.__init__(self, conn=sock_obj)
self.remote_ip, self.remote_port = self.socket.getpeername()
self.in_buffer = 
self.out_buffer = 
self.set_terminator(\r\n)

def handle_expt(self):
print OOB data arrived
data = self.socket.recv(1024, socket.MSG_OOB)
print tuple(data)

def collect_incoming_data(self, data):
self.in_buffer += data

def found_terminator(self):
print self.in_buffer
self.in_buffer = ''

def handle_error(self):
raise


class Server(asyncore.dispatcher):

def __init__(self):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
if os.name == 'posix':
self.set_reuse_addr()
self.bind(('', 21))
self.listen(5)

def handle_accept(self):
sock_obj, addr = self.accept()
Handler(sock_obj)

def handle_error(self):
raise


Server()
asyncore.loop(timeout=1)

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


Re: asyncore and OOB data

2007-07-11 Thread billiejoex
Douglas Wells wrote:

 Second, when I look at the FTP specification, I don't find the
 concept of OOB anywhere.  So, it's not clear what OOB data would
 mean in terms of the defined FTP commands in any case.

Steve Holde wrote:

 You are correct, however, in stating that the FTP
 protocol doesn't support or implement out-of-band
 data transmissions.


Wait a sec. RFC959 [1], on chapter 4.1.3 says:

 Certain commands (such as ABOR, STAT, QUIT) may be sent over the
 control connection while a data transfer is in progress.  Some
 servers may not be able to monitor the control and data connections
 simultaneously, in which case some special action will be necessary
 to get the server's attention.  The following ordered format is
 tentatively recommended:

 1. User system inserts the Telnet Interrupt Process (IP) signal
 in the Telnet stream.
 2. User system sends the Telnet Synch signal.
 3. User system inserts the command (e.g., ABOR) in the Telnet
 stream.
 4. Server PI, after receiving IP, scans the Telnet stream for
 EXACTLY ONE FTP command.

I believe that the TCP urgent flag, activated by using
socket.MSG_OOB, should be set when client must send the Sync signal
(RFC854 [2] talks about it). I think that you do not find references
of OOB in RFC959 (FTP) just because it is specified into RFC854
(Telnet).
According to RFC854 a Sync signal should consist of sending Telnet
DATA MARK (DM) inside a TCP packet with URGent flag set:

 The Synch is sent via the TCP send operation with the Urgent
 flag set and the DM as the last (or only) data octet.

If we'd want to traduce this in Python we could assume that a fully
RFC-compliant FTP client implementation sending 'ABOR' command should
act like this:

 import socket, telnetlib
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.connect(('127.0.0.1', 21))
 s.sendall(telnetlib.IP)
 s.sendall(telnetlib.DM, socket.MSG_OOB)
 s.sendall('ABOR\r\n')

We also could find references about such flag (URGent, alias OOB)
even in Bernstein FTP-related paper (http://cr.yp.to/ftp/
pipelining.html) which says:

 The client is required to send the TELNET string \377\364, and
 then send the TELNET string \377\362 with the TCP Urgent bit
 set, immediately before the ABOR request.

...that, traduced, should appear like this:

 s.sendall(\377\364) # Telnet IP signal?
 s.sendall(\377\362, socket.MSG_OOB) # Telnet Synch signal?
 s.sendall(ABOR\r\n)


I also find interesting the fact that ftplib ABOR command
implementation is not RFC-compliant (and I can't realize how my server
could recognize it):

def abort(self):
'''Abort a file transfer.  Uses out-of-band data.
This does not follow the procedure from the RFC to send Telnet
IP and Synch; that doesn't seem to work with the servers I've
tried.  Instead, just send the ABOR command as OOB data.'''
line = 'ABOR' + CRLF
if self.debugging  1: print '*put urgent*',
self.sanitize(line)
self.sock.sendall(line, MSG_OOB)
resp = self.getmultiline()
if resp[:3] not in ('426', '226'):
raise error_proto, resp


[1] http://www.faqs.org/rfcs/rfc959.html
[2] http://www.faqs.org/rfcs/rfc854.html

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


glob.glob standardization

2007-06-27 Thread billiejoex
os.listdir(path) return a list of file names independently if the path-
argument used is absolute or relative:

 os.getcwd()
'/home/user'
 os.listdir('Desktop')
['file.py']
 os.listdir('/home/user/Desktop')
['file.py']

glob.glob, instead, return file names only if given path is relative:

 os.chdir('Desktop')
 os.getcwd()
'/home/user/Desktop
 glob.glob(*)
['file.py']

...and absolute file names if given path is absolute:

 glob.glob('/home/user/Desktop/*')
['/home/user/Desktop/file.py']

Don't you think it would be more convenient for glob.glob to return
file names only in any case, like os.listdir do?

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


Re: How can I know the name of caller

2007-06-20 Thread billiejoex
On 20 Giu, 06:52, John Nagle [EMAIL PROTECTED] wrote:
 billiejoex wrote:
  Hi there,
  unfortunately, I'm compelled to apply a sort of monkey patching at the
  code of an existing libreary that I can't modify directly.
 ...

  ...(if it is possible) how can I get, from method called, the name
  of function/method that called it (in this case caller)?

  Bad idea.

  Note, though, that within Python, you can easily replace existing
 function definitions with your own.  This is something of a desperation
 measure, but it works.

 I have a small collection of patches to the standard Python libraries
 which I import.  (I've reported all of them in the tracker as bugs, and some
 later version of Python will contain the fixes. But that can take years.)

 John Nagle

Yeah, it seems really horrible to me too. Python is awesome but
stdlib, imo, lacks of properly maintenance.
I sincerely don't know what to do...
In a production environment what could be better? Overriding the
bugged method or including the patched version of the entire module
into the distribution?

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


How can I know the name of caller

2007-06-19 Thread billiejoex
Hi there,
unfortunately, I'm compelled to apply a sort of monkey patching at the
code of an existing libreary that I can't modify directly.
Here's my question
Having such code:

class test:

def caller(self):
self.b()

def called(self):
pass

...(if it is possible) how can I get, from method called, the name
of function/method that called it (in this case caller)?

Thanks in advance

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


Re: How can I know the name of caller

2007-06-19 Thread billiejoex
On 19 Giu, 22:50, Stefan Sonnenberg-Carstens
[EMAIL PROTECTED] wrote:
 billiejoex schrieb:



  Hi there,
  unfortunately, I'm compelled to apply a sort of monkey patching at the
  code of an existing libreary that I can't modify directly.
  Here's my question
  Having such code:

  class test:

  def caller(self):
  self.b()

  def called(self):
  pass

  ...(if it is possible) how can I get, from method called, the name
  of function/method that called it (in this case caller)?

  Thanks in advance

 inspect.stack is your friend ;-)- Nascondi testo tra virgolette -

 - Mostra testo tra virgolette -

Thank you man. That's what I was searching for.
This should be production code. Is insepct.stack fast enough?
Considering that I'd have to use inspect.stack inside a 'while'
statement looping different times, I wouldn't slow down my application.

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


os.path.normpath bug?

2007-06-14 Thread billiejoex
Hi there,
I've noticed that os.path.normpath does not collapse redundant
separators if they're located at the beginning of the string:

 print os.path.normpath('/a//b//c')
\a\b\c
 print os.path.normpath('//a//b//c')
\\a\b\c

Is it intentional or is it a bug?

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


Re: os.path.normpath bug?

2007-06-14 Thread billiejoex
On 14 Giu, 22:35, Michael Hoffman [EMAIL PROTECTED] wrote:

 Intentional.

 http://en.wikipedia.org/wiki/Path_(computing)#Universal_Naming_Conven...
 --
 Michael Hoffman

Got it.
Thank you.


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


Re: FTP Date Format Function

2007-06-14 Thread billiejoex
On 14 Giu, 19:25, samuraisam [EMAIL PROTECTED] wrote:
 FTP LST/LIST/NLST date field formatting function for all those seekers
 out there...

 import time
 import datetime

 def ftpdateformat(value):
 Formats dates from most FTP servers
 if : in value: # within 6 months
 return datetime.datetime(
 *time.strptime( # have to guess this calculation
 %s %s % (value, datetime.datetime.now().year),
 %b %d %H:%M %Y
 )[0:5]
 ).strftime(%B %d, %Y %H:%M)
 else: # before six months
 return datetime.datetime(
 *time.strptime(value, %b %d %Y)[0:5]
 ).strftime(%B %d, %Y)

 I'm not sure if there is a proper algorithm for deciding on a proper
 year within the last 6 months as it isn't given by most FTP servers.
 I'd love to amend the function with the correct solution. :)

I didn't well understand your question, anyway...

- FTP got no LST command. What's that?
- NLST should return filenames only: returned output doesn't contain
file sizes, last modification time values or whatever.
- RFC959 gives no specifications about *how* LIST command output
should be formatted. Depending on the type of server you're talking to
you could find unix/ls -l-like format outputs, DOS-like ones or
something completely different and your code does not cover all of
them. Take a look at: http://effbot.org/downloads/#ftpparse

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


Re: FTP/SSL

2007-06-08 Thread billiejoex
On 8 Giu, 16:54, Dave Borne [EMAIL PROTECTED] wrote:
  I'm trying to figure out how to use FTP/SSL (FTPS) - just as a client. Can I
  do this in Python? Is everything I need in ftplib? Where else do I look? And
  - any good newbie references on using FTPS?

 Hi, Nancy,
  I'm not sure if ftplib can handle ssh or not, but googling for
 python sftp turned up this link:http://www.lag.net/paramiko/

 It looks like it might do what you want.

 -Dave

SFTP is FTP over SSH, quite different from FTPS that's FTP over TLS/
SSL.
Actually Python really lacks of good / maintained SSL libraries.

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


Re: Asyncore Help?

2007-05-17 Thread billiejoex
On 14 Mag, 06:51, Paul Kozik [EMAIL PROTECTED] wrote:
 I have trouble finding a solid example for what I need. Python.org and
 other sites provide simple examples, but they appear more intended for
 servers that simply send one peice of data to the client.

Not a big deal. asynchat / asyncore are pretty easy-to-learn
frameworks. Under the hoods they are extremely simpler if compared to
Twisted.
You shouldn't have problems in learning how the things works in a
couple of days.
Try to take a look at:
http://effbot.org/zone/asyncore-ftp-client.htm
http://effbot.org/librarybook/asynchat.htm

 Besides this I am also stuck with dealing with TCP data streams. I can
 receive and send the data (using threads, not yet with asynocore), but
 I am unsure how to deal with the streamlike nature of TCP (and would
 prefer to use TCP over UDP).

If you really need speed UDP could be a better choice.

 While basic socket work was rather easy to deal with, this has proved
 significantly more difficult.

Developing a bug-less network application by using the basic socket
module instead of an high-level framework like asyncore it's surely a
lot harder.
Again: asyncore is really simple: it's just a matter of understanding
the event-based approach that's very different from the thread-based
one.

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


Re: Asyncore Help?

2007-05-17 Thread billiejoex
On 14 Mag, 06:51, Paul Kozik [EMAIL PROTECTED] wrote:
 I have trouble finding a solid example for what I need. Python.org and
 other sites provide simple examples, but they appear more intended for
 servers that simply send one peice of data to the client.

Not a big deal. asynchat / asyncore are pretty easy-to-learn
frameworks. Under the hoods they are extremely simpler if compared to
Twisted.
You shouldn't have problems in learning how the things works in a
couple of days.
Try to take a look at:
http://effbot.org/zone/asyncore-ftp-client.htm
http://effbot.org/librarybook/asynchat.htm

 Besides this I am also stuck with dealing with TCP data streams. I can
 receive and send the data (using threads, not yet with asynocore), but
 I am unsure how to deal with the streamlike nature of TCP (and would
 prefer to use TCP over UDP).

If you really need speed UDP could be a better choice.

 While basic socket work was rather easy to deal with, this has proved
 significantly more difficult.

Developing a bug-less network application by using the basic socket
module instead of an high-level framework like asyncore it's surely a
lot harder.
Again: asyncore is really simple: it's just a matter of understanding
the event-based approach that's very different from the thread-based
one.

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


Re: Interrupting ftplib.storbinary()

2007-04-29 Thread billiejoex
On 26 Apr, 16:29, Florian  Demmer [EMAIL PROTECTED] wrote:
 Hi!

 I have a number of ftp uploads running in parallel using
 ftplib.storbinary and threading and in case one of them fails I need
 to interrupt all the others (but not exit the program completely)...
 do you guys have an idea how i could implement the interruption as
 cleanly as possible?

 thanks!

You could interrupt the transfer by directly using the lower 'ftp-
data' socket instead of the storbinary() method.
Try the following code (not tested):


import ftplib

file = open('file.ext', 'r')
ftp = ftplib.FTP()
ftp.connect(host='127.0.0.1', port=21)
ftp.login(user='user', passwd='passwd')
conn = ftp.transfercmd('stor file.ext', rest=None)

# the 'shared' var. change it to
# 1 when you want to stop the transfer
stop = 0
while 1:
chunk = file.read(8192)
conn.sendall(chunk)
if not chunk:
print finished
break
elif stop:
print stopped
break
conn.close()
ftp.close()

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


Re: Modules for peer-to-peer chat program

2007-04-26 Thread billiejoex
On 24 Apr, 19:51, Viewer T. [EMAIL PROTECTED] wrote:
 I would like to know which modules I would need in order to create
 peer-to-peer chat program in python using Tkinter.

 If I would need modules that do not come packaged with python, I would
 appreciate information on where I can get them.

 Thanks.

Some options:
- socket
- asyncore
- asynchat
- twisted
- twisted with support for tkinter (
http://twistedmatrix.com/projects/core/documentation/howto/choosing-reactor.html#auto13
)

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


Python and SSL

2007-04-16 Thread billiejoex
Hi,
I developed an ftp-server library and now I would like to add support
for SSL/TLS as described in RFC 2228: http://tools.ietf.org/html/rfc2228
Currenlty I'm searching for documentation about this subject and I
would like to start to ask some questions:

- I noticed that socket module provides an SSL class (socket.ssl) but
even if documentation reports that it does not do any certificate
verification a lot of stdlib modules (imaplib, poplib, smtplib,
httplib and urllib2) provides SSL extension classes wherein socket.ssl
is used. What does it mean?

- On top of that why such extension classes [examples: 1, 2, 3]
accepts key-files and cert-files as optional argouments if no
certificate verification occurs?
[1] poplib.POP3_SSL( host[, port[, keyfile[, certfile]]])
[2] imaplib.IMAP4_SSL( [host[, port[, keyfile[, certfile)
[3] smtplib.starttls( [keyfile[, certfile]])

- By searching through the web I found some daemons supporting SSL
such as this one:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442473
By looking at the code I notice that pyopenssl package is used and
that a certificate file is required. Why do I need to use pyopenssl
and how do I generate the cert file?

Could someone point me in the right direction?

Thanks in advance.

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


Re: low level networking in python

2007-04-05 Thread billiejoex
 I wish to do some low level network stuff using python.
 I've googled somewhat and came up with pylibpcap[1], trouble is I
 can't compile it on my Ubuntu 6.10 workstation.

I would suggest pcapy:
http://oss.coresecurity.com/projects/pcapy.html
Higher level, easier Object-Oriented API and support for multi-
threading.
Here's an example showing a simple sniffer app:
http://oss.coresecurity.com/impacket/sniff.py
Anyway, what kind of 'low-level network stuff' we're talking about?

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


Re: How many connections can accept a 'binded' socket?

2007-03-21 Thread billiejoex
On 20 Mar, 17:44, John Nagle [EMAIL PROTECTED] wrote:
 When you ask questions like this, please specify what
 operating system you're using.   Thanks.

That was a Linux Ubuntu 6.10. I submitted a bug report on sourceforge:
http://sourceforge.net/tracker/index.php?func=detailaid=1685000group_id=5470atid=105470


Alex Martelli wrote:
 A shell command
 ulimit -Hn
 should report on the hard-limit of the number of open file descriptors;
 just ulimit -n should report on the current soft-limit.

Thank you, I'll try it.

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


How many connections can accept a 'binded' socket?

2007-03-20 Thread billiejoex
Hi,
I'm writing a small asyncore-based server application serving a lot of
clients. When I have to handle more than 1021 client simoultaneously
the 'binded' socket object raises an error:

[...]
connections: 1018
connections: 1019
connections: 1020
connections: 1021
Traceback (most recent call last):
  File asyncore_client.py, line 31, in module
  File asyncore.py, line 191, in loop
  File asyncore.py, line 138, in poll
  File asyncore.py, line 80, in write
  File asyncore.py, line 76, in write
  File asyncore.py, line 395, in handle_write_event
  File asyncore_client.py, line 24, in handle_connect
  File asyncore_client.py, line 9, in __init__
  File asyncore.py, line 257, in create_socket
  File socket.py, line 156, in __init__
socket.error: (24, 'Too many open files')

I just wanna know: is there a way to know how many connections can
accept a 'binded' socket BEFORE getting such error? Maybe
socket.SOMAXCONN could help me?

Thanks in advance.

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


ANN: pyftpdlib 0.1.1

2007-03-07 Thread billiejoex
Changed in version 0.1.1
==

* port selection on PASV command has been randomized (this to prevent
a remote user
   to know how many data connections are in progress on the server).
* fixed bug in demo/unix_ftpd.py script.
* ftpd automatically re-use address if current system is unix.
* license changed into a MIT style one.


About
=

pyftpdlib is an high-level FTP server library based on asyncore/
asychat frameworks.
pyftpdlib is actually the most complete RFC959 FTP server
implementation available for Python programming language.


Requirements
==

Python 2.2 or higher


Bug reports / Contacts


billiejoex -_[AT]_- gmail (dot) com

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


ANN: pyftpdlib 0.1 released

2007-03-05 Thread billiejoex
Hi all,
I'm proud to announce the first beta release of pyftpdlib available at
the following urls:

home: http://billiejoex.altervista.org/pyftpdlib.html
google code: http://code.google.com/p/pyftpdlib/

About
=

pyftpdlib is an high-level FTP server library based on asyncore/
asychat frameworks.
pyftpdlib is actually the most complete RFC959 FTP server
implementation available for Python language.

Requirements
==

Python 2.2 or higher

Bug reports / Contacts


billiejoex [EMAIL PROTECTED] gmail (dot) com

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


ANN: pyftpdlib 0.1 released

2007-03-05 Thread billiejoex
Hi all,
I'm proud to announce the first beta release of pyftpdlib available at
the following urls:

home: http://billiejoex.altervista.org/pyftpdlib.html
google code: http://code.google.com/p/pyftpdlib/

About
=

pyftpdlib is an high-level FTP server library based on asyncore/
asychat frameworks.
pyftpdlib is actually the most complete RFC959 FTP server
implementation available for Python language.

Requirements
==

Python 2.2 or higher

Bug reports / Contacts


billiejoex -_[AT]_- gmail (dot) com

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


ANN: pyftpdlib 0.1 released

2007-03-05 Thread billiejoex
Hi all,
I'm proud to announce the first beta release of pyftpdlib available at
the following urls:

home: http://billiejoex.altervista.org/pyftpdlib.html
google code: http://code.google.com/p/pyftpdlib/

About
=

pyftpdlib is an high-level FTP server library based on asyncore/
asychat frameworks.
pyftpdlib is actually the most complete RFC959 FTP server
implementation available for Python programming language.

Requirements
==

Python 2.2 or higher

Bug reports / Contacts


billiejoex -_[AT]_- gmail (dot) com

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


Re: ANN: pyftpdlib 0.1 released

2007-03-05 Thread billiejoex
On 5 Mar, 15:13, Duncan Booth [EMAIL PROTECTED] wrote:
 billiejoex [EMAIL PROTECTED] wrote:
  Hi all,
  I'm proud to announce the first beta release of pyftpdlib available at
  the following urls:

 Announcing it once will do. Three times with minor edits is a bit much.

I'm sorry. I removed them by using google groups interface but maybe
with no success.

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


pcapy listen on multiple devices

2005-09-12 Thread billiejoex
Hi all. I noticed that with the original pcap sniffing library it is 
possible to listen on multiple devices by using select() or poll() 
function.
These function aren't present in pcapy module. Do you got any suggestion to 
avoid this problem?


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


Re: Socket options

2005-09-12 Thread billiejoex
If you are intrested in speed my personal advice is to use UDP insted of 
TCP.
The great majority of network games use it.
Here's a simple UDP implementation:
http://www.evolt.org/article/Socket_Programming_in_Python/17/60276/

 For an online game I'm developing I need some advice concerning 
 tcp-sockets, and especially which socket options to set and not.
 What I want is a connection where nothing is buffered (but are sent 
 immediatly), and I also want to keep the connections persistent until 
 explicitly closed.
 The server-side socket will receive multiple incomming requests from 
 clients...

 regards tores


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


Re: pinging from within python

2005-09-11 Thread billiejoex
Impacket module can helps you to construct the ip/icmp packet structure, 
then you can send the packet and wait for the ECHOREPLY by using a 
RAW_SOCKET.
Here's an example:
http://oss.coresecurity.com/impacket/ping.py

Cheers

 I need a simple script to run the ping command with some parameters and be 
 able to read the return value of the ping function. Any pointers will be 
 appreciated

 thanks
 m.smadi 


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


execute commands and return output

2005-09-10 Thread billiejoex
Hi all. I'm searching for a portable (working on *nix and win32) function 
that executes a system command and encapsulate its output into a string.
Searching for the web I found this:

os.popen('command').read()

It is perfect but when che command return an error the funciotn returns an 
empy string.
Does it is possible to return stdout and stderr too?

Best regards



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


Re: execute commands and return output

2005-09-10 Thread billiejoex
Thank you for your help but I'm searching a different way.
Moreover it doesn't work always (for exaple: try a 'dir' command).
Because of I'm implementing a remote shell  the 
[[os.popen('command').read()]] rapresents the best for me because it can 
also accepts arguments direclty  (for example: 
os.popen('netstat -a -n -o').read() and this is a great advantage.
I was looking at sys.stdout and sys.stderr. Can they be helpful?

Cheers
 Use subprocess:

 from subprocess import Popen, PIPE
 proc = Popen(['command', 'arg', 'arg'], stdout=PIPE, stderr=PIPE)
 return_code = proc.wait()
 if return_code == 0:
print Success:\n%s % proc.stdout.read()
 else:
print Failure %s:\n%s % (return_code, proc.stderr.read()) 


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


Re: execute commands and return output

2005-09-10 Thread billiejoex
Thanks for suggestions.
I'll try one of these solutions soon. 


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


icmp sniffer with pcapy module

2005-09-09 Thread billiejoex
Hi all. The source below is a simple icmp sniffer made with pcapy.
To decode packets I'm using the EthDecoder() function that returns a 
rapresentation of the packet including ICMP type, ICMP code, IP source and 
IP destination.
All I need, now, is to get the ip src and ip dst only but I don't know how 
to do it.
I tried to use the IPDecoder instead of EthDecoder to decode packets but 
misteriously it doesn't works.
Does anybody have a good idea about how to get this values only?

Best regards

#!/usr/bin/python
### sniffer
import pcapy
from impacket.ImpactDecoder import *

def recv_pkts(hdr, data):
x = EthDecoder().decode(data)
print x

def get_int():
devs = pcapy.findalldevs()
i=0
for eth in devs:
print  %d - %s %(i,devs[i])
i+=1
sel=input( Select interface: )
dev=devs[sel]
return dev

dev = get_int()
p = pcapy.open_live(dev, 1500, 0, 100)
p.setfilter('icmp')
print Listening on eth: net=%s, mask=%s\n % (p.getnet(), p.getmask())
p.loop(-1, recv_pkts) 


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


Sniffer with RAW SOCKETS

2005-09-07 Thread billiejoex
Hi all. I'm trying to make a simple icmp sniffer by using SOCK_RAW.
The code below works but ONLY if I first use the sendto() function.
Does anybody knows why?
Regards

from socket import *
import select
def recv():
while 1:
if s in select.select([s],[],[],99)[0]:
reply = s.recvfrom(2000)[0]
print reply
s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)
s.setsockopt(IPPROTO_IP, IP_HDRINCL, 1)
s.sendto('test', ('127.0.0.1', 0)) # without this it doesn't work.
recv()


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


Re: Python compiled?

2005-09-06 Thread billiejoex
Clear. Thank you all. 


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


Python compiled?

2005-09-05 Thread billiejoex
Hi all. I'm sorry for a noob question like this but I'll try to ask it 
anyway.
One of the greatest problem that may discourage a new user to choose Python 
language is it's interpreted nature.
Another important problem is that no interpreter is installed on Windows 
machine by default and this makes harder to distribute the software.
Does it is planned that, in a far future, Python will implement a form of 
compilation?
This would be awesome. 


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


Re: Python compiled?

2005-09-05 Thread billiejoex
I'm sorry. Maybe you  misunderstanded.
I know the great advanteges deriving by using interpretation too, I 
appreciate it very much (I'm newbie in Python and the interpeter really 
helps me out in many situations), but a 'pure' interpretated language needs 
obligatorily an interpreter and (sorry for repeating) this could be a 
problem for distribution (imho).
Py2exe is surely a good compromise but it is not comparable to an executable 
file compiled, for example, in C for obvious sizing reasons (I never used 
PyInstaller. I surely try it out as soon as possible, but I didn't think 
that the output package size is too much different than py2exe one).
For these reasons I think that an hibrid language that permits 
interpretation and compilation at the same time, should be a great 
advantage.

best regards 


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


Re: Python compiled?

2005-09-05 Thread billiejoex
 there are noob questions and there are uneducated questions, yours
 are of the latter ( actually yours are STATEMENTS not questions ), and
 just trolling for what it is worth, if you would take the time to read
 what Python is and why it is you would not be asking these questions.

I'm really sorry man. I didn't wanted to be uneducated, believe me.
I wrote fastly, I'm new in Python and probably for my language problems I 
didn't expressed concepts properly.



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


use threading without classes

2005-08-31 Thread billiejoex
Hi all. Hi would like to use two threads in a program but all the examples I 
found on the net use oop programming that I doesn't love too much. :-)
Can you code me a short example in wich two different functions are executed 
at the same time, plz?

Thank you all.


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


Re: use threading without classes

2005-08-31 Thread billiejoex
Thank you for your helping. 


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


Re: aproximate a number

2005-08-30 Thread billiejoex
I wanted the round up the number (5.0 = 5.0, not 6.0.). The ceil funciotn is 
the right one for me.
Thanks to all.


 Grant Edwards wrote:
 On 2005-08-30, Devan L [EMAIL PROTECTED] wrote:
 
  RoundToInt(2.0) will give you 3.

 That's what the OP said he wanted.  The next bigger integer
 after 2.0 is 3.

 It's not really clear whether he wanted it to round up or to go to the
 next biggest integer because he says he has bad english. I can't think
 of a particular use of returning the next bigger integer.

 You're probably right.  I suspect what he really wants is

 i = int(math.ceil(x))

 -- 
 Grant Edwards   grante Yow!  Is it FUN to be
  at   a MIDGET?
   visi.com 


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


py2exe can't compile this program

2005-08-30 Thread billiejoex
Hi all. I tried to compile this little source with py2exe:
http://pastebin.com/350143
...but once I execute the program I encount this error:

C:\src\distsniffer.exe
Traceback (most recent call last):
  File sniffer.py, line 24, in ?
  File sniffer.py, line 18, in get_int
LookupError: no codec search functions registered: can't find encoding

Any idea? :-\





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


Re: py2exe can't compile this program

2005-08-30 Thread billiejoex
Really thank you. It works.


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


aproximate a number

2005-08-28 Thread billiejoex
Hi all. I'd need to aproximate a given float number into the next (int) 
bigger one. Because of my bad english I try to explain it with some example:

5.7 -- 6
52.987 -- 53
3.34 -- 4
2.1 -- 3

Regards 


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


Re: aproximate a number

2005-08-28 Thread billiejoex
Thank you. :-) 


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


Re: Closing programs that use sockets

2005-08-27 Thread billiejoex
Awesome. :-)
Thank you.

 You may find that CTRL/Break works even when CTRL/C doesn't.

 regards
  Steve
 -- 
 Steve Holden   +44 150 684 7255  +1 800 494 3119
 Holden Web LLC http://www.holdenweb.com/
 


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


pcapy - print the DATA field of a packet

2005-08-27 Thread billiejoex
Hi all. I'm using pcapy module to sniff some ICMP packets. I would like to 
modify this source:
http://www.google.it/search?hl=itq=pcapybtnG=Cerca+con+Googlemeta=
and visualize only the DATA filed of the sniffed packets instead of all 
fields that are generally visualized (for example: ip src, ip dest, packet 
type...)
For example in this sniffing output:

ICMP type: ECHOREPLY code: UNKNOWN

6efb bf0d 0800 4500 0027 9c42  ff01n.E..'.B
72eb 29ff 0459 2907 5549  9942 0001r.)..Y).UI...B..
 6e65 7473 7461 7420 2d61 6e   ..Hello world!

... I would like to visualize the 'Hello world' string only.
Sorry for my bad english.

Best regards. 


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


Re: pcapy - print the DATA field of a packet

2005-08-27 Thread billiejoex
I'm really sorry. I was talking about this source:
http://oss.coresecurity.com/impacket/sniff.py
...but nevermind. I discovered the get_data_as_string() function that 
resolved my problem


 Sorry, but *which* source are you talking about?  The link you provided 
 appears to be merely a page of Google search results.

 Was there a specific page in there which you meant to point us to instead?

 -Peter 


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


Integrate C source in a Python project

2005-08-26 Thread billiejoex
Hi all.
I was wondering if it ispossible to integrate C source in a python project.

Best regards 


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


Re: Integrate C source in a Python project

2005-08-26 Thread billiejoex
Than you James. I'll take a look as soon as possible.
It is possible do the contrary (integrates python source in a C project)?


James [EMAIL PROTECTED] ha scritto nel messaggio 
news:[EMAIL PROTECTED]
 billiejoex wrote:
 Hi all.
 I was wondering if it ispossible to integrate C source in a python 
 project.

 There is ofcourse Python/C API
 http://docs.python.org/api/api.html

 But you will probably be easier off with Pyrex or Swig.

 Good summary on when to use which
 http://www.rexx.com/~dkuhlman/python_201/python_201.html#SECTION00650

 James
 


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


Does any1 use pcapy module on win32 platforms?

2005-08-26 Thread billiejoex
Hi. I'm trying to use pcapy module on Windows XP prof sp2 but it doesn't
work.
The example source reported on the site
(http://oss.coresecurity.com/impacket/sniff.py) works only on *unix 
machines.
On Windows machines the findalldevs() function (an output on the bottom)
gives an unicode object that can't be processed by open_live function
that tipically accept strings.
This not happens on linux machines where findalldev() function gives a
string object that can be quietly accepted by open_live.
Does exist a patch to fix this bug? I really would like to write a portable
program usable in both platforms.
Maybe do can I process the unicode outputs and converting them into valid
strings?
Happy summer and happy coding! :-)

Regards

billiejoex


 pcapy.findalldevs()
[u'\u445c\u7665\u6369\u5c65\u504e\u5f46\u6547\u656e\u6972\u4e63\u6964\u5773\u6e6
1\u6441\u7061\u6574r\u445c\u7665\u6369\u5c65\u504e\u5f46\u317b\u4534\u3544\u3642
\u2d31\u3030\u3942\u342d\u4441\u2d39\u3341\u4345\u382d\u3033\u3246\u3938\u3241\u
4531\u7d44\u5c00\u6544\u6976\u6563\u4e5c\u4650\u7b5f\u3541\u3630\u3934\u3434\u45
2d\u4230\u2d37\u3634\u3239\u382d\u4237\u2d35\u4630\u3133\u4244\u3933\u3532\u3943
}\u445c\u7665\u6369\u5c65\u504e\u5f46\u377b\u4337\u3644\u3034\u2d31\u3841\u3143\
u342d\u3743\u2d43\u3241\u4633\u432d\u3731\u3037\u3538\u3234\u4538\u7d34',
u'\u65
47\u656e\u6972\u2063\u644e\u7369\u6157\u206e\u6461\u7061\u6574r\u4d56\u6177\u657
2\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u6574r\u4d56
\u6177\u6572\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u
6574r\u564e\u4449\u4149\u6e20\u6f46\u6372\u2065\u434d\u2050\u654e\u7774\u726f\u6
96b\u676e\u4120\u6164\u7470\u7265\u4420\u6972\u6576\u2072\u4d28\u6369\u6f72\u6f7
3\u7466\u7327\u5020\u6361\u656b\u2074\u6353\u6568\u7564\u656c\u2972 ']



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


Re: Does any1 use pcapy module on win32 platforms?

2005-08-26 Thread billiejoex
The problem was my winpcap version. I was using the 3.1.
Now, with the 3.0 it works.

Really thanks. :-)


 For what it's worth, I can run that on my XP Professional SP2 machine and
 it works perfectly:

 pcapy.findalldevs()
 [u'\\Device\\NPF_{15310604-FCFC-4016-9D36-14DAA948A600}',
 u'\\Device\\NPF_{62280C1D-DC5C-42AF-BA0F-6BDB48418CA5}']

 I'm using WinPcap 3.0.  My packet.dll is stamped as version 3.0.0.18.
 Maybe you're running a different version?

 -- 
 Richie Hindle
 [EMAIL PROTECTED] 


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


Closing programs that use sockets

2005-08-26 Thread billiejoex
Hi all. I got a problem when using socket modules.
By using them I can't stop my program by pressing ctrl+c.
The only way to doit is by killing the python.exe process manually.
Is there a solution to avoid this?

Regards 


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


Re: sniffer in python

2005-08-16 Thread billiejoex
Thanks for your help. Like you suggested I converted the integer value in a
string one by using the repr() funtion applied on the print:

print '%d \n %s' %(count, repr(iface))

The program now permit me to select the interface. The output is in a
strange hex-similar form:

C:\Python24test.py
0
 
u'\u445c\u7665\u6369\u5c65\u504e\u5f46\u6547\u656e\u6972\u4e63\u6964\u5773\u6e61\u6441\u7061\u6574r\u445c\u7665\u6369\u5c65\u504e\u5f46\u317b\u4534\u3544\u3642\u2d31\u3030\u3942\u342d\u4441\u2d39\u3341\u4345\u382d\u3033\u3246\u3938\u3241\u4531\u7d44\u5c00\u6544\u6976\u6563\u4e5c\u4650\u7b5f\u3541\u3630\u3934\u3434\u452d\u4230\u2d37\u3634\u3239\u382d\u4237\u2d35\u4630\u3133\u4244\u3933\u3532\u3943}\u445c\u7665\u6369\u5c65\u504e\u5f46\u377b\u4337\u3644\u3034\u2d31\u3841\u3143\u342d\u3743\u2d43\u3241\u4633\u432d\u3731\u3037\u3538\u3234\u4538\u7d34'1
 
u'\u6547\u656e\u6972\u2063\u644e\u7369\u6157\u206e\u6461\u7061\u6574r\u4d56\u6177\u6572\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u6574r\u4d56\u6177\u6572\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u6574r\u564e\u4449\u4149\u6e20\u6f46\u6372\u2065\u434d\u2050\u654e\u7774\u726f\u696b\u676e\u4120\u6164\u7470\u7265\u4420\u6972\u6576\u2072\u4d28\u6369\u6f72\u6f73\u7466\u7327\u5020\u6361\u65!
 6b\u2074\u6353\u6568\u7564\u656c\u2972 'Please select an interface: 0When I 
select the interface (0 or 1) I encounter an encoding error:Traceback (most 
recent call last):  File C:\Python24\test.py, line 108, in ?main(filter)  
File C:\Python24\test.py, line 92, in mainp = open_live(dev, 1500, 0, 
100)UnicodeEncodeError: 'ascii' codec can't encode characters in position 
0-15:ordinal not in range(128)- How con I resolve this encoding problem?- How 
can I display the interface names in a 'human' form?Best regardsbillie Helping 
you learn to troubleshoot from tracebacks: look at the linepreceding the 
failing call.  Can you guess anything about what in that linemight be causing 
an encode() call?  The count variable is, presumably, justan integer, so %i 
wouldn't like have to do more than convert it to a string.%s, however, asks for 
iface to be turned into a string... if it were notalready a string (i.e. it's 
a unicode?) it would have to be encoded.  Whatdoes iface cont!
 ain and where did it come from?  Can you make it be just astring?  Doe
s that change or fix anything? -Peter

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


Re: sniffer in python

2005-08-16 Thread billiejoex
Sorry... the text has been wrong formatted. Read this, plz 

Thanks for your help. Like you suggested I converted the integer value in a
string one by using the repr() funtion applied on the print:
print '%d \n %s' %(count, repr(iface))
The program now permit me to select the interface. The output is in a
strange hex-similar form:
http://billiejoex.altervista.org/test.txt

When I select the interface (0 or 1) I encounter an encoding error:
Traceback (most recent call last):
  File C:\Python24\test.py, line 108, in ?
main(filter)
  File C:\Python24\test.py, line 92, in main
p = open_live(dev, 1500, 0, 100)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-15:
ordi
nal not in range(128)

- How con I resolve this encoding problem?
- How can I display the interface names in a 'human' form?

Best regards
billie


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


Re: sniffer in python

2005-08-16 Thread billiejoex
Moreover the getInterface() function seems to be unexistent:

 from pcapy import *
 getInterface()
Traceback (most recent call last):
  File stdin, line 1, in ?
NameError: name 'getInterface' is not defined

Maybe it can be used only on *nix platforms? 


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


sniffer in python

2005-08-15 Thread billiejoex
Hi!
I made a little, simple program that sends strings over an ICMP packet.
The source here:
http://billiejoex.altervista.org/a1.txt

Now all I need is create a simple network sniffer able to sniff the ICMP 
packets and print  the strings on the screen.
A useful library known in a lot of other programming languages is 'libcap' 
(winpcap for win32 platforms).
For python exist a porting called pcapy:
http://oss.coresecurity.com/projects/pcapy.html
...that I'd like to use BUT... all the examples reported on the sites don't 
works!!
Is there someone who has already created a network sniffer in python?
It shouldn't be too much difficult...

Best regards 


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


Re: sniffer in python

2005-08-15 Thread billiejoex
Thank you for your fast reply. You're right. I'll be more specific, sorry.
The example source is the one you can find on the 'Impacket' page on the 
same site of pcapy:
http://oss.coresecurity.com/impacket/sniff.py
I use a Win XP prof sp2 system, python ver. 2.4.1.
Here's the output:

C:\Python241.py
Traceback (most recent call last):
File C:\Python24\1.py, line 107, in ?
main(filter)
File C:\Python24\1.py, line 88, in main
dev = getInterface()
File C:\Python24\1.py, line 81, in getInterface
print '%i - %s' % (count, iface)
File C:\Python23\lib\encodings\cp850.py, line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 
4-19: ch
aracter maps to undefined




 For python exist a porting called pcapy:
 http://oss.coresecurity.com/projects/pcapy.html
 ...that I'd like to use BUT... all the examples reported on the sites 
 don't works!!

 It usually helps to describe *in what way* things don't work.

 Do they crash?  If so, provide the full traceback.

 Do they not install?  If so, provide error messages.

 Do they appear to run but without visible signs of activity?  If so, say 
 so... and describe exactly what options you were using, what platform and 
 version of platform, Python, and library you are using, and any other 
 conditions relevant to the situation.

 Help us help you...

 (Alternative suggestion: use whatever mailing list is provided for that 
 specific project, if there is one, so you get access to more people with 
 direct knowledge of what might go wrong.)

 -Peter 


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


pcapy help

2005-08-11 Thread billiejoex



Hi man! I found a post of yours in wich you tell 
that you use pcapy python module to capture packets. 
I need to do something similar but unfortunately I 
can't find too much domentation (and example codes) about this library. 


Can you paste me a simple code in wich you use 
thismodule for simply sniff network traffic? 
I made a simple 'data over ICMP' client that sends 
packets containing strings:
http://billiejoex.altervista.org/a1.txt
...now I have to develop a simple server that 
sniffs them.

Greetings


billiejoex



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