<s> VERSION = '<STR_LIT>' <EOL> import sys <EOL> import os <EOL> if os . name == '<STR_LIT>' : <EOL> from . serialwin32 import * <EOL> elif os . name == '<STR_LIT>' : <EOL> from . serialposix import * <EOL> else : <EOL> raise ImportError ( "<STR_LIT>" % ( os . name , ) ) <EOL> protocol_handler_packages = [ <EOL> '<STR_LIT>' , <EOL> ] <EOL> def serial_for_url ( url , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> do_open = '<STR_LIT>' not in kwargs or not kwargs [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in kwargs : del kwargs [ '<STR_LIT>' ] <EOL> klass = Serial <EOL> try : <EOL> url_nocase = url . lower ( ) <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> if '<STR_LIT>' in url_nocase : <EOL> protocol = url_nocase . split ( '<STR_LIT>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> for package_name in protocol_handler_packages : <EOL> module_name = '<STR_LIT>' % ( package_name , protocol , ) <EOL> try : <EOL> handler_module = __import__ ( module_name ) <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> klass = sys . modules [ module_name ] . Serial <EOL> break <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % ( protocol , ) ) <EOL> else : <EOL> klass = Serial <EOL> instance = klass ( None , * args , ** kwargs ) <EOL> instance . port = url <EOL> if do_open : <EOL> instance . open ( ) <EOL> return instance </s>
