src/p/y/pyserial-HEAD/trunk/pyserial/examples/rfc2217_server.py pyserial(Download)
ser.port = args[0]
ser.timeout = 3 # required so that the reader thread can exit
logging.info("RFC 2217 TCP/IP to Serial redirector - type Ctrl-C / BREAK to quit")
try:
ser.open()
except serial.SerialException, e:
logging.error("Could not open serial port %s: %s" % (ser.portstr, e))
sys.exit(1)
logging.info("Serving serial port: %s" % (ser.portstr,))
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind( ('', options.local_port) )
srv.listen(1)
logging.info("TCP/IP port: %s" % (options.local_port,))
while True:
try:
connection, addr = srv.accept()
logging.info('Connected by %s:%s' % (addr[0], addr[1]))
try:
r.shortcut()
finally:
logging.info('Disconnected')
r.stop()
connection.close()
ser.setDTR(False)
except socket.error, msg:
logging.error('%s' % (msg,))
logging.info('--- exit ---')
src/p/y/pyserial-HEAD/pyserial/examples/rfc2217_server.py pyserial(Download)
ser.port = args[0]
ser.timeout = 3 # required so that the reader thread can exit
logging.info("RFC 2217 TCP/IP to Serial redirector - type Ctrl-C / BREAK to quit")
try:
ser.open()
except serial.SerialException, e:
logging.error("Could not open serial port %s: %s" % (ser.portstr, e))
sys.exit(1)
logging.info("Serving serial port: %s" % (ser.portstr,))
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind( ('', options.local_port) )
srv.listen(1)
logging.info("TCP/IP port: %s" % (options.local_port,))
while True:
try:
connection, addr = srv.accept()
logging.info('Connected by %s:%s' % (addr[0], addr[1]))
try:
r.shortcut()
finally:
logging.info('Disconnected')
r.stop()
connection.close()
ser.setDTR(False)
except socket.error, msg:
logging.error('%s' % (msg,))
logging.info('--- exit ---')
src/p/y/pyserial-2.5/examples/rfc2217_server.py pyserial(Download)
ser.port = args[0]
ser.timeout = 3 # required so that the reader thread can exit
logging.info("RFC 2217 TCP/IP to Serial redirector - type Ctrl-C / BREAK to quit")
try:
ser.open()
except serial.SerialException, e:
logging.error("Could not open serial port %s: %s" % (ser.portstr, e))
sys.exit(1)
logging.info("Serving serial port: %s" % (ser.portstr,))
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind( ('', options.local_port) )
srv.listen(1)
logging.info("TCP/IP port: %s" % (options.local_port,))
while True:
try:
connection, addr = srv.accept()
logging.info('Connected by %s:%s' % (addr[0], addr[1]))
try:
r.shortcut()
finally:
logging.info('Disconnected')
r.stop()
connection.close()
ser.setDTR(False)
except socket.error, msg:
logging.error('%s' % (msg,))
logging.info('--- exit ---')
src/f/o/Fos-HEAD/very_scratch/server/example7/webSocketServer.py Fos(Download)
def InstantiateApplication(moduleName, *classArgs):
module = __import__(moduleName)
log.info("InstantiateApplication - Module: " + repr(module))
classInstance = module.Instantiate(*classArgs)
log.info( repr(classInstance) )
return classInstance
#
#MAIN
#
if __name__ == "__main__":
log.info('Loading configuration info')
connectionQueueSize = config.getint('Server', 'ConnectionQueueSize')
#Start applications
log.info('Loading Applications...')
applications = {}
#Admin app
for application in applicationList:
appModuleName = application[1]
appInstanceName = application[0]
log.info('\tLoading instance of application %s as %s' % (appModuleName, appInstanceName))
applicationInstance = InstantiateApplication(appModuleName, appInstanceName)
applications['/' + appInstanceName] = applicationInstance
applicationThread = threading.Thread(target=applicationInstance.Run).start()
log.info("Applications Loaded:")
log.info(repr(applications))
#done with config
del config
log.info('Starting web socket server')
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serverSocket.bind( ('', port) )
#Accept clients
try:
while 1:
log.info('Waiting to accept client connection...')
clientSocket, clientAddress = serverSocket.accept()
try:
log.info('Got client connection from %s' % (repr(clientAddress)))
connection = Connection(clientSocket, clientAddress)
log.info('Client %s requested %s application' % (repr(clientAddress), connection.ApplicationPath))
if connection.ApplicationPath in applications:
requestedApp = applications[connection.ApplicationPath]
log.info('Client %s requested app: %s ' % (repr(clientAddress), repr(requestedApp)))
connection.Close()
connection = None
else:
log.info("Client %s requested an unknown Application. Closing connection." % repr(clientAddress))
connection.Close()
connection = None
except Exception as ex:
log.info('Execption occurred while attempting to establish client connection from %s.' % repr(clientAddress))
log.info(repr(ex))
except Exception as ex:
log.info('Server encountered an unhandled exception.')
log.info(repr(ex))
log.info('Server encountered an unhandled exception.')
log.info(repr(ex))
log.info('Web socket server closing.')
src/f/o/Fos-HEAD/very_scratch/server/example7-modified/webSocketServer.py Fos(Download)
def InstantiateApplication(moduleName, *classArgs):
module = __import__(moduleName)
log.info("InstantiateApplication - Module: " + repr(module))
classInstance = module.Instantiate(*classArgs)
log.info( repr(classInstance) )
return classInstance
#
#MAIN
#
if __name__ == "__main__":
log.info('Loading configuration info')
connectionQueueSize = config.getint('Server', 'ConnectionQueueSize')
#Start applications
log.info('Loading Applications...')
applications = {}
#Admin app
for application in applicationList:
appModuleName = application[1]
appInstanceName = application[0]
log.info('\tLoading instance of application %s as %s' % (appModuleName, appInstanceName))
applicationInstance = InstantiateApplication(appModuleName, appInstanceName)
applications['/' + appInstanceName] = applicationInstance
applicationThread = threading.Thread(target=applicationInstance.Run).start()
log.info("Applications Loaded:")
log.info(repr(applications))
#done with config
del config
log.info('Starting web socket server')
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serverSocket.bind( ('', port) )
#Accept clients
try:
while 1:
log.info('Waiting to accept client connection...')
clientSocket, clientAddress = serverSocket.accept()
try:
log.info('Got client connection from %s' % (repr(clientAddress)))
connection = Connection(clientSocket, clientAddress)
log.info('Client %s requested %s application' % (repr(clientAddress), connection.ApplicationPath))
if connection.ApplicationPath in applications:
requestedApp = applications[connection.ApplicationPath]
log.info('Client %s requested app: %s ' % (repr(clientAddress), repr(requestedApp)))
connection.Close()
connection = None
else:
log.info("Client %s requested an unknown Application. Closing connection." % repr(clientAddress))
connection.Close()
connection = None
except Exception as ex:
log.info('Execption occurred while attempting to establish client connection from %s.' % repr(clientAddress))
log.info(repr(ex))
except Exception as ex:
log.info('Server encountered an unhandled exception.')
log.info(repr(ex))
log.info('Server encountered an unhandled exception.')
log.info(repr(ex))
log.info('Web socket server closing.')
src/b/r/broadwick-1.2.0/examples/messaging/twistedstomp/subscriber.py broadwick(Download)
self.delay += now - float(headers['_sent'])
if '_count' in headers:
if self.count == int(headers['_count']):
logging.info('Counts match - received all %d messages' % self.count)
else:
logging.error('Count mismatch - expected %s but got %s' % (headers['_count'], self.count))
logging.info('Avg delay: %f secs' % (self.delay / self.count))
if now != self.start:
logging.info('Throughput: %f msgs / sec' % (self.count / (now - self.start)))
def onPublishedMessage(self, header, body, client):
logging.info('Got published message: %s' % body)
src/p/y/PyNN-0.6.0/test/test_examples.py PyNN(Download)
fail_message = "%s produce an empty file for %s" %(engine2.upper(), script)
if not fail:
if mse < mse_threshold:
logging.info("%s: Pass (mse = %f, threshold = %f)" % (script, mse, mse_threshold))
else:
logging.info("%s: Fail (mse = %f, threshold = %f)" % (script, mse, mse_threshold))
else:
logging.info("%s: Fail - %s" % (script, fail_message))
if not fail:
if mse < mse_threshold:
logging.info("%s: Pass (mse = %f, threshold = %f)" % (script, mse, mse_threshold))
else:
logging.info("%s: Fail (mse = %f, threshold = %f)" % (script, mse, mse_threshold))
else:
logging.info("%s: Fail - %s" % (script, fail_message))
src/n/o/notmm-0.4.1/examples/satchmo_store/contrib/satchmo/projects/base/local_settings.py notmm(Download)
# add the handler to the root logger
logging.getLogger('').addHandler(fileLog)
logging.getLogger('keyedcache').setLevel(logging.INFO)
logging.info("Satchmo Started")
src/b/r/broadwick-1.2.0/examples/messaging/twistedstomp/broadcaster.py broadwick(Download)
def onLoggedIn(self):
StompClient.onLoggedIn(self)
self.count = 0
logging.info('broadcasting %i messages to %s' % (MESSAGE_COUNT,
subscriber.EXAMPLE_TOPIC))
self._nextMessage()
headers['_end'] = nowstr
headers['_count'] = MESSAGE_COUNT
duration = now - self.start
logging.info('sent %d in %f second(s)' % (self.count, duration))
elif self.count > MESSAGE_COUNT:
self.disconnect()
reactor.callLater(2, reactor.stop)
src/f/o/Fos-HEAD/very_scratch/server/example7/webSocket.py Fos(Download)
if self.Origin != None and self.Host != None:
#WebSocket-Origin = Origin parameter of HTTP request
#WebSocket-Location = Host + resource request parameters of HTTP request
log.info("WebSocket sending HTTP response to client")
if self.WebSocketSecurityRequired:
self.Socket.send(HTTP_101_RESPONSE)
self.Socket.send(HTTP_UPGRADE)
self.Socket.send(HTTP_CRLF)
else:
log.info("WebSocket could not parse HTTP header")
raise Exception("WebSocket could not parse HTTP header")
except Exception as ex:
log.info("WebSocket could not complete the HTTP handshake to establish a web socket connection")
log.info(ex)
if appNameEndIndex != -1:
appPath = header[appNameStartIndex + 4:appNameEndIndex]
self.ApplicationPath = appPath
log.info("Application Path requested by WebSocket connection: %s" % (appPath))
hostStartIndex = header.find("Host: ")
if hostStartIndex != -1:
hostEndIndex = header.find("\r", hostStartIndex)
if hostEndIndex != -1:
host = header[hostStartIndex + 6 : hostEndIndex]
self.Host = host
log.info("Host requested by WebSocket connection: %s" % (host))
if originEndIndex != -1:
origin = header[originStartIndex + 8 : originEndIndex]
self.Origin = origin
log.info("Origin requested by WebSocket connection: %s" % (origin))
#Web Socket Security protocol
securityKey1 = self._ExtractField(header, "Sec-WebSocket-Key1: ")
if securityKey1 != None:
log.info("Sec-Websocket present, need to create Web Socket security response")
print 'Security Request: ', securityCode
self.SecurityResponse = self._CreateSecurityResponse(securityKey1, securityKey2, securityCode)
log.info("Created security response!")
def _ExtractField(self, header, name):
startIndex = header.find(name)
def Send(self, msg):
log.info(u'WebSocket sending data to client: %s' % (repr(msg)))
self.Socket.send(STARTBYTE + str(msg) + ENDBYTE)
#Will return a (possibly empty) list of commands,
#or None if the connection is suspected to be closed or an error occurs
def Recv(self):
webSocketCommands = []
try:
log.info('WebSocket waiting to receive data from client')
#strip protocol bytes from front and end of string
command = command[1:-1]
webSocketCommands.append(command)
log.info(u'WebSocket got command from client: %s' % (repr(command)))
else:
log.info(u'WebSocket got incorrectly formatted data from client: %s' % (repr(command)))
bufferIndex = self.WebSocketBuffer.find(ENDBYTE)
log.info('WebSocket got data from client: %s' % (repr(webSocketCommands)))
return webSocketCommands
except Exception as ex:
log.info("WebSocket got an exception while trying to receive from client socket")
def Close(self):
log.info('WebSocket closing client socket')
self.Socket.close()
#Needed for use with select()
def fileno(self):
return self.Socket.fileno()
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next