Skip to content

Commit 4eea904

Browse files
committed
Server: Replace pyserial tools with full package in local-packages
1 parent 68af39f commit 4eea904

36 files changed

+7909
-706
lines changed

ardublocklyserver/local-packages/serial/CHANGES.rst

Lines changed: 683 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Copyright (c) 2001-2016 Chris Liechti <[email protected]>
2+
All Rights Reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
---------------------------------------------------------------------------
33+
Note:
34+
Individual files contain the following tag instead of the full license text.
35+
36+
SPDX-License-Identifier: BSD-3-Clause
37+
38+
This enables machine processing of license information based on the SPDX
39+
License Identifiers that are here available: http://spdx.org/licenses/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
=================================
2+
pySerial |build-status| |docs|
3+
=================================
4+
5+
Overview
6+
========
7+
This module encapsulates the access for the serial port. It provides backends
8+
for Python_ running on Windows, OSX, Linux, BSD (possibly any POSIX compliant
9+
system) and IronPython. The module named "serial" automatically selects the
10+
appropriate backend.
11+
12+
- Project Homepage: https://github.com/pyserial/pyserial
13+
- Download Page: https://pypi.python.org/pypi/pyserial
14+
15+
BSD license, (C) 2001-2016 Chris Liechti <[email protected]>
16+
17+
18+
Documentation
19+
=============
20+
For API documentation, usage and examples see files in the "documentation"
21+
directory. The ".rst" files can be read in any text editor or being converted to
22+
HTML or PDF using Sphinx_. A HTML version is online at
23+
https://pythonhosted.org/pyserial/
24+
25+
Examples
26+
========
27+
Examples and unit tests are in the directory examples_.
28+
29+
30+
Installation
31+
============
32+
``pip install pyserial`` should work for most users.
33+
34+
Detailed information can be found in `documentation/pyserial.rst`_.
35+
36+
The usual setup.py for Python_ libraries is used for the source distribution.
37+
Windows installers are also available (see download link above).
38+
39+
.. _`documentation/pyserial.rst`: https://github.com/pyserial/pyserial/blob/master/documentation/pyserial.rst#installation
40+
.. _examples: https://github.com/pyserial/pyserial/blob/master/examples
41+
.. _Python: http://python.org/
42+
.. _Sphinx: http://sphinx-doc.org/
43+
.. |build-status| image:: https://travis-ci.org/pyserial/pyserial.svg?branch=master
44+
:target: https://travis-ci.org/pyserial/pyserial
45+
:alt: Build status
46+
.. |docs| image:: https://readthedocs.org/projects/pyserial/badge/?version=latest
47+
:target: http://pyserial.readthedocs.io/
48+
:alt: Documentation
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python
2+
#
3+
# This is a wrapper module for different platform implementations
4+
#
5+
# This file is part of pySerial. https://github.com/pyserial/pyserial
6+
# (C) 2001-2016 Chris Liechti <[email protected]>
7+
#
8+
# SPDX-License-Identifier: BSD-3-Clause
9+
10+
import sys
11+
import importlib
12+
13+
from serial.serialutil import *
14+
#~ SerialBase, SerialException, to_bytes, iterbytes
15+
16+
__version__ = '3.2.1'
17+
18+
VERSION = __version__
19+
20+
# pylint: disable=wrong-import-position
21+
if sys.platform == 'cli':
22+
from serial.serialcli import Serial
23+
else:
24+
import os
25+
# chose an implementation, depending on os
26+
if os.name == 'nt': # sys.platform == 'win32':
27+
from serial.serialwin32 import Serial
28+
elif os.name == 'posix':
29+
from serial.serialposix import Serial, PosixPollSerial, VTIMESerial # noqa
30+
elif os.name == 'java':
31+
from serial.serialjava import Serial
32+
else:
33+
raise ImportError("Sorry: no implementation for your platform ('{}') available".format(os.name))
34+
35+
36+
protocol_handler_packages = [
37+
'serial.urlhandler',
38+
]
39+
40+
41+
def serial_for_url(url, *args, **kwargs):
42+
"""\
43+
Get an instance of the Serial class, depending on port/url. The port is not
44+
opened when the keyword parameter 'do_not_open' is true, by default it
45+
is. All other parameters are directly passed to the __init__ method when
46+
the port is instantiated.
47+
48+
The list of package names that is searched for protocol handlers is kept in
49+
``protocol_handler_packages``.
50+
51+
e.g. we want to support a URL ``foobar://``. A module
52+
``my_handlers.protocol_foobar`` is provided by the user. Then
53+
``protocol_handler_packages.append("my_handlers")`` would extend the search
54+
path so that ``serial_for_url("foobar://"))`` would work.
55+
"""
56+
# check and remove extra parameter to not confuse the Serial class
57+
do_open = not kwargs.pop('do_not_open', False)
58+
# the default is to use the native implementation
59+
klass = Serial
60+
try:
61+
url_lowercase = url.lower()
62+
except AttributeError:
63+
# it's not a string, use default
64+
pass
65+
else:
66+
# if it is an URL, try to import the handler module from the list of possible packages
67+
if '://' in url_lowercase:
68+
protocol = url_lowercase.split('://', 1)[0]
69+
module_name = '.protocol_{}'.format(protocol)
70+
for package_name in protocol_handler_packages:
71+
try:
72+
importlib.import_module(package_name)
73+
handler_module = importlib.import_module(module_name, package_name)
74+
except ImportError:
75+
continue
76+
else:
77+
if hasattr(handler_module, 'serial_class_for_url'):
78+
url, klass = handler_module.serial_class_for_url(url)
79+
else:
80+
klass = handler_module.Serial
81+
break
82+
else:
83+
raise ValueError('invalid URL, protocol {!r} not known'.format(protocol))
84+
# instantiate and open when desired
85+
instance = klass(None, *args, **kwargs)
86+
instance.port = url
87+
if do_open:
88+
instance.open()
89+
return instance

0 commit comments

Comments
 (0)