Can some1 review my code?

2009-04-19 Thread zaheer . agadi
hi

I am from java background, I have written some code that actually
works :)
Need to some one to look at it and tell me if there are better ways of
doing same things

Will some one help?

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


Re: Can some1 review my code?

2009-04-19 Thread zaheer . agadi
On Apr 19, 11:29 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Sat, 18 Apr 2009 23:18:32 -0700, zaheer.agadi wrote:
  hi

  I am from java background, I have written some code that actually works
  :)
  Need to some one to look at it and tell me if there are better ways of
  doing same things

  Will some one help?

 Are you offering to pay or are you after free advice?

 How large is your code? Ten lines, ten thousand lines, ten million lines?

 What does it do?

 How about if you start with a small, self-contained function (say, 20 to
 50 lines) that can be understood in isolation from the rest of your code,
 and we'll comment on that.

 --
 Steven

Thanks guys,
I am asking free advice,The program is not very complex it is around
500 lines with most the code being reused, I am bit hesitant to post
the code publicly, is it ok if I send part of  code say a function. Or
does it makes more sense if I send the complete code to you guys
personally?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can some1 review my code?

2009-04-19 Thread zaheer . agadi

 When done all this you might feel it is not necessary to review the code
 any more, which is then is a good moment to actually request a review :-)


 I'll be happy to have a look at it though you might consider posting it
 here, more chance of useful feedback ;-)

Great, Thanks a lot I will make sure that I complete what ever you
have listed here and then
request for a review. Well I understand that refusing to post the code
here in the mailing list might
annoy people and posting code here will only help it making it more
robust and clean. I am just being cautious that I don't break any of
the laws at my workplace.


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


Downloading folders from a server

2009-04-14 Thread zaheer . agadi
Hi ,

I am trying to download folders using webDAV Protocol, I want to
download the folders which in turn have many other folders. I am
trying to read each and every folder and create  the folder
locally.How do I do this? If I have a folder structure like the
following

Folder1
  |
  |_ Folder11(has some files also)
  |
  Folder111
  |
  |_Folder21
  |
  |_Folder211

If I have to download Folder1, how do I download this maintaining the
folder and Files structure
inside the sub folders.

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


Re: Creating Zip file like java jar file

2009-03-01 Thread zaheer . agadi
On Mar 1, 6:53 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
 En Sun, 01 Mar 2009 03:16:53 -0200, zaheer.ag...@gmail.com escribió:



I want to create zip file equivalent to java jar file,I created a
   zip
file of my sources and added some __main__.py
it says __Main__.py not found in Copyproject.zip..?
  I can get to work but is it is not able to locate the packages,says
  import error cant find the package and module

 Make it work *before* you attempt to zip the files. A complete session:

 C:\TEMPtree /a /f test_main_in_zip
 Listado de rutas de carpetas para el volumen Cucho
 El número de serie del volumen es 007A005F F4EC:16A9
 C:\TEMP\TEST_MAIN_IN_ZIP
 |   __main__.py
 |
 \---pkgA
  foo.py
  __init__.py

 C:\TEMPcd test_main_in_zip

 C:\TEMP\test_main_in_ziptype __main__.py
 #!/bin/env python

 This script is the entry point
 to the application

 import sys
 import pkgA.foo

 def main():
print I'm main():
print __name__, __name__
print __file__, __file__
print sys.path, sys.path[:3], ...
print
pkgA.foo.bar()

 main()

 C:\TEMP\test_main_in_ziptype pkgA\__init__.py
 print I'm __init__.py
 print __name__,__name__
 print __file__,__file__
 print
 C:\TEMP\test_main_in_ziptype pkgA\foo.py
 def bar():
print I'm bar() inside foo.py:
print __name__,__name__
print __file__,__file__
print
 C:\TEMP\test_main_in_zippython __main__.py
 I'm __init__.py
 __name__ pkgA
 __file__ C:\TEMP\test_main_in_zip\pkgA\__init__.py

 I'm main():
 __name__ __main__
 __file__ __main__.py
 sys.path ['C:\\TEMP\\test_main_in_zip',
 'c:\\apps\\python26\\python26.zip', 'c:\
 \apps\\python26\\DLLs'] ...

 I'm bar() inside foo.py:
 __name__ pkgA.foo
 __file__ C:\TEMP\test_main_in_zip\pkgA\foo.py

 C:\TEMP\test_main_in_zipzip anyname.zip __main__.py pkgA\*
adding: __main__.py (196 bytes security) (deflated 40%)
adding: pkgA/foo.py (196 bytes security) (deflated 40%)
adding: pkgA/foo.pyc (196 bytes security) (deflated 41%)
adding: pkgA/__init__.py (196 bytes security) (deflated 38%)
adding: pkgA/__init__.pyc (196 bytes security) (deflated 29%)

 C:\TEMP\test_main_in_zippython anyname.zip
 I'm __init__.py
 __name__ pkgA
 __file__ anyname.zip\pkgA\__init__.pyc

 I'm main():
 __name__ __main__
 __file__ None
 sys.path ['anyname.zip', 'c:\\apps\\python26\\python26.zip',
 'c:\\apps\\python26
 \\DLLs'] ...

 I'm bar() inside foo.py:
 __name__ pkgA.foo
 __file__ anyname.zip\pkgA\foo.pyc

 --
 Gabriel Genellin

 Make it work *before* you attempt to zip the files.
  Thanks a lot Gabriel, yes this works fine when I am running it
outside of zip.
when I say  python __main__.py --uploadfile  it works fine
I dont know what happens when I zip it.

And Steve: all of the packages have __init__.py inside them, I have
posted the tree structure of application if it helps.

C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\PYTHNSTUF
\TestApplication
├───src
│   ├───network
│   │   ├───.svn
│   │   │   └───text-base
│   │   └───storage
│   │   └───.svn
│   │   └───text-base
│   ├───uc
│   │   └───some
│   │   └───extra
│   │   └───package
│   └───webdav
│   └───acp
└───test
└───.svn
└───text-base

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


Re: Creating Zip file like java jar file

2009-03-01 Thread zaheer . agadi
On Mar 1, 7:40 pm, zaheer.ag...@gmail.com wrote:
 On Mar 1, 6:53 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:



  En Sun, 01 Mar 2009 03:16:53 -0200, zaheer.ag...@gmail.com escribió:

 I want to create zip file equivalent to java jar file,I created a
zip
 file of my sources and added some __main__.py
 it says __Main__.py not found in Copyproject.zip..?
   I can get to work but is it is not able to locate the packages,says
   import error cant find the package and module

  Make it work *before* you attempt to zip the files. A complete session:

  C:\TEMPtree /a /f test_main_in_zip
  Listado de rutas de carpetas para el volumen Cucho
  El número de serie del volumen es 007A005F F4EC:16A9
  C:\TEMP\TEST_MAIN_IN_ZIP
  |   __main__.py
  |
  \---pkgA
   foo.py
   __init__.py

  C:\TEMPcd test_main_in_zip

  C:\TEMP\test_main_in_ziptype __main__.py
  #!/bin/env python

  This script is the entry point
  to the application

  import sys
  import pkgA.foo

  def main():
 print I'm main():
 print __name__, __name__
 print __file__, __file__
 print sys.path, sys.path[:3], ...
 print
 pkgA.foo.bar()

  main()

  C:\TEMP\test_main_in_ziptype pkgA\__init__.py
  print I'm __init__.py
  print __name__,__name__
  print __file__,__file__
  print
  C:\TEMP\test_main_in_ziptype pkgA\foo.py
  def bar():
 print I'm bar() inside foo.py:
 print __name__,__name__
 print __file__,__file__
 print
  C:\TEMP\test_main_in_zippython __main__.py
  I'm __init__.py
  __name__ pkgA
  __file__ C:\TEMP\test_main_in_zip\pkgA\__init__.py

  I'm main():
  __name__ __main__
  __file__ __main__.py
  sys.path ['C:\\TEMP\\test_main_in_zip',
  'c:\\apps\\python26\\python26.zip', 'c:\
  \apps\\python26\\DLLs'] ...

  I'm bar() inside foo.py:
  __name__ pkgA.foo
  __file__ C:\TEMP\test_main_in_zip\pkgA\foo.py

  C:\TEMP\test_main_in_zipzip anyname.zip __main__.py pkgA\*
 adding: __main__.py (196 bytes security) (deflated 40%)
 adding: pkgA/foo.py (196 bytes security) (deflated 40%)
 adding: pkgA/foo.pyc (196 bytes security) (deflated 41%)
 adding: pkgA/__init__.py (196 bytes security) (deflated 38%)
 adding: pkgA/__init__.pyc (196 bytes security) (deflated 29%)

  C:\TEMP\test_main_in_zippython anyname.zip
  I'm __init__.py
  __name__ pkgA
  __file__ anyname.zip\pkgA\__init__.pyc

  I'm main():
  __name__ __main__
  __file__ None
  sys.path ['anyname.zip', 'c:\\apps\\python26\\python26.zip',
  'c:\\apps\\python26
  \\DLLs'] ...

  I'm bar() inside foo.py:
  __name__ pkgA.foo
  __file__ anyname.zip\pkgA\foo.pyc

  --
  Gabriel Genellin
  Make it work *before* you attempt to zip the files.

   Thanks a lot Gabriel, yes this works fine when I am running it
 outside of zip.
 when I say  python __main__.py --uploadfile  it works fine
 I dont know what happens when I zip it.

 And Steve: all of the packages have __init__.py inside them, I have
 posted the tree structure of application if it helps.

 C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\PYTHNSTUF
 \TestApplication
 ├───src
 │   ├───network
 │   │   ├───.svn
 │   │   │   └───text-base
 │   │   └───storage
 │   │   └───.svn
 │   │   └───text-base
 │   ├───uc
 │   │   └───some
 │   │   └───extra
 │   │   └───package
 │   └───webdav
 │   └───acp
 └───test
 └───.svn
 └───text-base

and also what it gives me when I Do,  python BRU.zip
some list of files
:
:
BRU/__init__.py2009-02-28
17:08:10  1
BRU/__main__.py2009-03-01
18:17:20  8
BRU/   2009-03-01 14:52:58
Traceback (most recent call last):
  File C:\Python26\lib\runpy.py, line 121, in _run_module_as_main
__main__, fname, loader, pkg_name)
  File C:\Python26\lib\runpy.py, line 34, in _run_code
exec code in run_globals
  File BRU.zip\__main__.py, line 18, in module
ImportError: No module named network.storage

I think I should I also mention I create this application using
ecliplse plugin

I appreciate your help Gabriella thanks  a lot,
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating Zip file like java jar file

2009-03-01 Thread zaheer . agadi
On Mar 1, 7:53 pm, zaheer.ag...@gmail.com wrote:
 On Mar 1, 7:40 pm, zaheer.ag...@gmail.com wrote:



  On Mar 1, 6:53 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:

   En Sun, 01 Mar 2009 03:16:53 -0200, zaheer.ag...@gmail.com escribió:

  I want to create zip file equivalent to java jar file,I created 
  a
 zip
  file of my sources and added some __main__.py
  it says __Main__.py not found in Copyproject.zip..?
I can get to work but is it is not able to locate the packages,says
import error cant find the package and module

   Make it work *before* you attempt to zip the files. A complete session:

   C:\TEMPtree /a /f test_main_in_zip
   Listado de rutas de carpetas para el volumen Cucho
   El número de serie del volumen es 007A005F F4EC:16A9
   C:\TEMP\TEST_MAIN_IN_ZIP
   |   __main__.py
   |
   \---pkgA
foo.py
__init__.py

   C:\TEMPcd test_main_in_zip

   C:\TEMP\test_main_in_ziptype __main__.py
   #!/bin/env python

   This script is the entry point
   to the application

   import sys
   import pkgA.foo

   def main():
  print I'm main():
  print __name__, __name__
  print __file__, __file__
  print sys.path, sys.path[:3], ...
  print
  pkgA.foo.bar()

   main()

   C:\TEMP\test_main_in_ziptype pkgA\__init__.py
   print I'm __init__.py
   print __name__,__name__
   print __file__,__file__
   print
   C:\TEMP\test_main_in_ziptype pkgA\foo.py
   def bar():
  print I'm bar() inside foo.py:
  print __name__,__name__
  print __file__,__file__
  print
   C:\TEMP\test_main_in_zippython __main__.py
   I'm __init__.py
   __name__ pkgA
   __file__ C:\TEMP\test_main_in_zip\pkgA\__init__.py

   I'm main():
   __name__ __main__
   __file__ __main__.py
   sys.path ['C:\\TEMP\\test_main_in_zip',
   'c:\\apps\\python26\\python26.zip', 'c:\
   \apps\\python26\\DLLs'] ...

   I'm bar() inside foo.py:
   __name__ pkgA.foo
   __file__ C:\TEMP\test_main_in_zip\pkgA\foo.py

   C:\TEMP\test_main_in_zipzip anyname.zip __main__.py pkgA\*
  adding: __main__.py (196 bytes security) (deflated 40%)
  adding: pkgA/foo.py (196 bytes security) (deflated 40%)
  adding: pkgA/foo.pyc (196 bytes security) (deflated 41%)
  adding: pkgA/__init__.py (196 bytes security) (deflated 38%)
  adding: pkgA/__init__.pyc (196 bytes security) (deflated 29%)

   C:\TEMP\test_main_in_zippython anyname.zip
   I'm __init__.py
   __name__ pkgA
   __file__ anyname.zip\pkgA\__init__.pyc

   I'm main():
   __name__ __main__
   __file__ None
   sys.path ['anyname.zip', 'c:\\apps\\python26\\python26.zip',
   'c:\\apps\\python26
   \\DLLs'] ...

   I'm bar() inside foo.py:
   __name__ pkgA.foo
   __file__ anyname.zip\pkgA\foo.pyc

   --
   Gabriel Genellin
   Make it work *before* you attempt to zip the files.

Thanks a lot Gabriel, yes this works fine when I am running it
  outside of zip.
  when I say  python __main__.py --uploadfile  it works fine
  I dont know what happens when I zip it.

  And Steve: all of the packages have __init__.py inside them, I have
  posted the tree structure of application if it helps.

  C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\PYTHNSTUF
  \TestApplication
  ├───src
  │   ├───network
  │   │   ├───.svn
  │   │   │   └───text-base
  │   │   └───storage
  │   │   └───.svn
  │   │   └───text-base
  │   ├───uc
  │   │   └───some
  │   │   └───extra
  │   │   └───package
  │   └───webdav
  │   └───acp
  └───test
  └───.svn
  └───text-base

 and also what it gives me when I Do,  python BRU.zip
 some list of files
 :
 :
 BRU/__init__.py2009-02-28
 17:08:10  1
 BRU/__main__.py2009-03-01
 18:17:20  8
 BRU/   2009-03-01 14:52:58
 Traceback (most recent call last):
   File C:\Python26\lib\runpy.py, line 121, in _run_module_as_main
 __main__, fname, loader, pkg_name)
   File C:\Python26\lib\runpy.py, line 34, in _run_code
 exec code in run_globals
   File BRU.zip\__main__.py, line 18, in module
 ImportError: No module named network.storage

 I think I should I also mention I create this application using
 ecliplse plugin

 I appreciate your help Gabriella thanks  a lot,

Thanks a lot folks it is solved now,the problem  was I had to create a
zip file from the location where actual package declarations are there
and not from the top level directory  whatever I had.
I created zip file from the src directory of the my tree which had all
the packages as its next level contents and imports were resolved.
--
http://mail.python.org/mailman/listinfo/python-list


Re: what does this mean....?

2009-02-28 Thread zaheer . agadi
On Feb 28, 1:50 pm, Ben Finney bignose+hates-s...@benfinney.id.au
wrote:
 Gabriel Genellina gagsl-...@yahoo.com.ar writes:
  En Sat, 28 Feb 2009 04:44:28 -0200, zaheer.ag...@gmail.com escribió:

   One question off the topic.,

  Usually it's better to post a separate message.

 More specifically (and I only say this because many people seem not to
 observe the distinction), when starting an entirely new topic of
 discussion, you should not reply to an existing message since it's
 then confusingly related with the same thread; instead, compose a
 *new* message with the appropriate subject.

 --
  \   “Either he's dead or my watch has stopped.” —Groucho Marx |
   `\   |
 _o__)  |
 Ben Finney

I agree I should have posted a new topic, Point taken..
Thanks Gabriel ,I will try this if  could not get this to work will
post a new thread.
--
http://mail.python.org/mailman/listinfo/python-list


Creating Zip file like java jar file

2009-02-28 Thread zaheer . agadi
Hi,
I want to create zip file equivalent to java jar file,I created a zip
file of my sources and added some __main__.py
some how I am getting an error saying __main.py does not exist in the
zip file

  Copyproject(main folder)
  |
  |_src(folder)
  |  |
  |  |__Nertworkpackage
  |   ||
  |   ||__Storepackage
  |   |   |
  |   |__FtpPackage |__module1.py
  |   |__module2.py
  | tests  |__ module3.py

Copyproject(main folder) | |_src(folder) | | | |__Nertworkpackage
| | | | | |__Storepackage | | | | |__FtpPackage |__module1.py | |
__module2.py | tests |__ module3.py

Module1 takes some commandline parameters that will do some operation
Like If I say
 module1.py --uploadFile file name  A file should get uploaded
(this works)
Now I want to do
Copyproject.zip --uploadFile filename to upload the file

How should I do this, I tried to put __main__ parallel to src folder
it says __Main__.py not found in Copyproject.zip..?

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


Re: Creating Zip file like java jar file

2009-02-28 Thread zaheer . agadi
On Feb 28, 11:15 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 En Sat, 28 Feb 2009 14:34:15 -0200, zaheer.ag...@gmail.com escribió:

  I want to create zip file equivalent to java jar file,I created a zip
  file of my sources and added some __main__.py
  it says __Main__.py not found in Copyproject.zip..?

 __main__.py must exist in the root directory.

 --
 Gabriel Genellina

What do you mean by root directory..?What is this directory in
Windows..?You mean the top level folder of the project?in my case
copyproject folder..?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating Zip file like java jar file

2009-02-28 Thread zaheer . agadi
On Feb 28, 11:33 pm, Lie Ryan lie.1...@gmail.com wrote:
 zaheer.ag...@gmail.com wrote:
  On Feb 28, 11:15 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
  wrote:
  En Sat, 28 Feb 2009 14:34:15 -0200, zaheer.ag...@gmail.com escribió:

  I want to create zip file equivalent to java jar file,I created a zip
  file of my sources and added some __main__.py
  it says __Main__.py not found in Copyproject.zip..?
  __main__.py must exist in the root directory.

  --
  Gabriel Genellina

  What do you mean by root directory..?What is this directory in
  Windows..?You mean the top level folder of the project?in my case
  copyproject folder..?

 root directory is the topmost directory (imagine a tree, the root is
 where all the branches branched from), in this case the root directory
 is your copyproject main folder.



I wonder, I do have the __main__.py  in the root directory,but still
getting
python.exe cannot find __main__.py in CopyProject.zip

I used the following command
python Copyproject.zip -m __main__.py --uploadFile and also tried with
python Copyproject.zip --uploadFile
both give me the same error , I can see the sys.path contains the
project folder.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating Zip file like java jar file

2009-02-28 Thread zaheer . agadi
On Mar 1, 1:32 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
 En Sat, 28 Feb 2009 16:51:04 -0200, zaheer.ag...@gmail.com escribió:



  On Feb 28, 11:33 pm, Lie Ryan lie.1...@gmail.com wrote:
  zaheer.ag...@gmail.com wrote:
   On Feb 28, 11:15 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
   wrote:
   En Sat, 28 Feb 2009 14:34:15 -0200, zaheer.ag...@gmail.com
  escribió:

   I want to create zip file equivalent to java jar file,I created a
  zip
   file of my sources and added some __main__.py
   it says __Main__.py not found in Copyproject.zip..?
   __main__.py must exist in the root directory.

   What do you mean by root directory..?What is this directory in
   Windows..?You mean the top level folder of the project?in my case
   copyproject folder..?

  root directory is the topmost directory (imagine a tree, the root is
  where all the branches branched from), in this case the root directory
  is your copyproject main folder.

  I wonder, I do have the __main__.py  in the root directory,but still
  getting
  python.exe cannot find __main__.py in CopyProject.zip

 The top of the tree inside the zip file. Depth zero. Not inside any
 directory. Above anything else. Just a bare name.

 Open your zip using the zipfile module:

 import zipfile
 z = zipfile.ZipFile(xxx.zip)
 z.printdir()

 You should see a line starting with __main__.py *without* any / in it.

  I used the following command
  python Copyproject.zip -m __main__.py --uploadFile and also tried with
  python Copyproject.zip --uploadFile

 Use the second one.

  both give me the same error , I can see the sys.path contains the
  project folder.


 --
 Gabriel Genellina

 Uh? Which project folder? Isn't it in the .zip?

 Yeah I meant zip file.
I can get to work but is it is not able to locate the packages,says
import error cant find the package and module

here is my code

import sys
import os.path as op
sys.path.insert(0, op.join(op.dirname(op.abspath(__file__)),
somezip.zip))

import zipfile
z = zipfile.ZipFile(somezip.zip)
z.printdir()

import some.storagepackage.somemodule
print upload
print syspath,sys.path

#do something

should it not find the modules when the zip files is in sys.path..?
--
http://mail.python.org/mailman/listinfo/python-list


what does this mean....?

2009-02-27 Thread zaheer . agadi
I am trying to download a file from the server, I am getting this
error,what does this mean

   localFile = open(localFileName, 'wb')
TypeError: coercing to Unicode: need string or buffer, type found

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


Re: what does this mean....?

2009-02-27 Thread zaheer . agadi
On Feb 28, 10:50 am, Rhodri James rho...@wildebst.demon.co.uk
wrote:
 On Sat, 28 Feb 2009 05:17:41 -, zaheer.ag...@gmail.com wrote:
  I am trying to download a file from the server, I am getting this
  error,what does this mean

 localFile = open(localFileName, 'wb')
  TypeError: coercing to Unicode: need string or buffer, type found

 The rest of the traceback and enough of your code to make sense of
 it would have helped.  Without context, my best guess is that
 localFileName isn't actually a string.

 --
 Rhodri James *-* Wildebeeste Herder to the Masses

Ohh thats my bad, I was actually  passing  a file type instead of
string,thanks a lot .
One question off the topic.,
How to create a .pyz file. I have python project that has some modules
in it , I want to create a zip file so that I can use it as we use
java jar file
Like I want to do a
mypyFiles.pyz --sendFile C:\\testFile
I currently have a module that does this when run as single python
module, but I want to do same this using a zip file which will  have
some other modules within it.

Any help..?

Thanks

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


Is there any equivalent feature available in Python..?

2009-02-24 Thread zaheer . agadi
Hi,

Is there any Python equivalent of java jar,can I include all my
sources,properties file etc into a single file.Is there anyway in
Python that I can run like the following

java  -jar Mytest.jar --startwebserver

How to so something like this in Python?

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


Re: Is there any equivalent feature available in Python..?

2009-02-24 Thread zaheer . agadi
On Feb 25, 1:10 am, Albert Hopkins mar...@letterboxes.org wrote:
 On Tue, 2009-02-24 at 11:05 -0800, zaheer.ag...@gmail.com wrote:
  Hi,

  Is there any Python equivalent of java jar,can I include all my
  sources,properties file etc into a single file.Is there anyway in
  Python that I can run like the following

  java  -jar Mytest.jar --startwebserver

  How to so something like this in Python?

 Similar but not equal:

 $ tree mytest
 mytest
 |-- __init__.py
 `-- main.py

 $ cat mytest/__init__.py
 if __name__ == '__main__':
     import sys
     print sys.argv
     import mytest.main

 $ cat mytest/main.py
 print 'hi mom'

 $ zip -r mytest.zip mytest
   adding: mytest/ (stored 0%)
   adding: mytest/main.py (stored 0%)
   adding: mytest/__init__.py (deflated 4%)

 $ PYTHONPATH=mytest.zip python -m mytest --startserver
 [None, '--startserver']
 hi mom

Thanks A lot this should solve my problem.Just out of curiosity how is
Python eggs different from the zip file you created here
--
http://mail.python.org/mailman/listinfo/python-list


why do I get name not defined error

2009-02-18 Thread zaheer . agadi
Hi,

 I have the following declared in my class, I am trying tp call a
method defined in the same class
I am not sure why I am getting name not defined error

if options.uploadFile != None :
print This is path, the_rest
filePath = the_rest
UploadFile(None,filePath)

def UploadFile(self,path):
print I wil upload now
os.chdir(homeFolder)
config = ConfigParser.ConfigParser()
.

any ideas why the error name UploadFile not defined

Thnaks


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


Re: Reading a file

2009-02-15 Thread zaheer . agadi
On Feb 15, 10:27 am, Steven D'Aprano st...@pearwood.info wrote:
 Philipp Pagel wrote:
  zaheer.ag...@gmail.com wrote:
  Hi

  How do i read  a file in Python and search a particular pattern
  like I have a file char.txt  which has

  Mango=sweet
  Sky=blue

  I want to get the strings sweet and blue,How to do this..?

  If your entire file consists of such key=value pairs you may want to
  properly parse them:

 The proper way to parse them would be with the ConfigParser module.

 The only negative with ConfigParser is that it requires a section label. In
 my experience it is quite common for INI files with only a single section
 to leave out the label.

 --
 Steven

Thanks to all of you,I used to ConfigParser worked fine.

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


Python WebDAV library

2009-02-15 Thread zaheer . agadi
Hi

I am looking for  WebDAV library in Python

I found one in
http://users.sfo.com/~jdavis/Software/PyDAV/readme.html
and one here
http://pypi.python.org/packages/any/P/Python_WebDAV_Library/


I basically have to upload and download files/folders to/from a server
should be able to copy them move them and delete.

Any body know if these serve the purpose or there are   libraries more
promising than listed above

Thanks




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


Reading a file

2009-02-14 Thread zaheer . agadi
Hi

How do i read  a file in Python and search a particular pattern
like I have a file char.txt  which has

Mango=sweet
Sky=blue

I want to get the strings sweet and blue,How to do this..?

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


Internal Server error

2009-02-08 Thread zaheer . agadi
HI
I am getting an internal server error while trying get response from a
server following is my code


   def getDetails(self,username,password):
urllib = urllib2.Request
idurl=https://some.server.com/;
port=8181
conn = httplib.HTTPSConnection(some.server.com/,8181);
conn.debuglevel  = 1
username = userone
password = 
Auth = Basic + ecnodeURL(self,username, password)
url= https://some.network.com:8181/main/folder/persons/; +
username + /attributes/atrone
print url
headers = {Authorization: Auth,Accept: application/json}
conn.request(GET, url,{},headers)
response = conn.getresponse()
data = response.read()
print response.reason
print response.


What I am getting as response

https://some.server.com:8181/main/folder/persons/userone/attributes/atrone
C:\Python26\lib\site-packages\httplib2\__init__.py:29:
DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import md5
C:\Python26\lib\site-packages\httplib2\__init__.py:44:
DeprecationWarning: the sha module is deprecated; use the hashlib
module instead
  import sha
send: 'GET 
https://some.server.com:8181/main/folder/persons/userone/attributes/atrone
HTTP/1.1\r\nHost: /some.server.com:8181\r\nAccept-Encoding: identity\r
\nAccept: application/json\r\nAuthorization: BasicU3RvcmFnZUVncjA1OA==
\r\n\r\n'
reply: 'HTTP/1.1 500 Internal Server Error\r\n'
header: Content-Type: text/html
header: Content-Language:
header: Content-Length: 1299
header: Date: Sun, 08 Feb 2009 10:25:52 GMT
header: Connection: close
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtdhtmlheadtitleSun
Java System Application Server 9.1_02 - Error report/titlestyle
type=text/css!--H1 {font-family:Tahoma,Arial,sans-
serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-
family:Tahoma,Arial,sans-serif;color:white;background-
color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-
serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-
family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B
{font-family:Tahoma,Arial,sans-serif;color:white;background-
color:#525D76;} P {font-family:Tahoma,Arial,sans-
serif;background:white;color:black;font-size:12px;}A {color : black;}
HR {color : #525D76;}--/style /headbodyh1HTTP Status 500 - /
h1hr/pbtype/b Exception report/ppbmessage/b/
ppbdescription/bThe server encountered an internal error ()
that prevented it from fulfilling this request./ppbexception/b
prejava.util.NoSuchElementException/pre/ppbnote/b uThe
full stack traces of the exception and its root causes are available
in the Sun Java System Application Server 9.1_02 logs./u/phr/
h3Sun Java System Application Server 9.1_02/h3/body/html
Internal Server Error
httplib.HTTPResponse instance at 0x00B9CDA0


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


Re: Internal Server error

2009-02-08 Thread zaheer . agadi
On Feb 8, 4:09 pm, Diez B. Roggisch de...@nospam.web.de wrote:
 zaheer.ag...@gmail.com schrieb:



  HI
  I am getting an internal server error while trying get response from a
  server following is my code

     def getDetails(self,username,password):
      urllib = urllib2.Request
      idurl=https://some.server.com/;
      port=8181
      conn = httplib.HTTPSConnection(some.server.com/,8181);
      conn.debuglevel  = 1
      username = userone
      password = 
      Auth = Basic + ecnodeURL(self,username, password)
      url= https://some.network.com:8181/main/folder/persons/; +
  username + /attributes/atrone
      print url
      headers = {Authorization: Auth,Accept: application/json}
      conn.request(GET, url,{},headers)
      response = conn.getresponse()
      data = response.read()
      print response.reason
      print response.

  What I am getting as response

 https://some.server.com:8181/main/folder/persons/userone/attributes/a...
  C:\Python26\lib\site-packages\httplib2\__init__.py:29:
  DeprecationWarning: the md5 module is deprecated; use hashlib instead
    import md5
  C:\Python26\lib\site-packages\httplib2\__init__.py:44:
  DeprecationWarning: the sha module is deprecated; use the hashlib
  module instead
    import sha
  send: 
  'GEThttps://some.server.com:8181/main/folder/persons/userone/attributes/a...
  HTTP/1.1\r\nHost: /some.server.com:8181\r\nAccept-Encoding: identity\r
  \nAccept: application/json\r\nAuthorization: BasicU3RvcmFnZUVncjA1OA==
  \r\n\r\n'
  reply: 'HTTP/1.1 500 Internal Server Error\r\n'
  header: Content-Type: text/html
  header: Content-Language:
  header: Content-Length: 1299
  header: Date: Sun, 08 Feb 2009 10:25:52 GMT
  header: Connection: close
  !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://
 www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtdhtmlheadtitleSun
  Java System Application Server 9.1_02 - Error report/titlestyle
  type=text/css!--H1 {font-family:Tahoma,Arial,sans-
  serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-
  family:Tahoma,Arial,sans-serif;color:white;background-
  color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-
  serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-
  family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B
  {font-family:Tahoma,Arial,sans-serif;color:white;background-
  color:#525D76;} P {font-family:Tahoma,Arial,sans-
  serif;background:white;color:black;font-size:12px;}A {color : black;}
  HR {color : #525D76;}--/style /headbodyh1HTTP Status 500 - /
  h1hr/pbtype/b Exception report/ppbmessage/b/
  ppbdescription/bThe server encountered an internal error ()
  that prevented it from fulfilling this request./ppbexception/b
  prejava.util.NoSuchElementException/pre/ppbnote/b uThe
  full stack traces of the exception and its root causes are available
  in the Sun Java System Application Server 9.1_02 logs./u/phr/
  h3Sun Java System Application Server 9.1_02/h3/body/html
  Internal Server Error
  httplib.HTTPResponse instance at 0x00B9CDA0

 What do you expect us to do about this? That has nothing todo with
 python, what you do is that you don't speak the right way with the
 server in question, producing a stacktrace. But nobody here knows *how*
 to talk to that machine. O

 Diez

Thanks,

I know there is something on the wrong side, when it says
java.util.NoSuchElementException i  thought something wrong with
setting values I just wanted you guys to point me out  there is
something wrong with the code I have written I am not very familiar
with Python the same work for java works fine.

I wanted to know if I am setting the headers correctly, getting the
response correctly
are there any better ways of encoding the url Over all Does the code
look ok...?
--
http://mail.python.org/mailman/listinfo/python-list


Java to Python

2009-02-07 Thread zaheer . agadi
Hi

I have a following class that is written Java and makes use of apache
http client library,I am new to python can any one suggest me a python
equivalent of this following class,

Thanks ,

public class Authenticate{

 private String storageUserName=null;
private String storagePassword=null;
private String authorization=null;
private String identityHostName = null;
private String identityPortNumber = null;

private String accessKey=null;
private String secretKey=null;

public String getStoragePassword() {
return storagePassword;
}

public void setStoragePassword(String storagePassword) {
this.storagePassword = storagePassword;
}

public String getStorageUserName() {
return storageUserName;
}

public void setStorageUserName(String storageUserName) {
this.storageUserName = storageUserName;
}

public String getIdentityHostName() {
return identityHostName;
}

public void setIdentityHostName(String identityHostName) {
this.identityHostName = identityHostName;
}

public String getIdentityPortNumber() {
return identityPortNumber;
}

public void setIdentityPortNumber(String identityPortNumber) {
this.identityPortNumber = identityPortNumber;
}

public String getAccessKey() {
return accessKey;
}

public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}

public String getSecretKey() {
return secretKey;
}

public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}


 /**
 * pConvenience string for Base 64 encoding./p
 */
private static final String BASE64_CHARS =
ABCDEFGHIJKLMNOPQRSTUVWXYZ +
abcdefghijklmnopqrstuvwxyz +
0123456789+/;

/**
 * pEncode the specified credentials into a String as required
by
 * HTTP Basic Authentication (a href=http://www.ietf.org/rfc/
rfc2617.txtRFC 2617/a)./p
 *
 * @param username Username to be encoded
 * @param password Password to be encoded
 * @return String string containing encoded username and password.
 */
public String encodeCredentialsBasic(String username, String
password) {
String encode = username + : + password;
int paddingCount = (3 - (encode.length() % 3)) % 3;
encode += \0\0.substring(0, paddingCount);
StringBuilder encoded = new StringBuilder();

for (int i = 0; i  encode.length(); i += 3) {
}
return encoded.toString();
}

public void fetchDetails(){
HttpClient client=new HttpClient();
//reqDetails = new RequestDetails();
//String identityURL=MessageUtil.getMessage
(IDENTITY_INSTANCE);
//int portNumber=Integer.parseInt(MessageUtil.getMessage
(IDENTITY_PORT));
authorization=Basic  + encodeCredentialsBasic
(storageUserName, storagePassword);
String url=https://+identityHostName+
:+identityPortNumber+/test/ndcsd2/persons/+UserName
+/attributes/;

Protocol https=null;
//try {
https = new Protocol(https, new
EasySSLProtocolSocketFactory(), Integer.parseInt(identityPortNumber));
/*} catch (GeneralSecurityException ex) {
Logger.getLogger(Authenticate.class.getName()).log
(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Authenticate.class.getName()).log
(Level.SEVERE, null, ex);
}*/
Protocol.registerProtocol(https, https);
GetMethod method=new GetMethod(url);
method.setRequestHeader(Authorization,authorization);
method.setRequestHeader(Accept,application/xml);
try {
int responseCode=client.executeMethod(method);
if(responseCode==200){
InputStream is=method.getResponseBodyAsStream();
BufferedReader bis=new BufferedReader(new
InputStreamReader(is));
String temp=null,sKey=null, aKey=null;
String accessKeySearchString=AccessKey/
NameValue;
String secretKeySearchString=SecretKey/
NameValue;
int searchStringLength=0;
while((temp=bis.readLine())!=null){
if(temp.indexOf(accessKeySearchString)!=-1){
int beginIndex=temp.indexOf
(accessKeySearchString);
searchStringLength=accessKeySearchString.length
();
int endIndex=temp.indexOf(/
Value,beginIndex);
aKey=temp.substring(beginIndex
+searchStringLength,endIndex);
}
if(temp.indexOf(secretKeySearchString)!=-1){
int beginIndex=temp.indexOf
(secretKeySearchString);
searchStringLength=secretKeySearchString.length
();
int endIndex=temp.indexOf(/
Value,beginIndex);

Re: Java to Python

2009-02-07 Thread zaheer agadi
Hi Thanks for replying ..
I am actually looking for the pure Python options

Are there any equivalent clasees  for the following

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import
org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.protocol.Protocol;


Thanks for your help
-Zaheer

On Sat, Feb 7, 2009 at 9:57 PM, Banibrata Dutta
banibrata.du...@gmail.comwrote:

 Jython is not an option ?

 On Sat, Feb 7, 2009 at 9:54 PM, zaheer.ag...@gmail.com wrote:

 Hi

 I have a following class that is written Java and makes use of apache
 http client library,I am new to python can any one suggest me a python
 equivalent of this following class,

 Thanks ,

 public class Authenticate{

  private String storageUserName=null;
private String storagePassword=null;
private String authorization=null;
private String identityHostName = null;
private String identityPortNumber = null;

private String accessKey=null;
private String secretKey=null;

public String getStoragePassword() {
return storagePassword;
}

public void setStoragePassword(String storagePassword) {
this.storagePassword = storagePassword;
}

public String getStorageUserName() {
return storageUserName;
}

public void setStorageUserName(String storageUserName) {
this.storageUserName = storageUserName;
}

public String getIdentityHostName() {
return identityHostName;
}

public void setIdentityHostName(String identityHostName) {
this.identityHostName = identityHostName;
}

public String getIdentityPortNumber() {
return identityPortNumber;
}

public void setIdentityPortNumber(String identityPortNumber) {
this.identityPortNumber = identityPortNumber;
}

public String getAccessKey() {
return accessKey;
}

public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}

public String getSecretKey() {
return secretKey;
}

public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}


 /**
 * pConvenience string for Base 64 encoding./p
 */
private static final String BASE64_CHARS =
ABCDEFGHIJKLMNOPQRSTUVWXYZ +
abcdefghijklmnopqrstuvwxyz +
0123456789+/;

/**
 * pEncode the specified credentials into a String as required
 by
 * HTTP Basic Authentication (a href=http://www.ietf.org/rfc/
 rfc2617.txt http://www.ietf.org/rfc/%0Arfc2617.txtRFC 2617/a)./p
 *
 * @param username Username to be encoded
 * @param password Password to be encoded
 * @return String string containing encoded username and password.
 */
public String encodeCredentialsBasic(String username, String
 password) {
String encode = username + : + password;
int paddingCount = (3 - (encode.length() % 3)) % 3;
encode += \0\0.substring(0, paddingCount);
StringBuilder encoded = new StringBuilder();

for (int i = 0; i  encode.length(); i += 3) {
}
return encoded.toString();
}

public void fetchDetails(){
HttpClient client=new HttpClient();
//reqDetails = new RequestDetails();
//String identityURL=MessageUtil.getMessage
 (IDENTITY_INSTANCE);
//int portNumber=Integer.parseInt(MessageUtil.getMessage
 (IDENTITY_PORT));
authorization=Basic  + encodeCredentialsBasic
 (storageUserName, storagePassword);
String url=https://+identityHostName+
:+identityPortNumber+/test/ndcsd2/persons/+UserName
 +/attributes/;

Protocol https=null;
//try {
https = new Protocol(https, new
 EasySSLProtocolSocketFactory(), Integer.parseInt(identityPortNumber));
/*} catch (GeneralSecurityException ex) {
Logger.getLogger(Authenticate.class.getName()).log
 (Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Authenticate.class.getName()).log
 (Level.SEVERE, null, ex);
}*/
Protocol.registerProtocol(https, https);
GetMethod method=new GetMethod(url);
method.setRequestHeader(Authorization,authorization);
method.setRequestHeader(Accept,application/xml);
try {
int responseCode=client.executeMethod(method);
if(responseCode==200){
InputStream is=method.getResponseBodyAsStream();
BufferedReader bis=new BufferedReader(new
 InputStreamReader(is));
String temp=null,sKey=null, aKey=null;
String accessKeySearchString=AccessKey/
 NameValue;
String secretKeySearchString=SecretKey/
 NameValue;
int searchStringLength=0;
while((temp=bis.readLine())!=null){