serial_for_url: add option to implement a factory function instead of Serial instance in modules
diff --git a/serial/__init__.py b/serial/__init__.py
index cdc2ba3..7e24719 100644
--- a/serial/__init__.py
+++ b/serial/__init__.py
@@ -71,7 +71,10 @@
except ImportError:
continue
else:
- klass = handler_module.Serial
+ if hasattr(handler_module, 'serial_class_for_url'):
+ url, klass = handler_module.serial_class_for_url(url)
+ else:
+ klass = handler_module.Serial
break
else:
raise ValueError('invalid URL, protocol %r not known' % (protocol,))