Re: make a string a list

2008-05-30 Thread iapain
On May 29, 11:30 pm, Nikhil [EMAIL PROTECTED] wrote:
 or a string iterable ? How can I do that. I have lots of '\r\n'
 characters in the string which I think can be easier if it were made
 into a list and I can easily see if the required value (its a numeral)
 is present in it or not after some position or after some characters'
 position.

 Thanks,
 Nikhil

If you just want to check required value then you can even use Sets or
build your own hash table.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Unicode to String conversion

2007-09-01 Thread iapain
First make sure your DB encoding is UTF-8 not the latin1

 The error I keep having is something like this:
 ERREUR:  Séquence d'octets invalide pour le codage «UTF8» : 0xe02063

then try this:

def smart_str(s, encoding='utf-8', errors='strict'):

Returns a bytestring version of 's', encoded as specified in
'encoding'.

if not isinstance(s, basestring):
try:
return str(s)
except UnicodeEncodeError:
return unicode(s).encode(encoding, errors)
elif isinstance(s, unicode):
return s.encode(encoding, errors)
elif s and encoding != 'utf-8':
return s.decode('utf-8', errors).encode(encoding, errors)
else:
return s



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


Re: escaping only double quotes

2007-08-31 Thread iapain

 string = Butler's 15\ TV
 s = my string goes here %s  % string

Couldn't find anything wrong in

string = Butler's 15\ TV
s = my string goes here %s % string

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


Re: escaping only double quotes

2007-08-31 Thread iapain
You could write a simple escape function.

def escape(html):
Return the given TEXT with ampersands, quotes and carets
encoded.
return html.replace('', 'amp;').replace('',
'lt;').replace('', 'gt;').replace('', 'quot;').replace(',
'#39;')

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


Re: JavaScript

2007-08-31 Thread iapain
python has modules for forms and other things... and for it?

Check out httplib and urlib2, it might be useful for you.

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


Re: So what exactly is a complex number?

2007-08-31 Thread iapain
  On Thu, 2007-08-30 at 20:11 -0500, Lamonte Harris wrote:
   Like in math where you put letters that represent numbers for place
   holders to try to find the answer type complex numbers?

You shouldnt worry about it in python, its pretty large to handle all
your calc.

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


Re: Google spreadsheets

2007-08-31 Thread iapain
On Aug 31, 5:40 pm, Michele Simionato [EMAIL PROTECTED]
wrote:
 I would like to upload a tab-separated file to a Google spreadsheet
 from Python. Does anybody
 have a recipe handy? TIA,

 Michele Simionato

Probably its irrelevant to python. Use should see Google Spreadsheet
API and use it in your python application.

http://code.google.com/apis/spreadsheets/

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


Re: sorting a list of lists

2007-08-27 Thread iapain
 i would like to sort a list of lists. The list is first sorted on the
 second item in the sub-lists (which I can do), then on the third item
 (which I can't).

Write a comparator instead of dirty hacks

mylistoflist.sort(mycomparator)

def mycomparator(a, b):
  #do


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


Re: sorting a list of lists

2007-08-27 Thread iapain
 Taking advantage of stable sorting is totally not a hack. The OP just tried
 the two sorting steps in the wrong order.

I didnt say not to use stable sorting, but write a generic function
and hacky code. It is always better to adopt a generic approach.


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


Re: Learning Python - Have Question.

2006-08-26 Thread iapain
 I'm just learning Python, and I have a question about os.path.join(dirpath,
 name) and its use.  Simply put, I haven't figured out how to use it.

First thing you have to remember while using python is everything is
an object. os.join.path concatenates one or more path for example
os.path.join(c:, myfolder) represent a path relative to current dir
on c: drive.

 I was looking through the Python reference material in the wee hours of the
 morning and checking out some of the modules.  I was keenly interested in
 the os module, as it is necessary for me to learn this stuff in order to
 begin my first real Python project.

Dont worry Python is quite easy to learn, just keep on coding in
python.

 Oh, I have one more question.   So far everything that I've played with
 yields only the filename of file.  I am aware that os.walk will place the
 pathnames and filenames in a tuple, but I'm wondering if there is a way to
 input a full path directory from within Python.  Specifically, I want to be
 able to get directories like one would get by entering ls -l at a *nix
 shell prompt.

you could easily do it with python. Its more than your expectation. The
best would be to call os.system(shell cmd). You can also print tuple in
your own way.

Cheers!
Deepak

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


Re: Python web service ...

2006-08-26 Thread iapain
 My question is how difficult is to set up a web server that can run
 python easy ? should I try ZOPE or there is something better in mind ?

Just install Apache and run Python as CGI thats the best solution I
found for my apps. Thats the best and faster way to move python apps on
web.

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


Re: Restricted Access

2006-07-12 Thread iapain
   Do you have an IBM s/370 running VM/CMS? VM was sort of an OS for
 running multiple OSs, so it would be the restricted environment G

I'm having currently working on OS/2 and Linux platform, I've designed
a web based ide for python and i wish to restrict some commands and
user can only access i.e rwx in his folder.

Best!

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


Re: Restricted Access

2006-07-12 Thread iapain
 You'll need to make your own AccessControl/ZopeGuards.py-like module, and
 probably subclass the RestrictionMutator  to enable/disable certain
 functionnality (interdiction of names beginning by '_' for example is hard
 coded).

Your reply is pretty hopeful, I saw that one, its the only fractional
part. I'm agree with others that I need to setup a safe runtime
enviornment rather than detecting harmful code.

 This should be possible by providing a wrapper function for file and open (see
 the Guards.py module).

Thats a nice idea, I guess it should work. I should try it really
quick! Thanks!

Best!
iapain

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


Re: Restricted Access

2006-07-11 Thread iapain
 googling for python restricted execution might give you some clues.

I've already assumed that there is no rexec for me as i am using python
2.4. Yeah its much more difficult that my imagination. Should I go for
alternatives like
1. Assume every one who is using this webide, wont corrupt system
2. Use some tricks to encrypt the user path and do lots of replacement
on user code and o/p.

or something else?

Best!
iapain

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


Re: Restricted Access

2006-07-11 Thread iapain
 unless you're willing to build a restricted runtime that runs on top of the 
 core inter-
 preter, you should assume that anyone writing a Python script that's executed 
 by
 your program has access to everything that your Python process has access 
 to...

I think using replacements I can ban atleast OS module and about files,
either i should ban file open or write my own module something like
rexec, truefully i dont know if I can write that one or not. I was
thinking that this gonna take few days but looking much more difficult.
Thanks Fred! for nice tutorials on www.

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


Re: Restricted Access

2006-07-11 Thread iapain

 my_innocent_object = __import__(''.join([chr(110+x) for x in [1, 5]]))

Thats really smart way, yeah i had plan to scan and detect but I think
its not gonna work.

 Creating a restricted execution environment is *hard*. As far as I know,
 even Microsoft has never attempted it. And for all of Sun's resources and
 talent, security holes are sometimes found even in Java.

Does that mean there is no way to implement restricted enviorment?

Best!
iapain

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


Re: Best command for running shell command

2006-07-11 Thread iapain
 where I'm not interested in the output, I only want to make sure that the
 command was executed OK. How should I invoke this (in a Unix/linux
 environment)?

Remember few things about executing program within python
1. Create a subprocess or child process and execute it.
2. You should use Timeout stratagy i.e your execution took more than
provided time then timeout this process. In linux/unix you may use
singnal alarm to implement it.

Best!

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


Re: Restricted Access

2006-07-11 Thread iapain
 The most knowledgeable people have effectively given up, in
 regard to Python.

I guess now I am up with only one option, i.e hope that user input code
wont be evil to the system. **which is rarely possible**

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


Re: Restricted Access

2006-07-11 Thread iapain
 Brett Cannon is currently trying to come up with a comprehensive spec
 and implementation of a sandboxed Python interpreter, for use in
 Mozilla as a JavaScript replacement. (look in the python-dev archives
 for more)

I'm not sure he is working or not, latest i read was he purposed new
restricted enviornment for python.

Best!

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


Restricted Access

2006-07-10 Thread iapain
I'm developing a webIDE for python and I've 2 questions regarding it.

1. How can i disable some of the modules without deleting. e.g I wish
to disable os module.
2. How can i force user code to access only his particular folder, I
dont want to create uses in unix, e.g

fp = open(PATH, 'w') # If this PATH is defined then use can access
files else he cant .. is there is any way?

Regards!
iapain

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


Re: Restricted Access

2006-07-10 Thread iapain
Tim Chase wrote:
 If you're prepared for the massive breakage that will ensue, you can

   chmod go-rwx /usr/lib/python2.3/os.*

No, I cant change permission or delete the module, the best would be
something to detect 'import os' in user code .. but If i go with chroot
jail approch then everything will be like what i want. But chroot jail
approch would take much space on webserver, what would happen if number
of users are large.

 Another alternative might just be to copy the python
 libraries to some place in the user's homedir (whatever their
 original library path was), revoke execute non-user execute privs
 from the python executable (chmod go-x `which python`), and then
 change python to be a script that runs something like chroot
 $HOME/ python $@.  Allow per-user access to this script via sudo.

Its having the same problem. The idea on which i am working is a
webide(which i already created) and a user file system(on which i am
working now) so that each user can access python globally and files
from his own folder, without adding them in unix user list. 

Best!

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


Re: Executing a DOS program from within Python

2006-03-16 Thread iapain
Use os.system and if you wanna get rid of console window use subprocess
as gary said, you could have better options like killing proc if it
hang/stuck using win32api (if you are using windows) else process
timeout.

ret = os.system('sample.exe') # ret will have return code and os.system
execute sample.exe

#using subprocess

import subprocess
process = subprocess.Popen('sample.exe', stdout=subprocess.PIPE)
#you can print error/output using stderr/stdout pipe

Both are easy to implement!
Thanks!!

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


Re: timeout a process

2006-01-22 Thread iapain
Thanks Tim, Yeah win32api is working normally.

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


timeout a process

2006-01-13 Thread iapain
Hello,
I am trying to build and infinite loop handler in python 2.4 on windows
platform. The problem is that i want to create a process and forcely
kill/timeout after 2 sec to handle infinite loop in a gcc complied exe
on cygwin. something like below

os.system(mycpp.exe) # this exe is compiled with g++ and having an
infinite loop

I wish to terminate this after 2 sec. I've tried Watchdog and deamon
thread.. but nothing seem to work here.

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


Re: import module and execute function at runtime

2006-01-13 Thread iapain
Hi,
if you want to import module dynamically, you can use __import__ ..
always remember modules are objects  ..

mStr=sys
mod=__import__(mStr)
# Now u can use mod.version .. but cant specify the attribute using
other variable, like u did
mod.version

should read it
http://diveintopython.org/functional_programming/dynamic_import.html

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