示例#1
0
 def decode( data ) :
     data = decode( data )
     if type(data) is not dict : raise TypeError
     publicIP = data.get( 'publicIP' )
     try :
         validateIPAddress( publicIP )
     except :
         publicIP = ''
     directLocations = []
     routedLocations = []
     for direct in data.get('direct',[]) :
         if type(direct) is not list : continue
         direct = tuple( direct )
         try :
             validateInetAddress( direct )
         except :
             continue
         directLocations.append( DirectLocation(direct) )
     for routed in data.get('routed',[]) :
         if type(routed) is not list : continue
         if len(routed) != 2 : continue
         routerAddr,routerId = routed
         if type(routerId) is not str : continue
         if type(routerAddr) is not list : continue
         routerAddr = tuple( routerAddr )
         try :
             validateInetAddress( routerAddr )
         except :
             continue
         routedLocations.append( RoutedLocation(routerAddr,routerId) )
     return UserLocation( directLocations, routedLocations, publicIP )
示例#2
0
文件: location.py 项目: hj91/cspace
 def decode(data):
     data = decode(data)
     if type(data) is not dict: raise TypeError
     publicIP = data.get('publicIP')
     try:
         validateIPAddress(publicIP)
     except:
         publicIP = ''
     directLocations = []
     routedLocations = []
     for direct in data.get('direct', []):
         if type(direct) is not list: continue
         direct = tuple(direct)
         try:
             validateInetAddress(direct)
         except:
             continue
         directLocations.append(DirectLocation(direct))
     for routed in data.get('routed', []):
         if type(routed) is not list: continue
         if len(routed) != 2: continue
         routerAddr, routerId = routed
         if type(routerId) is not str: continue
         if type(routerAddr) is not list: continue
         routerAddr = tuple(routerAddr)
         try:
             validateInetAddress(routerAddr)
         except:
             continue
         routedLocations.append(RoutedLocation(routerAddr, routerId))
     return UserLocation(directLocations, routedLocations, publicIP)
示例#3
0
文件: rpc.py 项目: AchillesA/cspace
 def _onInput( self, data ) :
     try :
         (msgCode,requestId,payload) = decode(data)
         if (type(msgCode) is not IntType) or (type(requestId) is not IntType) :
             raise TypeError, 'invalid msg structure'
     except DecodeError, de :
         logger.warning( 'invalid msg structure: %s', de )
         return
示例#4
0
 def _onInput(self, data, fromaddr):
     try:
         (msgCode, id, payload) = decode(data)
         if (type(msgCode) is not IntType) or (type(id) is not StringType):
             raise TypeError, 'invalid msg structure'
     except DecodeError, de:
         logger.exception('decode error: %s', de)
         return
示例#5
0
文件: rpc.py 项目: vesellov/datahaven
 def _onInput( self, data, fromaddr ) :
     try :
         (msgCode,id,payload) = decode( data )
         if (type(msgCode) is not IntType) or (type(id) is not StringType) :
             raise TypeError, 'invalid msg structure'
     except DecodeError, de :
         logger.exception( 'decode error: %s', de )
         return
示例#6
0
文件: rpc.py 项目: hj91/cspace
 def _onInput(self, data):
     try:
         (msgCode, requestId, payload) = decode(data)
         if (type(msgCode) is not IntType) or (type(requestId)
                                               is not IntType):
             raise TypeError, 'invalid msg structure'
     except DecodeError, de:
         logger.warning('invalid msg structure: %s', de)
         return
示例#7
0
文件: listener.py 项目: hj91/cspace
 def onInput(data):
     try:
         serviceName = decode(data)
         assert type(serviceName) is str
         assert len(serviceName) > 0
     except:
         onError()
         return
     obj.stream.shutdown()
     obj.stream = None
     op.notify((obj.sslConn, obj.peerKey, obj.peerName, serviceName))
示例#8
0
 def onInput( data ) :
     try :
         serviceName = decode( data )
         assert type(serviceName) is str
         assert len(serviceName) > 0
     except :
         onError()
         return
     obj.stream.shutdown()
     obj.stream = None
     op.notify( (obj.sslConn,obj.peerKey,obj.peerName,serviceName) )
示例#9
0
文件: connector.py 项目: hj91/cspace
 def onInput( data ) :
     try :
         result = decode( data )
         assert type(result) is int
         assert result == 0
     except :
         doCancel()
         op.notify( None )
         return
     ms.shutdown()
     op.notify( sslConn )