<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function <EOL> import struct <EOL> from binascii import hexlify <EOL> from collections import deque , namedtuple <EOL> import enum <EOL> import socket <EOL> from ... aid . sixing import * <EOL> from ... aid . odicting import odict <EOL> from ... aid . byting import bytify , unbytify , packify , unpackify <EOL> from ... aid . eventing import eventify , tagify <EOL> from ... aid import getConsole <EOL> from . protoing import MixIn <EOL> console = getConsole ( ) <EOL> class Device ( MixIn ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> stack , <EOL> uid = None , <EOL> name = None , <EOL> ha = None , <EOL> kind = None , <EOL> ) : <EOL> """<STR_LIT>""" <EOL> self . stack = stack <EOL> self . uid = uid if uid is not None else stack . nextUid ( ) <EOL> self . name = name if name is not None else "<STR_LIT>" . format ( self . uid ) <EOL> self . ha = ha if ha is not None else '<STR_LIT>' <EOL> self . kind = kind <EOL> def show ( self ) : <EOL> """<STR_LIT>""" <EOL> result = ( "<STR_LIT>" . format ( <EOL> self . name , <EOL> self . uid , <EOL> self . ha , <EOL> self . kind ) ) <EOL> return result <EOL> def process ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def receive ( self , rx ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class LocalDevice ( Device ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> stack , <EOL> ** kwa ) : <EOL> """<STR_LIT>""" <EOL> super ( LocalDevice , self ) . __init__ ( stack = stack , ** kwa ) <EOL> class RemoteDevice ( Device ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> stack , <EOL> uid = None , <EOL> ** kwa ) : <EOL> """<STR_LIT>""" <EOL> if uid is None : <EOL> uid = stack . nextUid ( ) <EOL> while uid in stack . remotes or uid in ( stack . local . uid , ) : <EOL> uid = stack . nextUid ( ) <EOL> super ( RemoteDevice , self ) . __init__ ( stack = stack , uid = uid , ** kwa ) <EOL> class UdpDevice ( Device ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> stack , <EOL> ha = None , <EOL> ** kwa ) : <EOL> """<STR_LIT>""" <EOL> if ha : <EOL> host , port = ha <EOL> host = socket . gethostbyname ( host ) <EOL> if host in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> host = '<STR_LIT:127.0.0.1>' <EOL> ha = ( host , port ) <EOL> else : <EOL> ha = ( '<STR_LIT:127.0.0.1>' , stack . Port ) <EOL> super ( ) . __init__ ( stack = stack , ha = ha , ** kwa ) <EOL> @ property <EOL> def host ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . ha [ <NUM_LIT:0> ] <EOL> @ host . setter <EOL> def host ( self , value ) : <EOL> """<STR_LIT>""" <EOL> host , port = self . local . ha <EOL> self . local . ha = ( value , port ) <EOL> @ property <EOL> def port ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . ha [ <NUM_LIT:1> ] <EOL> @ port . setter <EOL> def port ( self , value ) : <EOL> """<STR_LIT>""" <EOL> host , port = self . local . ha <EOL> self . local . ha = ( host , value ) <EOL> class UdpLocalDevice ( UdpDevice , LocalDevice ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> stack , <EOL> ** kwa ) : <EOL> """<STR_LIT>""" <EOL> super ( ) . __init__ ( stack = stack , ** kwa ) <EOL> class UdpRemoteDevice ( UdpDevice , RemoteDevice ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> stack , <EOL> ** kwa ) : <EOL> """<STR_LIT>""" <EOL> super ( ) . __init__ ( stack = stack , ** kwa ) </s>
