def serial_for_url(url, *args, **kwargs):
 do_open = (('do_not_open' not in kwargs) or (not kwargs['do_not_open']))
 if ('do_not_open' in kwargs):
  del kwargs['do_not_open']
 klass = Serial
 try:
  url_nocase = url.lower()
 except AttributeError:
  pass
 else:
  if ('://' in url_nocase):
   protocol = url_nocase.split('://', 1)[0]
   for package_name in protocol_handler_packages:
    module_name = ('%s.protocol_%s' % (package_name, protocol))
    try:
     handler_module = __import__(module_name)
    except ImportError:
     pass
    else:
     klass = sys.modules[module_name].Serial
     break
   else:
    raise ValueError(('invalid URL, protocol %r not known' % (protocol,)))
  else:
   klass = Serial
 instance = klass(None, *args, **kwargs)
 instance.port = url
 if do_open:
  instance.open()
 return instance

def serial_for_url ( url , * args , ** kwargs ) : do_open = ( ( 'do_not_open' not in kwargs ) or ( not kwargs [ 'do_not_open' ] ) ) if ( 'do_not_open' in kwargs ) : del kwargs [ 'do_not_open' ] klass = Serial try : url_nocase = url . lower ( ) except AttributeError : pass else : if ( '://' in url_nocase ) : protocol = url_nocase . split ( '://' , 1 ) [ 0 ] for package_name in protocol_handler_packages : module_name = ( '%s.protocol_%s' % ( package_name , protocol ) ) try : handler_module = __import__ ( module_name ) except ImportError : pass else : klass = sys . modules [ module_name ] . Serial break else : raise ValueError ( ( 'invalid URL, protocol %r not known' % ( protocol , ) ) ) else : klass = Serial instance = klass ( None , * args , ** kwargs ) instance . port = url if do_open : instance . open ( ) return instance
get an instance of the serial class .