Re: Python, Dutch, English, Chinese, Japanese, etc.
On Jun 4, 11:54 am, Ross Ridge <[EMAIL PROTECTED]> wrote: > Steve Howell <[EMAIL PROTECTED]> wrote: > > >about Japan: > >major linguistic influences: Chinese, English, > >Dutch > > English and Dutch are minor linguistic influences. > Obviously. But language evolves. > > >Asia: > > > Python should be *completely* internationalized for > >Mandarin, Japanese, and possibly Hindi and Korean. > >Not just identifiers. I'm talking the entire > >language, keywords and all. > > This would be more convincing if it came from someone who spoke Mandarin, > Japanese, Hindi or Korean. > I'm a Chinese. Language/English is really a big problem for Chinese programmers. If python can be written in Chinese, it may become the most popular program language in China(though popular alreay). Considering the potential large amount of users in China, the effort of internationalization for Chinese will totally worth. > btw. Mandarin is a spoken dialect Chinese, what you're actually asking > for is a Simplified-Chinese version of Python. Mandarin is not a friendly way of saying Chinese and it is totally unacceptable in some area. Either Simplified Chinese or Traditional Chinese will be better. and last but not least, python ROCKS. -- http://mail.python.org/mailman/listinfo/python-list
skip next item in list
list=('a','d','c','d') for a in list: if a=='a' : #skip the letter affer 'a' what am I supposed to do? -- http://mail.python.org/mailman/listinfo/python-list
Re: skip next item in list
Thanks to all of you. I think the next() trick is the one I'm looking for. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
socket: connection reset by server before client gets response
Hi, everyone, I'm implementing a simple client/server protocol. Now I've got a situation: client will send server command,header paires and optionally body. server checks headers and decides whether to accept(read) the body. if server decided to throw(dump) the request's body, it'll send back a response message, such as "resource already exists" and close the connection. the problem is, client will never get the response but a "peer reset" exception. any comments or help will be appreciated. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
Re: socket: connection reset by server before client gets response
me again. "Connection reset by peer" happens about one in fifth. I'm using python 2.5.1 and ubuntu 7.04. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED]://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
Re: socket: connection reset by server before client gets response
> Post the code. ok. here is the code: # Echo server program import socket HOST = '' # Symbolic name meaning the local host PORT = 50007 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr conn.settimeout(1) toread = 99 retrytime = 0 reads = 0 while reads < toread and retrytime < 10: try: data = conn.recv(min(32,toread-reads)) if not data: continue print data reads += len(data) except: retrytime += 1 print "timeout %d" % retrytime continue if reads == toread: conn.send("OK") else: conn.send("NOT OK") conn.close() I'm the separate line* # Echo client program import socket HOST = 'localhost'# The remote host PORT = 50007 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) for i in range(12): print "time %d" % i s.send('0123456789') #data = s.recv(1024) #print "data %d" %i, data #s.shutdown(socket.SHUT_WR)#no more write data=s.recv(1024) s.close() print 'Received', repr(data) client is supposed to get the response, either "OK" or "NOT OK". but the fact is, client gets "Connection reset by peer" (as shown below) about one in fifth. -- Traceback (most recent call last): File "c.py", line 10, in s.send('0123456789') socket.error: (104, 'Connection reset by peer') -- anyway, server is doing well all the time. any comments on the design or implementation will be greatly appreciated. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
Re: socket: connection reset by server before client gets response
> So, umm, what exactly are you trying to accomplish? > It looks like what is happening is the server only accepts 99 bytes. It > then does the send and the close. yes. What I want is that, server sends response to client and closes connection when it feels recieving enough information, and make sure at the same time ,client will definitely get the response from server. > The client wants to send 120 bytes, 10 bytes at a time. By the time is > does the 12th send the server has already finished, closing its socket > and exiting. So when the client attempts send #12 the socket is already > closed. Thus the error. > > I'm not sure why you are getting the 'connection reset' instead of > 'broken pipe'. Probably different OS. (I'm using Mac OS X 10.4.10.) > as I saied before, running results will varies. And most of the time they are working quite well. But that's not enough. > Anyway, I changed your code slightly, wrapping the send in a try/except > block like this: > try: > s.send('0123456789') > except socket.error ,e: > print "Socket Error:", e > break > > Now here are my results for the client: > time 0 > time 1 > time 2 > time 3 > time 4 > time 5 > time 6 > time 7 > time 8 > time 9 > time 10 > time 11 > error: (32, 'Broken pipe') > Received 'OK' This really helped. Now I know the client will still get the response even under 'Connection reset by peer' or 'Broken pipe'. > The way you had it the program crashed before it could do the receive. > > Frank Frank, thanks a lot. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
socket.makefile() buggy?
socket.makefile() may lose data when "connection reset by peer". and socket.recv() will never lose the data. change the "1" to "0" in the client code to see the difference. confirmed on both windows and linux. so I guess there is a problem with makefile(). # Echo server program import socket HOST = '' # Symbolic name meaning the local host PORT = 50007 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((HOST, PORT)) s.listen(1) while(1): conn, addr = s.accept() print 'Connected by', addr conn.settimeout(1) toread = 99 retrytime = 0 reads = 0 while reads < toread and retrytime < 10: try: data = conn.recv(min(32,toread-reads)) if not data: continue print data reads += len(data) except: retrytime += 1 print "timeout %d" % retrytime continue #conn.shutdown(socket.SHUT_RD)#no more read if reads == toread: conn.send("OK") else: conn.send("NOT OK") conn.close() # Echo client program import socket HOST = 'localhost'# The remote host PORT = 50007 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) for i in range(12): print "time %d" % i try: s.send('0123456789') except socket.error, e: print "socket error:", e break #data = s.recv(1024) #print "data %d" %i, data #s.shutdown(socket.SHUT_WR)#no more write ''' try changing 1 to 0. ''' if 1: data=s.recv(1024) else: rf = s.makefile("rb") data = rf.read() rf.close() s.close() print 'Received', repr(data) -- http://mail.python.org/mailman/listinfo/python-list
Re: socket: connection reset by server before client gets response
> Try to wait a while in the server thread, after sending the > message before closing the connection, to give the message > time to get transmitted. > > time.sleep(0.5) should do it... > > - Hendrik OMG, it works. I can't believe the problem can be solved so easily. Thanks very much. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket: connection reset by server before client gets response
> It's a pleasure. > > Sometimes I think that all would be programmers should be > forced to write a "Hello World" to transmit out of a serial port > in assembler on hardware that carries no OS - just to teach > them about interrupts and time. > > I would require them to hand assemble the code too, to make > them appreciate what a compiler or an interpreter does. > Then there will be more crocodiles than programmers. > And if you fail the test, you get taken out and fed to the > sacred crocodiles. > > - Hendrik > > -- > For training with a bite, enrol now in Heavy Henry's > Wholesome Hackadamy for Precocious Programmers I feel a little embarrassed now. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.makefile() buggy?
On Jul 8, 9:54 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > That's a pretty pejorative subject line for someone who's been > programming Python [guessing by the date of your first post] for about a > month. > I have to admit it that I'm quite a newbie programmer. > Perhaps "Incomprehensible behavior from socket.makefile()", or "I have > written a buggy network application"? That would at least show that you > are considering the possibility you yourself are the cause of the > problem ;-) > Thanks. I'll be more careful about my words. but I did show some possibility myself is the cause of the problem. Is there any chance you missed the "?" and "guess" at the same time. > Python has been around for a long time, so you should ask yourself how > likely it is that you would be the first to discover such a fundamental > flaw? very low but not zero. Miracle happens. >I'd be very surprised if someone doesn't point you at an article > on "how to ask smart questions", but I will content myself with that > oblique reference. > > The big problem is that, I didn't know such a person like you before. It's my misfortune. > The big problem here seems to be that your server is closing the socket > after reading 99 bytes, but the client is actually sending 120. If you > change the "99" in the server to "120" you will see that the client > works when it uses the makefile().read(). I can't be bothered to debug > the exact reason why the 21 bytes of buffered data doesn't cause a > problem with the recv() version, but I wouldn't regard the error you are > getting as a bug in Python, rather as a bug in your application. > I don't know the underlying details of networking. But with recv() version I can get things done as expected while makefile() version can't. I guess it's not that unreasonable to make a guess like I did. > The underlying cause of all this appears to be your failure to > understand that network protocols should ideally allow the endpoints to > determine when a complete message has been transmitted, and to consume > all transmitted data. > > You can't just ignore some or all of a client request and expect it not > to cause problems. Back to the problem, I make it working by adding a sleep(0.5) just before the server closes the connection. Actually this is Hendrik van Rooyen's idea. And luckily I got a another lesson http://groups.google.com/group/comp.lang.python/browse_thread/thread/9c5ad2608f4c80d5/4302772dfe27d8f1#4302772dfe27d8f1 >If you look at some of the better-known TCP-based > application protocols you will see they take pains to ensure that > clients and servers can deterministically parse each others' messages. > I found something useful in RFC2616--Hypertext Transfer Protocol -- HTTP/1.1. [PAGE49] - If an origin server receives a request that does not include an Expect request-header field with the "100-continue" expectation, the request includes a request body, and the server responds with a final status code before reading the entire request body from the transport connection, then the server SHOULD NOT close the transport connection until it has read the entire request, or until the client closes the connection. Otherwise, the client might not reliably receive the response message. However, this requirement is not be construed as preventing a server from defending itself against denial-of-service attacks, or from badly broken client implementations. "Otherwise, the client might not reliably receive the response message". My problem seems fixed. But it's not "relialbe" though it's working pretty good under windows 2k, windowsxp, and linux. I may reconsider my design and willprobably try dividing request with body into two steps like HTTP does. > In summary, a better protocol design will cause you rather less grief > and a little more humility will result in less acidity from crabby old > geeks like me. > I do appreciate your response. I mean it. > 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 - And last but not least, I' here to be helped and help as long as I can. But as you noticed I'm not very good at expressing myself in English. I didn't mean to offense anyone but I might seem to be rude or offensive. I hope you can understand. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
Re: socket: connection reset by server before client gets response
On Jul 9, 4:30 pm, Adriano Varoli Piazza <[EMAIL PROTECTED]> wrote: > > Gives a whole new meaning to chomp(), byte, nybble, and more :) > I wholeheartedly endorse this effort. I'm sick of reading about > students from WTF University (check thedailywtf.com if you don't know, > but beware. There be dragons). > > -- > Adriano > Once bitten, one arm less to code snafus with. I feel officially offended. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket: connection reset by server before client gets response
On Jul 9, 7:03 pm, Adriano Varoli Piazza <[EMAIL PROTECTED]> wrote: > ahlongxp wrote: > > I feel officially offended. > > I didn't intend to offend you, I was joking. I apologise in any case. > There's a few things to be said, though: > > As per your message in another thread, it isn't that you don't express > yourself clearly in English, but that you were too quick to claim a > standard function was buggy without first thinking if your own code > could be buggy instead. That presumption isn't related to the language. > > Second, if you do say that you aren't comfortable in English, try to > assume that people aren't trying to insult you by default. I was > speaking generallyin my message. > > Third, this is usenet. Although probably not in this newsgroup, if you > continue to make the assumptions I and others pointed out, you will > receive this kind of answer. Perhaps with much more insult than right > now. So it is a great idea to grow a thick skin. > > -- > Saludos > Adriano You don't have to apologise. I was joking too. But I know I have to change my way of thinking and questioning. I'll consider more carefully before speaking. I hope I can talk like you very soon. Thanks. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.makefile() buggy?
On Jul 11, 7:51 am, [EMAIL PROTECTED] (John J. Lee) wrote: > Steve Holden <[EMAIL PROTECTED]> writes: > > ahlongxp wrote: > >> On Jul 8, 9:54 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > >>> That's a pretty pejorative subject line for someone who's been > >>> programming Python [guessing by the date of your first post] for about a > >>> month. > > > [...] > >> And last but not least, I' here to be helped and help as long as I > >> can. > >> But as you noticed I'm not very good at expressing myself in English. > >> I didn't mean to offense anyone but I might seem to be rude or > >> offensive. > >> I hope you can understand. > > > Sure. I felt it necessary to explain my remarks as my own remarks > > seemed potentially rude or offensive. Naturally not everyone has > > English as a first language, but your first post was good enough that > > it wasn't immediately obvious in your case. > > This is the danger in getting too good at another language :-) > ahlongxp, maybe you should drop some deliberate mistakes in your > too-good English ;-) > > And FWLIW, I'd be less surprised than Steve at your finding a real bug > in Python's socket code... > > John Sorry, I don't think I understand what you are trying to say. But thanks for your response anyway. Frank Swarbrick, thank your for your advice. I'll think about it. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create new files?
On Jul 13, 5:14 am, Robert Dailey <[EMAIL PROTECTED]> wrote: > Hi, > > I'm trying to create a Python equivalent of the C++ "ifstream" class, > with slight behavior changes. > > Basically, I want to have a "filestream" object that will allow you to > overload the '<<' and '>>' operators to stream out and stream in data, > respectively. So far this is what I have: > > class filestream: > def __init__( self, filename ): > self.m_file = open( filename, "rwb" ) > > # def __del__( self ): > # self.m_file.close() > > def __lshift__( self, data ): > self.m_file.write( data ) > > def __rshift__( self, data ): > self.m_file.read( data ) > > So far, I've found that unlike with the C++ version of fopen(), the > Python 'open()' call does not create the file for you when opened > using the mode 'w'. I get an exception saying that the file doesn't > exist. I expected it would create the file for me. Is there a way to > make open() create the file if it doesn't exist, or perhaps there's > another function I can use to create the file? I read the python docs, > I wasn't able to find a solution. > using "w" or "wb" will create new file if it doesn't exist. at least it works for me. > Also, you might notice that my "self.m_file.read()" function is wrong, > according to the python docs at least. read() takes the number of > bytes to read, however I was not able to find a C++ equivalent of > "sizeof()" in Python. If I wanted to read in a 1 byte, 2 byte, or 4 > byte value from data into python I have no idea how I would do this. > f.read(10) will read up to 10 bytes. you know what to do now. > Any help is greatly appreciated. Thanks. and another thing to mention, __del__() will not always be called( any comments?). so you'd better flush your file explicitely by yourself. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
Re: bool behavior in Python 3000?
On Jul 11, 5:36 am, Bjoern Schliessmann wrote: > Is there any type named "bool" in standard Python? check this out. >>> doespythonrock = True >>> print type(doespythonrock) >>> -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list
some parts of wxPython broken on Mac
Sorry, I know this is not the most appropriate place to talk about wxPython. But I can't have access to wxPython mail list page(because I don't pay enough). I downloaded python2.5 and wxPython 2.8.4.0 from pythonmac.org and installed them into one of my friends' Mac 10.4.8(intel) and I found wx.lib.flatnotebook and wx.xrc were broken(which are quite OK under both Linux and Windows). because I don't have the machine, I can't give more details. I hope someone will be good enough to check out these problems. -- ahlongxp Software College,Northeastern University,China [EMAIL PROTECTED] http://www.herofit.cn -- http://mail.python.org/mailman/listinfo/python-list