Connection acception with confirmation

2007-05-29 Thread no`name`

Hi, i'm new in Python and i'm trying to write some server which can
confirm connection from client.
Here is a part of code:

import sys
import threading
from socket import *

class TelGUI(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
s = socket(AF_INET, SOCK_STREAM)
s.bind(('',8900))
s.listen(5)
while 1:
client,addr = s.accept()
print addr
print "Or u want to accept connection from this host? 
[y/n]"
opt = sys.stdin.read(1)
if opt == 'y':
#establish
else: s.close() #reject

def main():
app = TelGUI()
app.start()

print "Menu"
while 1:
#some menu operations
op = sys.stdin.read(1)
if op == 'x':
break

if __name__ == "__main__":
main()

maybe someone have some ideas how to block first stdin in main
function and get stdin from the thread when here is a new connection?
Thanks

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


Re: newbie qns : how do i use xmldiff?

2010-11-05 Thread No Name
I had to do some fishing around to figure this much out. Hope it helps.

from input import * # From the xmldiff directory
from fmes import *  # From the xmldiff directory
from format import *# From the xmldiff directory
from StringIO import *

# Build your original tree
text1 = '123'
stream1 = StringIO(text)
tree1 = tree_from_stream(stream)

# Build your modified tree
text2 = '223'
stream2 = StringIO(text2)
tree2 = tree_from_stream(stream2)

# Compare the trees
formatter = InternalPrinter()
corrector = FmesCorrector(formatter)
corrector.process_trees(tree, tree2)

## OUTPUT: 
## Instructions for modifying original to modified
#  [rename, /point[1]/y[1], x]
#  [insert-after, /point[1]/x[2],
#  
#  2
#  
#  ]
#  [remove, /point[1]/x[1]]

> On Wednesday, February 03, 2010 1:38 AM sWrath swrath wrote:

> Hi ,
> 
> I am pretty new to python , and reading up on it.
> 
> Basically I am trying to compare xml files . I know difflib have it
> but it does not work out as expected. I was looking at xmldiff ,
> unfortunately I am not able to find documentation how to call it from
> python. Anyone knows a link or doc to it as I have been looking high
> and low for few days?
> 
> lastly , is there a py (or algorithm) where it behaves exactly like
> diff ? Greatly appreciated.
> 
> Thanks
> john


>> On Wednesday, February 03, 2010 3:34 PM Terry Reedy wrote:

>> On 2/3/2010 1:38 AM, sWrath swrath wrote:
>> 
>> When asking such a question, it is good to explain what sort of thing,
>> in this case, 'xmldiff' is and where it is is from. Let us assume you
>> meant xmldiff from
>> 
>> http://www.logilab.org/859
>> 
>> It says it is a python tool that can "be used be used as a library or as
>> a command line tool." It includes a README file. Have you read that?
>> That says "USAGE ... Read the HELP.txt file.". Have you read *that*?
>> HELP.txt seems to focus on command line usage. I would start with that.
>> To use it as a library (via import ...), you might have to look at the
>> source code as I did not see importing covered in my quick look at that
>> file.
>> 
>> Terry Jan Reedy


>> Submitted via EggHeadCafe - Software Developer Portal of Choice 
>> FireAndForget Asynchronous Utility Class for SQL Server Inserts and Updates
>> http://www.eggheadcafe.com/tutorials/aspnet/7a22d9a4-59fc-40b0-8337-75c76f14fb3b/fireandforget-asynchronous-utility-class-for-sql-server-inserts-and-updates.aspx
-- 
http://mail.python.org/mailman/listinfo/python-list