From 7c35afbb0cdf2f32d8344717453cb28e09153438 Mon Sep 17 00:00:00 2001 From: aor-fokus <46489184+aor-fokus@users.noreply.github.com> Date: Fri, 18 Jan 2019 14:13:03 +0100 Subject: [PATCH] Test debian stretch+python3 (#18) * changes starting with python3 explicit * removes python modules which are not available for python3 * exchanges fyzz query parsing with rdflib functionality * fixes interop tests * replaces reduce with for loop in nodb driver * simple python2 -> python3 conversions * adds changes for handling different string handling in python3 * test stretch building with travis * installing python-setuptools in docker * installing python-setuptools in docker * changing python2 to python3 in docker makefiles * changing python2 to python3 and some other test changes * push docker only in master branche * running version of openmtc * fix some port problems * porting path library completly now * restoring travis.yml * testing new travis.yml * add sudo * updating travis OS from trusty to xenial * upgrade pip before * show running docker logs * show more logs * for debugging * showlogs of docker after failure * testing new travis.yml * finish travis.yml --- .travis.yml | 40 +++--- apps/InfluxdbApp/bin/openmtc-influxdb-app | 2 +- .../docker/configure-influxdbapp-and-start | 2 +- apps/InfluxdbApp/setup-influxdbapp.py | 2 +- apps/InfluxdbApp/src/influxdbapp/__main__.py | 18 +-- .../src/influxdbapp/influxdb_app.py | 4 +- apps/InfluxdbApp/utils.py | 8 +- .../bin/openmtc-orion-context-broker | 2 +- .../configure-orioncontextbroker-and-start | 2 +- .../setup-orioncontextbroker.py | 2 +- .../src/orioncontextbroker/__main__.py | 13 +- .../src/orioncontextbroker/orion_api.py | 17 +-- .../orion_context_broker.py | 14 +- apps/OrionContextBroker/utils.py | 8 +- apps/csv-injector | 2 +- apps/csvInjector/bin/openmtc-csv-injector | 2 +- .../docker/configure-csvinjector-and-start | 2 +- apps/csvInjector/setup-csvinjector.py | 2 +- apps/csvInjector/src/csvinjector/__main__.py | 28 ++-- .../src/csvinjector/csv_injector.py | 4 +- .../src/csvinjector/csv_process.py | 2 +- apps/csvInjector/utils.py | 8 +- apps/influxdb-app | 2 +- apps/mqtt-connector | 2 +- apps/mqttConnector/bin/openmtc-mqtt-connector | 2 +- .../docker/configure-mqttconnector-and-start | 2 +- apps/mqttConnector/setup-mqttconnector.py | 2 +- .../src/mqttconnector/__main__.py | 35 ++--- .../src/mqttconnector/mqtt_connector.py | 2 +- apps/mqttConnector/utils.py | 8 +- apps/orion-context-broker | 2 +- .../src/openmtc_onem2m/client/http.py | 14 +- .../src/openmtc_onem2m/client/mqtt.py | 7 +- .../src/openmtc_onem2m/mapper/__init__.py | 5 +- .../src/openmtc_onem2m/model.py | 47 +++---- .../src/openmtc_onem2m/serializer/__init__.py | 4 +- .../src/openmtc_onem2m/serializer/base.py | 16 +-- .../serializer/json/__init__.py | 2 + .../src/openmtc_onem2m/serializer/util.py | 2 +- .../src/openmtc_onem2m/transport.py | 8 +- common/openmtc/lib/aplus/__init__.py | 17 +-- common/openmtc/src/openmtc/configuration.py | 8 +- common/openmtc/src/openmtc/model/__init__.py | 68 +++++----- create-app-structure | 8 +- create-binary-dist | 18 +-- doc/example-apps/IoT-data-visualization.py | 18 +-- .../onem2m-examples/onem2m-example-1.py | 10 +- .../onem2m-examples/onem2m-example-10.py | 10 +- .../onem2m-examples/onem2m-example-11a.py | 14 +- .../onem2m-examples/onem2m-example-11b.py | 8 +- .../onem2m-examples/onem2m-example-12a.py | 10 +- .../onem2m-examples/onem2m-example-12b.py | 24 ++-- .../onem2m-examples/onem2m-example-2.py | 10 +- .../onem2m-examples/onem2m-example-3.py | 2 +- .../onem2m-examples/onem2m-example-4.py | 2 +- .../onem2m-examples/onem2m-example-5a.py | 4 +- .../onem2m-examples/onem2m-example-5b.py | 4 +- .../onem2m-examples/onem2m-example-6a.py | 4 +- .../onem2m-examples/onem2m-example-6b.py | 4 +- .../onem2m-examples/onem2m-example-7.py | 4 +- .../onem2m-examples/onem2m-example-8b.py | 6 +- doc/training/start-app.sh | 2 +- docker/backend-amd64 | 2 +- docker/backend-arm | 2 +- docker/base-amd64 | 7 +- docker/base-arm | 7 +- docker/configure-backend-and-start | 2 +- docker/configure-gateway-and-start | 2 +- docker/gateway-amd64 | 2 +- docker/gateway-arm | 2 +- docker/sdk-amd64 | 4 +- docker/sdk-arm | 4 +- futile/src/futile/collections/OrderedSet.py | 2 +- futile/src/futile/net/PortTester.py | 6 +- .../futile/net/http/client/RestClientAsync.py | 2 +- .../futile/net/http/server/ssl/__init__.py | 2 +- futile/src/futile/path/__init__.py | 60 ++++----- futile/src/futile/serializer/xml.py | 2 +- futile/src/futile/subprocess/daemon.py | 2 +- futile/src/futile/threading/RWLock.py | 2 +- ipes/CUL868IPE/bin/openmtc-cul-868-ipe | 2 +- .../docker/configure-cul868ipe-and-start | 2 +- ipes/CUL868IPE/setup-cul868ipe.py | 2 +- ipes/CUL868IPE/src/cul868ipe/__main__.py | 6 +- .../src/cul868ipe/cul_868_coordinator.py | 2 +- ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py | 10 +- ipes/CUL868IPE/src/cul868ipe/test_parsers.py | 2 +- ipes/CUL868IPE/utils.py | 8 +- ipes/cul-868-ipe | 2 +- .../src/openmtc_app/notification/__init__.py | 6 +- openmtc-app/src/openmtc_app/onem2m.py | 22 ++-- openmtc-app/src/openmtc_app/util.py | 3 +- openmtc-gevent/bin/openmtc-backend-gevent | 2 +- openmtc-gevent/bin/openmtc-gateway-gevent | 2 +- openmtc-gevent/dependencies.txt | 5 +- openmtc-gevent/run-backend | 2 +- openmtc-gevent/run-gateway | 2 +- openmtc-gevent/src/openmtc_gevent/main.py | 15 ++- .../src/openmtc_cse/methoddomain/__init__.py | 2 +- .../methoddomain/controller/__init__.py | 44 ++++--- .../methoddomain/filtercriteria/__init__.py | 6 +- .../plugins/announcement_handler/__init__.py | 20 +-- .../plugins/notification_handler/__init__.py | 24 ++-- .../plugins/registration_handler/__init__.py | 2 +- .../plugins/transport_gevent_http/wsgi.py | 13 +- .../plugins/transport_gevent_mqtt/__init__.py | 4 +- .../src/openmtc_cse/transport/__init__.py | 6 +- .../src/openmtc_server/Event.py | 8 +- .../src/openmtc_server/TaskRunner.py | 4 +- .../src/openmtc_server/__init__.py | 4 +- .../src/openmtc_server/db/__init__.py | 19 +-- .../src/openmtc_server/db/nodb2.py | 18 +-- .../platform/default/TaskRunner.py | 2 +- .../src/openmtc_server/util/__init__.py | 2 +- .../util/{async.py => async_.py} | 0 setup-gevent-all.py | 13 +- setup-sdk.py | 6 +- tests/interoperability/basic.yaml | 120 +++++++++++++----- util/json_benchmark.py | 16 +-- utils.py | 8 +- 120 files changed, 574 insertions(+), 575 deletions(-) rename server/openmtc-server/src/openmtc_server/util/{async.py => async_.py} (100%) diff --git a/.travis.yml b/.travis.yml index 63c70a4..cf38e29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,12 @@ services: - docker +dist: xenial before_script: - sudo apt update -- sudo apt install qemu-user-static +- sudo apt install qemu-user-static python3 python3-pip python3-setuptools +- sudo pip3 install --upgrade pip +- sudo python3 -m pip install --upgrade setuptools +- sudo python3 -m pip install --upgrade pyresttest - "./create-binary-docker backend" - "./create-binary-docker backend -a arm" - "./create-binary-docker gateway" @@ -13,24 +17,24 @@ before_script: - "./create-binary-docker influxdbapp -a arm" - "./create-binary-docker cul868ipe" - "./create-binary-docker cul868ipe -a arm" +- docker run -d --name backend -p 0.0.0.0:18000:18000 -e "ONEM2M_CSE_ID=backend" -e "ONEM2M_NOTIFICATION_DISABLED=false" openmtc/backend-amd64 -v +- docker logs backend +- docker run -d --name gateway -p 0.0.0.0:8000:8000 -e "ONEM2M_HTTP_TRANSPORT_PORT=8000" -e "ONEM2M_CSE_ID=gateway" -e "ONEM2M_REMOTE_CSE_POA=" -e "ONEM2M_REMOTE_CSE_ID=backend" -e "ONEM2M_NOTIFICATION_DISABLED=false" -e "ONEM2M_REGISTRATION_DISABLED=false" openmtc/gateway-amd64 -v +- docker logs gateway script: -- docker tag openmtc/orioncontextbroker-amd64 openmtc/orion-context-broker-app-amd64 -- docker tag openmtc/orioncontextbroker-arm openmtc/orion-context-broker-app-arm -- docker tag openmtc/cul868ipe-amd64 openmtc/cul868-ipe-amd64 -- docker tag openmtc/cul868ipe-arm openmtc/cul868-ipe-arm -- docker tag openmtc/influxdbapp-amd64 openmtc/influxdb-app-amd64 -- docker tag openmtc/influxdbapp-arm openmtc/influxdb-app-arm -- docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"; -- docker push openmtc/backend-amd64 -- docker push openmtc/backend-arm -- docker push openmtc/gateway-amd64 -- docker push openmtc/gateway-arm -- docker push openmtc/orion-context-broker-app-amd64 -- docker push openmtc/orion-context-broker-app-arm -- docker push openmtc/cul868-ipe-amd64 -- docker push openmtc/cul868-ipe-arm -- docker push openmtc/influxdb-app-amd64 -- docker push openmtc/influxdb-app-arm + - docker tag openmtc/orioncontextbroker-amd64 openmtc/orion-context-broker-app-amd64 + - docker tag openmtc/orioncontextbroker-arm openmtc/orion-context-broker-app-arm + - docker tag openmtc/cul868ipe-amd64 openmtc/cul868-ipe-amd64 + - docker tag openmtc/cul868ipe-arm openmtc/cul868-ipe-arm + - docker tag openmtc/influxdbapp-amd64 openmtc/influxdb-app-amd64 + - docker tag openmtc/influxdbapp-arm openmtc/influxdb-app-arm + - docker logs gateway + - docker logs backend +after_script: + - pyresttest http://localhost:8000 tests/interoperability/basic.yaml env: matrix: secure: oQe/MxxFrPPArxb6OFzOUwG2ZlA5GYekMR6qn0Y3101v82MdrIVgDILHR41iwykTtk1XpJPV9uabsRsvY4hBmbjYzihYZFOAzFf+/KU7wROtKum0fFfLjCPb8uGV41k1JTquB94FibXboVAP7rNL0Vrpl+FGUvMGatQBtwZnGvha6Ha07qTao+X9+0dJ4YvFlvcba/jfzBZBwHw7KHpRoiyKU0dPmXpHcqnZBFcNqRXhzdVrgx0auP/tghoshW5LQWkpTV11uSx/kYuby4oo8r8nB6L0rW1jYSXs9DHiTQCfCy24xlb9YJjCD9aFcjH0lIkVIqQwJYA67MzKYMK4XV684J/Jr3+jfVOoUt0bpZaTnk+r/uiFCtEsN7q0KUlvHLUAi1YNJhKs6CRrAH3GK25QByh+suzPzZoHP42F2LYP9URlzbDH+/v7CwNuw+9pHSmxEhs18LVmggwkMos3o3ArvzMLRNJ3QG1fdoxL/Ubqxhmvhy4rZi6vGQsiF64oX8PN0sRgXekTU/ma+6CTM6qhgkocMUYzT2r/6qd/9R3jmtxSZnikjkR6Iu9NLzAUY+cqnvvjohAvqYyj+tGlQfOPxAU9H4wXnbQWLBM8yn6yt2Ki+3+Jx4Owdv0oXVJpN0GWjMzIJ1nEus5odkWW+c4wcZb6m3Ak0PrzYPp2BgE= +after_failure: + - docker logs backend + - docker logs gateway \ No newline at end of file diff --git a/apps/InfluxdbApp/bin/openmtc-influxdb-app b/apps/InfluxdbApp/bin/openmtc-influxdb-app index 59a9f00..8c22921 100755 --- a/apps/InfluxdbApp/bin/openmtc-influxdb-app +++ b/apps/InfluxdbApp/bin/openmtc-influxdb-app @@ -1,3 +1,3 @@ #!/usr/bin/env bash -exec python -m influxdbapp $@ +exec python3 -m influxdbapp $@ diff --git a/apps/InfluxdbApp/docker/configure-influxdbapp-and-start b/apps/InfluxdbApp/docker/configure-influxdbapp-and-start index 8c537e5..69add5e 100755 --- a/apps/InfluxdbApp/docker/configure-influxdbapp-and-start +++ b/apps/InfluxdbApp/docker/configure-influxdbapp-and-start @@ -70,4 +70,4 @@ mv ${CONFIG_TEMP} ${CONFIG_FILE} echo "done" -exec python -m influxdbapp $@ +exec python3 -m influxdbapp $@ diff --git a/apps/InfluxdbApp/setup-influxdbapp.py b/apps/InfluxdbApp/setup-influxdbapp.py index d73d678..4dc0278 100755 --- a/apps/InfluxdbApp/setup-influxdbapp.py +++ b/apps/InfluxdbApp/setup-influxdbapp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup from distutils.core import setup diff --git a/apps/InfluxdbApp/src/influxdbapp/__main__.py b/apps/InfluxdbApp/src/influxdbapp/__main__.py index 5a55ea9..4de9825 100644 --- a/apps/InfluxdbApp/src/influxdbapp/__main__.py +++ b/apps/InfluxdbApp/src/influxdbapp/__main__.py @@ -30,21 +30,21 @@ parser.add_argument("--db-pw", help="InfluxDB User password") args, config = prepare_app(parser, __loader__, __name__, "config.json") # variables -nm = get_value("name", (unicode, str), default_name, args, config) +nm = get_value("name", str, default_name, args, config) cb = config.get("cse_base", "onem2m") -ep = get_value("ep", (unicode, str), default_ep, args, config) +ep = get_value("ep", str, default_ep, args, config) poas = config.get("poas", ["http://auto:23706"]) originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1") ssl_certs = config.get("ssl_certs", {}) lbl = get_value("labels", list, default_labels, args, config) -influx_host = get_value("influx_host", (unicode, str), "localhost", args, config) -influx_port = get_value("influx_port", (unicode, str), "8086", args, config) -influx_user = get_value("influx_user", (unicode, str), "root", args, config) -influx_password = get_value("influx_password", (unicode, str), "root", args, config) -db_name = get_value("db_name", (unicode, str), "example", args, config) -db_user = get_value("db_user", (unicode, str), "test", args, config) -db_pw = get_value("db_pw", (unicode, str), "test", args, config) +influx_host = get_value("influx_host", str, "localhost", args, config) +influx_port = get_value("influx_port", str, "8086", args, config) +influx_user = get_value("influx_user", str, "root", args, config) +influx_password = get_value("influx_password", str, "root", args, config) +db_name = get_value("db_name", str, "example", args, config) +db_user = get_value("db_user", str, "test", args, config) +db_pw = get_value("db_pw", str, "test", args, config) # start app = InfluxdbApp( diff --git a/apps/InfluxdbApp/src/influxdbapp/influxdb_app.py b/apps/InfluxdbApp/src/influxdbapp/influxdb_app.py index 2c08b55..6ace8c2 100644 --- a/apps/InfluxdbApp/src/influxdbapp/influxdb_app.py +++ b/apps/InfluxdbApp/src/influxdbapp/influxdb_app.py @@ -1,5 +1,5 @@ from openmtc_app.onem2m import ResourceManagementXAE -from connector import InfluxDBConnector +from .connector import InfluxDBConnector class InfluxdbApp(ResourceManagementXAE): @@ -18,7 +18,7 @@ class InfluxdbApp(ResourceManagementXAE): **kw ): super(InfluxdbApp, self).__init__(*args, **kw) - if isinstance(labels, basestring): + if isinstance(labels, str): self.labels = {labels} elif hasattr(labels, '__iter__') and len(labels): self.labels = set(labels) diff --git a/apps/InfluxdbApp/utils.py b/apps/InfluxdbApp/utils.py index d8a733f..532a2cc 100644 --- a/apps/InfluxdbApp/utils.py +++ b/apps/InfluxdbApp/utils.py @@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None): r_prefix = len(root) + 1 for path, dirs, files in os.walk(root, onerror=on_error): is_module = "__init__.py" in files and path != root - excluded = any(map(lambda x: x in path, excluded_list)) - included = any(map(lambda x: x in path, included_list)) + excluded = any([x in path for x in excluded_list]) + included = any([x in path for x in included_list]) if is_module and (not excluded or included): packages.append(package + "." + path[r_prefix:].replace("/", ".")) @@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name): def enable_init_files(init_dir, init_dist_files): for f in init_dist_files: - os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755) + os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755) def move_config_files(config_dir, config_files): @@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None): try: from pwd import getpwnam except ImportError: - print "Could not import the 'pwd' module. Skipping user management" + print("Could not import the 'pwd' module. Skipping user management") else: # assuming DB_DIR was created by setup already try: diff --git a/apps/OrionContextBroker/bin/openmtc-orion-context-broker b/apps/OrionContextBroker/bin/openmtc-orion-context-broker index 1908c2d..600fd14 100755 --- a/apps/OrionContextBroker/bin/openmtc-orion-context-broker +++ b/apps/OrionContextBroker/bin/openmtc-orion-context-broker @@ -1,3 +1,3 @@ #!/usr/bin/env bash -exec python -m orioncontextbroker $@ +exec python3 -m orioncontextbroker $@ diff --git a/apps/OrionContextBroker/docker/configure-orioncontextbroker-and-start b/apps/OrionContextBroker/docker/configure-orioncontextbroker-and-start index 8822f25..fe05e08 100755 --- a/apps/OrionContextBroker/docker/configure-orioncontextbroker-and-start +++ b/apps/OrionContextBroker/docker/configure-orioncontextbroker-and-start @@ -64,4 +64,4 @@ mv ${CONFIG_TEMP} ${CONFIG_FILE} echo "done" -exec python -m orioncontextbroker $@ +exec python3 -m orioncontextbroker $@ diff --git a/apps/OrionContextBroker/setup-orioncontextbroker.py b/apps/OrionContextBroker/setup-orioncontextbroker.py index eb11b17..6d0e7b8 100755 --- a/apps/OrionContextBroker/setup-orioncontextbroker.py +++ b/apps/OrionContextBroker/setup-orioncontextbroker.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup from distutils.core import setup diff --git a/apps/OrionContextBroker/src/orioncontextbroker/__main__.py b/apps/OrionContextBroker/src/orioncontextbroker/__main__.py index a68ba4f..0963941 100644 --- a/apps/OrionContextBroker/src/orioncontextbroker/__main__.py +++ b/apps/OrionContextBroker/src/orioncontextbroker/__main__.py @@ -38,20 +38,17 @@ parser.add_argument( args, config = prepare_app(parser, __loader__, __name__, "config.json") # variables -nm = get_value("name", (unicode, str), default_name, args, config) +nm = get_value("name", str, default_name, args, config) cb = config.get("cse_base", "onem2m") -ep = get_value("ep", (unicode, str), default_ep, args, config) +ep = get_value("ep", str, default_ep, args, config) poas = config.get("poas", ["http://auto:25396"]) originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1") ssl_certs = config.get("ssl_certs", {}) interval = get_value("interval", int, default_ep, args, config) lbl = get_value("labels", list, default_labels, args, config) -orion_host = get_value("orion_host", (unicode, str), default_orion_host, args, - config) -orion_api = get_value("orion_api", (unicode, str), default_orion_api, args, - config) -accumulate_address = get_value("accumulate_address", (unicode, str), - default_accumulate_address, args, config) +orion_host = get_value("orion_host", str, default_orion_host, args, config) +orion_api = get_value("orion_api", str, default_orion_api, args, config) +accumulate_address = get_value("accumulate_address", str, default_accumulate_address, args, config) # start app = OrionContextBroker( diff --git a/apps/OrionContextBroker/src/orioncontextbroker/orion_api.py b/apps/OrionContextBroker/src/orioncontextbroker/orion_api.py index 77a855b..c921630 100644 --- a/apps/OrionContextBroker/src/orioncontextbroker/orion_api.py +++ b/apps/OrionContextBroker/src/orioncontextbroker/orion_api.py @@ -1,7 +1,4 @@ -try: - from urllib.parse import urljoin -except ImportError: - from urlparse import urljoin +from urllib.parse import urljoin import logging import requests @@ -32,16 +29,16 @@ class OrionAPI(LoggerMixin): def _get_type(self, element): if isinstance(element, int): - return u"Int" + return "Int" elif isinstance(element, float): - return u"Float" + return "Float" elif isinstance(element, bool): - return u"Boolean" - elif isinstance(element, (str, unicode)): - return u"String" + return "Boolean" + elif isinstance(element, str): + return "String" else: self.logger.error('Type of "{}" unknown'.format(element)) - return u"Unknown" + return "Unknown" def is_host_alive(self): req = self._request( diff --git a/apps/OrionContextBroker/src/orioncontextbroker/orion_context_broker.py b/apps/OrionContextBroker/src/orioncontextbroker/orion_context_broker.py index bd3e1c8..14003a2 100644 --- a/apps/OrionContextBroker/src/orioncontextbroker/orion_context_broker.py +++ b/apps/OrionContextBroker/src/orioncontextbroker/orion_context_broker.py @@ -1,14 +1,11 @@ import re -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse +from urllib.parse import urlparse from flask import Flask, Response, request from gevent.pywsgi import WSGIServer from openmtc_app.onem2m import ResourceManagementXAE -from orion_api import OrionAPI +from .orion_api import OrionAPI class OrionContextBroker(ResourceManagementXAE): @@ -20,7 +17,7 @@ class OrionContextBroker(ResourceManagementXAE): *args, **kw): super(OrionContextBroker, self).__init__(*args, **kw) - if isinstance(labels, basestring): + if isinstance(labels, str): self.labels = {labels} elif hasattr(labels, '__iter__'): self.labels = set(labels) @@ -103,9 +100,8 @@ class OrionContextBroker(ResourceManagementXAE): device_type = "sensor" if sensor_info.get("sensor_labels", None) else "actuator" try: - id_label = filter( - lambda x: (x.startswith('openmtc:id:')), - sensor_info['{}_labels'.format(device_type)]).pop() + id_label = [x for x in sensor_info['{}_labels'.format(device_type)] + if x.startswith('openmtc:id:')].pop() cse_id, dev_id = re.sub('^openmtc:id:', '', id_label).split('/')[:2] except (IndexError, ValueError): diff --git a/apps/OrionContextBroker/utils.py b/apps/OrionContextBroker/utils.py index d8a733f..532a2cc 100644 --- a/apps/OrionContextBroker/utils.py +++ b/apps/OrionContextBroker/utils.py @@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None): r_prefix = len(root) + 1 for path, dirs, files in os.walk(root, onerror=on_error): is_module = "__init__.py" in files and path != root - excluded = any(map(lambda x: x in path, excluded_list)) - included = any(map(lambda x: x in path, included_list)) + excluded = any([x in path for x in excluded_list]) + included = any([x in path for x in included_list]) if is_module and (not excluded or included): packages.append(package + "." + path[r_prefix:].replace("/", ".")) @@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name): def enable_init_files(init_dir, init_dist_files): for f in init_dist_files: - os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755) + os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755) def move_config_files(config_dir, config_files): @@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None): try: from pwd import getpwnam except ImportError: - print "Could not import the 'pwd' module. Skipping user management" + print("Could not import the 'pwd' module. Skipping user management") else: # assuming DB_DIR was created by setup already try: diff --git a/apps/csv-injector b/apps/csv-injector index a81d819..d8e66d9 100755 --- a/apps/csv-injector +++ b/apps/csv-injector @@ -6,4 +6,4 @@ cd $(dirname ${0}) cd csvInjector -PYTHONPATH=${PYTHONPATH}:src exec python -m csvinjector $@ +PYTHONPATH=${PYTHONPATH}:src exec python3 -m csvinjector $@ diff --git a/apps/csvInjector/bin/openmtc-csv-injector b/apps/csvInjector/bin/openmtc-csv-injector index 40ba1f8..db4874e 100755 --- a/apps/csvInjector/bin/openmtc-csv-injector +++ b/apps/csvInjector/bin/openmtc-csv-injector @@ -1,3 +1,3 @@ #!/usr/bin/env bash -exec python -m csvinjector $@ +exec python3 -m csvinjector $@ diff --git a/apps/csvInjector/docker/configure-csvinjector-and-start b/apps/csvInjector/docker/configure-csvinjector-and-start index 8df4f5c..498e41f 100755 --- a/apps/csvInjector/docker/configure-csvinjector-and-start +++ b/apps/csvInjector/docker/configure-csvinjector-and-start @@ -70,4 +70,4 @@ mv ${CONFIG_TEMP} ${CONFIG_FILE} echo "done" -exec python -m csvinjector $@ +exec python3 -m csvinjector $@ diff --git a/apps/csvInjector/setup-csvinjector.py b/apps/csvInjector/setup-csvinjector.py index f19fbc6..e07117e 100755 --- a/apps/csvInjector/setup-csvinjector.py +++ b/apps/csvInjector/setup-csvinjector.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup from distutils.core import setup diff --git a/apps/csvInjector/src/csvinjector/__main__.py b/apps/csvInjector/src/csvinjector/__main__.py index 52232fd..d38358e 100644 --- a/apps/csvInjector/src/csvinjector/__main__.py +++ b/apps/csvInjector/src/csvinjector/__main__.py @@ -42,28 +42,20 @@ parser.add_argument( args, config = prepare_app(parser, __loader__, __name__, "config.json") # variables -nm = get_value("name", (unicode, str), default_name, args, config) +nm = get_value("name", str, default_name, args, config) cb = config.get("cse_base", "onem2m") -ep = get_value("ep", (unicode, str), default_ep, args, config) +ep = get_value("ep", str, default_ep, args, config) poas = config.get("poas", ["http://auto:28300"]) originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1") ssl_certs = config.get("ssl_certs", {}) -csv_path = get_value("csv_path", (unicode, str), default_csv_path, args, - config) -csv_delim = get_value("csv_delim", (unicode, str), default_csv_delim, args, - config) -csv_quotechar = get_value("csv_quotechar", (unicode, str), - default_csv_quotechar, args, config) -device_classifier = get_value("device_classifier", (unicode, str), - default_device_classifier, args, config) -date_classifier = get_value("date_classifier", (unicode, str, list), - default_date_classifier, args, config) -time_format = get_value("time_format", (unicode, str, list), - default_time_format, args, config) -duration = get_value("duration", (int, float), - default_duration, args, config) -repeat = get_value("repeat", (unicode, str), - default_repeat, args, config) +csv_path = get_value("csv_path", str, default_csv_path, args, config) +csv_delim = get_value("csv_delim", str, default_csv_delim, args, config) +csv_quotechar = get_value("csv_quotechar", str, default_csv_quotechar, args, config) +device_classifier = get_value("device_classifier", str, default_device_classifier, args, config) +date_classifier = get_value("date_classifier", (str, list), default_date_classifier, args, config) +time_format = get_value("time_format", (str, list), default_time_format, args, config) +duration = get_value("duration", (int, float), default_duration, args, config) +repeat = get_value("repeat", str, default_repeat, args, config) # start app = csvInjector( diff --git a/apps/csvInjector/src/csvinjector/csv_injector.py b/apps/csvInjector/src/csvinjector/csv_injector.py index afbab1e..68bdc5c 100644 --- a/apps/csvInjector/src/csvinjector/csv_injector.py +++ b/apps/csvInjector/src/csvinjector/csv_injector.py @@ -1,6 +1,6 @@ from openmtc_app.onem2m import XAE from openmtc_onem2m.model import Container -from csv_process import csvProcessor +from .csv_process import csvProcessor import sched import time import datetime @@ -95,7 +95,7 @@ class csvInjector(XAE): if k == "Date" or k == self.device_classifier or event[k] in ( "", None): continue - if not k in self._recognized_measurement_containers[sensor].keys(): + if k not in self._recognized_measurement_containers[sensor].keys(): self._create_measurement_container(sensor, k) timestamp = time.mktime(datetime.datetime.now().timetuple()) senml = { diff --git a/apps/csvInjector/src/csvinjector/csv_process.py b/apps/csvInjector/src/csvinjector/csv_process.py index 28b93d4..e8e8be7 100644 --- a/apps/csvInjector/src/csvinjector/csv_process.py +++ b/apps/csvInjector/src/csvinjector/csv_process.py @@ -65,4 +65,4 @@ class csvProcessor(LoggerMixin): if __name__ == "__main__": p = csvProcessor("example.csv", duration=300) for e in p.csv_data: - print e + print(e) diff --git a/apps/csvInjector/utils.py b/apps/csvInjector/utils.py index d8a733f..532a2cc 100644 --- a/apps/csvInjector/utils.py +++ b/apps/csvInjector/utils.py @@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None): r_prefix = len(root) + 1 for path, dirs, files in os.walk(root, onerror=on_error): is_module = "__init__.py" in files and path != root - excluded = any(map(lambda x: x in path, excluded_list)) - included = any(map(lambda x: x in path, included_list)) + excluded = any([x in path for x in excluded_list]) + included = any([x in path for x in included_list]) if is_module and (not excluded or included): packages.append(package + "." + path[r_prefix:].replace("/", ".")) @@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name): def enable_init_files(init_dir, init_dist_files): for f in init_dist_files: - os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755) + os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755) def move_config_files(config_dir, config_files): @@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None): try: from pwd import getpwnam except ImportError: - print "Could not import the 'pwd' module. Skipping user management" + print("Could not import the 'pwd' module. Skipping user management") else: # assuming DB_DIR was created by setup already try: diff --git a/apps/influxdb-app b/apps/influxdb-app index df7bb41..cae95ab 100755 --- a/apps/influxdb-app +++ b/apps/influxdb-app @@ -6,4 +6,4 @@ cd $(dirname ${0}) cd InfluxdbApp -PYTHONPATH=${PYTHONPATH}:src exec python -m influxdbapp $@ +PYTHONPATH=${PYTHONPATH}:src exec python3 -m influxdbapp $@ diff --git a/apps/mqtt-connector b/apps/mqtt-connector index 1566164..8703cca 100755 --- a/apps/mqtt-connector +++ b/apps/mqtt-connector @@ -6,4 +6,4 @@ cd $(dirname ${0}) cd mqttConnector -PYTHONPATH=${PYTHONPATH}:src exec python -m mqttconnector $@ +PYTHONPATH=${PYTHONPATH}:src exec python3 -m mqttconnector $@ diff --git a/apps/mqttConnector/bin/openmtc-mqtt-connector b/apps/mqttConnector/bin/openmtc-mqtt-connector index 0b67da1..28e04f7 100755 --- a/apps/mqttConnector/bin/openmtc-mqtt-connector +++ b/apps/mqttConnector/bin/openmtc-mqtt-connector @@ -1,3 +1,3 @@ #!/usr/bin/env bash -exec python -m mqttconnector $@ +exec python3 -m mqttconnector $@ diff --git a/apps/mqttConnector/docker/configure-mqttconnector-and-start b/apps/mqttConnector/docker/configure-mqttconnector-and-start index 5ab08d8..93582f0 100755 --- a/apps/mqttConnector/docker/configure-mqttconnector-and-start +++ b/apps/mqttConnector/docker/configure-mqttconnector-and-start @@ -76,4 +76,4 @@ mv ${CONFIG_TEMP} ${CONFIG_FILE} echo "done" -exec python -m mqttconnector $@ +exec python3 -m mqttconnector $@ diff --git a/apps/mqttConnector/setup-mqttconnector.py b/apps/mqttConnector/setup-mqttconnector.py index 37da228..b26f517 100755 --- a/apps/mqttConnector/setup-mqttconnector.py +++ b/apps/mqttConnector/setup-mqttconnector.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup from distutils.core import setup diff --git a/apps/mqttConnector/src/mqttconnector/__main__.py b/apps/mqttConnector/src/mqttconnector/__main__.py index a162c7c..080805f 100644 --- a/apps/mqttConnector/src/mqttconnector/__main__.py +++ b/apps/mqttConnector/src/mqttconnector/__main__.py @@ -40,36 +40,27 @@ parser.add_argument("--mqtts-keyfile", help="Path to own mqtts key") args, config = prepare_app(parser, __loader__, __name__, "config.json") # variables -nm = get_value("name", (unicode, str), default_name, args, config) +nm = get_value("name", str, default_name, args, config) cb = config.get("cse_base", "onem2m") -ep = get_value("ep", (unicode, str), default_ep, args, config) +ep = get_value("ep", str, default_ep, args, config) poas = config.get("poas", ["http://auto:21753"]) originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1") ssl_certs = config.get("ssl_certs", {}) - broker_ep = config.get("broker_ep", "localhost:8883") - -topic_pre = get_value("topic_pre", (unicode, str), default_topic_pre, args, - config) -topic_index_location = get_value("topic_index_location", (int), +topic_pre = get_value("topic_pre", str, default_topic_pre, args, config) +topic_index_location = get_value("topic_index_location", int, default_topic_index_location, args, config) -topic_index_device = get_value("topic_index_device", (int), +topic_index_device = get_value("topic_index_device", int, default_topic_index_device, args, config) -fiware_service = get_value("fiware_service", (unicode, str), - default_fiware_service, args, config) -broker_user = get_value("broker_user", (unicode, str), default_broker_user, - args, config) -broker_user_pw = get_value("broker_user_pw", (unicode, str), - default_broker_user_pw, args, config) -user_pw = get_value("broker_user_pw", (unicode, str), default_broker_user_pw, - args, config) +fiware_service = get_value("fiware_service", str, default_fiware_service, args, config) +broker_user = get_value("broker_user", str, default_broker_user, args, config) +broker_user_pw = get_value("broker_user_pw", str, default_broker_user_pw, args, config) +user_pw = get_value("broker_user_pw", str, default_broker_user_pw, args, config) mqtts_enabled = get_value("mqtts_enabled", (bool), False, args, config) -mqtts_ca_certs = get_value("mqtts_ca_certs", (unicode, str), - default_mqtts_ca_certs, args, config) -mqtts_certfile = get_value("mqtts_certfile", (unicode, str), - default_mqtts_certfile, args, config) -mqtts_keyfile = get_value("mqtts_keyfile", (unicode, str), - default_mqtts_keyfile, args, config) +mqtts_ca_certs = get_value("mqtts_ca_certs", str, default_mqtts_ca_certs, args, config) +mqtts_certfile = get_value("mqtts_certfile", str, default_mqtts_certfile, args, config) +mqtts_keyfile = get_value("mqtts_keyfile", str, default_mqtts_keyfile, args, config) + # start app = mqttConnector( broker_ep=broker_ep, diff --git a/apps/mqttConnector/src/mqttconnector/mqtt_connector.py b/apps/mqttConnector/src/mqttconnector/mqtt_connector.py index a58b6d1..09c8431 100644 --- a/apps/mqttConnector/src/mqttconnector/mqtt_connector.py +++ b/apps/mqttConnector/src/mqttconnector/mqtt_connector.py @@ -115,7 +115,7 @@ class mqttConnector(XAE): # check payload try: readings = json_decode( - base64decode(json_decode(payload)['m2m:cin']['con'])) + base64decode(json_decode(payload)['m2m:cin']['con']).decode('utf-8')) except (ValueError, KeyError, TypeError): self.logger.error('Damaged payload; discarding') return diff --git a/apps/mqttConnector/utils.py b/apps/mqttConnector/utils.py index d8a733f..532a2cc 100644 --- a/apps/mqttConnector/utils.py +++ b/apps/mqttConnector/utils.py @@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None): r_prefix = len(root) + 1 for path, dirs, files in os.walk(root, onerror=on_error): is_module = "__init__.py" in files and path != root - excluded = any(map(lambda x: x in path, excluded_list)) - included = any(map(lambda x: x in path, included_list)) + excluded = any([x in path for x in excluded_list]) + included = any([x in path for x in included_list]) if is_module and (not excluded or included): packages.append(package + "." + path[r_prefix:].replace("/", ".")) @@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name): def enable_init_files(init_dir, init_dist_files): for f in init_dist_files: - os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755) + os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755) def move_config_files(config_dir, config_files): @@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None): try: from pwd import getpwnam except ImportError: - print "Could not import the 'pwd' module. Skipping user management" + print("Could not import the 'pwd' module. Skipping user management") else: # assuming DB_DIR was created by setup already try: diff --git a/apps/orion-context-broker b/apps/orion-context-broker index e575968..f94857f 100755 --- a/apps/orion-context-broker +++ b/apps/orion-context-broker @@ -6,4 +6,4 @@ cd $(dirname ${0}) cd OrionContextBroker -PYTHONPATH=${PYTHONPATH}:src exec python -m orioncontextbroker $@ +PYTHONPATH=${PYTHONPATH}:src exec python3 -m orioncontextbroker $@ diff --git a/common/openmtc-onem2m/src/openmtc_onem2m/client/http.py b/common/openmtc-onem2m/src/openmtc_onem2m/client/http.py index dc5c66b..3113ca7 100644 --- a/common/openmtc-onem2m/src/openmtc_onem2m/client/http.py +++ b/common/openmtc-onem2m/src/openmtc_onem2m/client/http.py @@ -1,11 +1,13 @@ -import urllib +import urllib.request +import urllib.parse +import urllib.error import ssl from socket import ( gaierror, error as socket_error, ) from time import time -from urlparse import urlparse +from urllib.parse import urlparse from aplus import Promise from futile.caching import LRUCache from geventhttpclient.client import HTTPClient @@ -145,7 +147,7 @@ class OneM2MHTTPClient(OneM2MClient): filter_criteria = onem2m_request.fc params.update({ (get_short_attribute_name(name) or get_short_member_name(name)): val - for name, val in filter_criteria.get_values(True).iteritems() + for name, val in filter_criteria.get_values(True).items() }) if onem2m_request.ae_notifying: @@ -154,7 +156,7 @@ class OneM2MHTTPClient(OneM2MClient): path = normalize_path(onem2m_request.to) if params: - path += '?' + urllib.urlencode(params, True) + path += '?' + urllib.parse.urlencode(params, True) content_type, data = encode_onem2m_content(onem2m_request.content, self.content_type, path=path) @@ -165,7 +167,7 @@ class OneM2MHTTPClient(OneM2MClient): headers = { header: getattr(onem2m_request, field) - for header, field in _header_to_field_map.iteritems() + for header, field in _header_to_field_map.items() if getattr(onem2m_request, field) is not None } headers['content-type'] = content_type @@ -201,7 +203,7 @@ class OneM2MHTTPClient(OneM2MClient): get_response_status(rsc), request=onem2m_request, rsc=rsc, - pc=decode_onem2m_content(response.read(), response.get("content-type")) + pc=decode_onem2m_content(response.read().decode("utf-8"), response.get("content-type")) ) def send_onem2m_request(self, onem2m_request): diff --git a/common/openmtc-onem2m/src/openmtc_onem2m/client/mqtt.py b/common/openmtc-onem2m/src/openmtc_onem2m/client/mqtt.py index d714abf..03370d3 100644 --- a/common/openmtc-onem2m/src/openmtc_onem2m/client/mqtt.py +++ b/common/openmtc-onem2m/src/openmtc_onem2m/client/mqtt.py @@ -32,7 +32,7 @@ from simplejson import ( JSONDecodeError, ) from socket import error as SocketError -from urlparse import urlparse +from urllib.parse import urlparse from openmtc_onem2m.util import split_onem2m_address #: Dictionary mapping supported schemes to port numbers @@ -353,7 +353,7 @@ class OneM2MMQTTClient(OneM2MClient): self.logger.debug('Decoded JSON request: %s' % (request, )) - op = OneM2MOperation._member_map_.values()[request['op'] - 1] + op = list(OneM2MOperation._member_map_.values())[request['op'] - 1] to = request['to'] del request['op'], request['to'] @@ -485,7 +485,8 @@ class OneM2MMQTTClient(OneM2MClient): else: request.ty = None - request.op = 1 + OneM2MOperation._member_map_.keys().index(OneM2MOperation[request.op].name) + request.op = 1 + list(OneM2MOperation._member_map_.keys()).index( + OneM2MOperation[request.op].name) if request.pc: request.pc = self._decode( encode_onem2m_content(request.pc, 'application/json', path=request.to)[1] diff --git a/common/openmtc-onem2m/src/openmtc_onem2m/mapper/__init__.py b/common/openmtc-onem2m/src/openmtc_onem2m/mapper/__init__.py index 1c25072..caf5080 100644 --- a/common/openmtc-onem2m/src/openmtc_onem2m/mapper/__init__.py +++ b/common/openmtc-onem2m/src/openmtc_onem2m/mapper/__init__.py @@ -1,7 +1,4 @@ -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse +from urllib.parse import urlparse from openmtc.mapper import BasicMapper, MapperError from openmtc_onem2m import OneM2MRequest diff --git a/common/openmtc-onem2m/src/openmtc_onem2m/model.py b/common/openmtc-onem2m/src/openmtc_onem2m/model.py index 828ed4d..aa8f943 100644 --- a/common/openmtc-onem2m/src/openmtc_onem2m/model.py +++ b/common/openmtc-onem2m/src/openmtc_onem2m/model.py @@ -2,7 +2,8 @@ from enum import IntEnum, unique from openmtc.model import (Resource as Res, UnicodeAttribute, DatetimeAttribute, Attribute, ListAttribute, Entity, EntityAttribute, - AnyURI, StringListAttribute, ContentResource) + AnyURI, StringListAttribute, ContentResource, + BytesAttribute) from openmtc.model.exc import ModelTypeError from futile import issubclass @@ -407,7 +408,7 @@ class FilterUsageE(OneM2MIntEnum): @unique class CountryCodeE(OneM2MIntEnum): india = 91 - usa = 01 + usa = 1 @unique @@ -600,7 +601,7 @@ class ResourceC(LabeledResource): typename = None - resourceName = UnicodeAttribute(accesstype=Attribute.WO) + resourceName = UnicodeAttribute(accesstype=Attribute.WO, mandatory=False) resourceType = EntityAttribute(ResourceTypeE, accesstype=Attribute.RO) resourceID = IDS(accesstype=Attribute.RO) @@ -789,8 +790,7 @@ class Subscription(RegularResourceC): notificationForwardingURI = Attribute(AnyURI) batchNotify = EntityAttribute(BatchNotify) rateLimit = EntityAttribute(RateLimit) - preSubscriptionNotify = Attribute(int, accesstype=Attribute.WO, - mandatory=False) + preSubscriptionNotify = Attribute(int, accesstype=Attribute.WO, mandatory=False) pendingNotification = Attribute(PendingNotificationE) notificationStoragePriority = Attribute(int) latestNotify = Attribute(bool) @@ -991,8 +991,8 @@ class ContentInstance(AnnounceableSubordinateResourceC, # ex: application/json:1 contentInfo = UnicodeAttribute() # m2m:contentInfo contentSize = Attribute(int, accesstype=Attribute.RO) - ontologyRef = UnicodeAttribute(accesstype=Attribute.WO) - content = Attribute(bytes, accesstype=Attribute.WO, mandatory=True) + ontologyRef = UnicodeAttribute(accesstype=Attribute.WO, mandatory=False) + content = BytesAttribute(accesstype=Attribute.WO, mandatory=True) __child_types__ = ( Subscription, @@ -1004,8 +1004,8 @@ class ContentInstanceAnnc(AnnouncedSubordinateResourceC): stateTag = Attribute(int, accesstype=Attribute.RO) contentInfo = UnicodeAttribute(EncodingTypeE) # m2m:contentInfo contentSize = Attribute(int, accesstype=Attribute.WO) - ontologyRef = UnicodeAttribute(accesstype=Attribute.WO) - content = Attribute(bytes, accesstype=Attribute.WO, mandatory=True) + ontologyRef = UnicodeAttribute(accesstype=Attribute.WO, mandatory=False) + content = BytesAttribute(accesstype=Attribute.WO, mandatory=True) ################################################################################ @@ -1107,7 +1107,7 @@ class AEAnnc(AnnouncedResourceC, SubscribableResource): typename = "AEAnnc" - appName = UnicodeAttribute(accesstype=Attribute.WO) + appName = UnicodeAttribute(accesstype=Attribute.WO, mandatory=False) App_ID = UnicodeAttribute() AE_ID = UnicodeAttribute() pointOfAccess = StringListAttribute() @@ -1376,8 +1376,7 @@ long_to_short_attribute_mapping = { "relatedSemantics": "rels", } -short_to_long_attribute_mapping = {v: k for k, v in - long_to_short_attribute_mapping.items()} +short_to_long_attribute_mapping = {v: k for k, v in long_to_short_attribute_mapping.items()} def get_long_attribute_name(n): @@ -1459,8 +1458,7 @@ long_to_short_resource_mapping = { "dynamicAuthorizationConsultation": "dac" } -short_to_long_resource_mapping = {v: k for k, v in - long_to_short_resource_mapping.items()} +short_to_long_resource_mapping = {v: k for k, v in long_to_short_resource_mapping.items()} def get_long_resource_name(n): @@ -1584,8 +1582,7 @@ long_to_short_member_mapping = { "escertkeMessage": "eckm" } -short_to_long_member_mapping = {v: k for k, v in - long_to_short_member_mapping.items()} +short_to_long_member_mapping = {v: k for k, v in long_to_short_member_mapping.items()} def get_long_member_name(n): @@ -1601,8 +1598,7 @@ long_to_short_root_mapping = { "responsePrimitive": "rsp" } -short_to_long_root_mapping = {v: k for k, v in - long_to_short_root_mapping.items()} +short_to_long_root_mapping = {v: k for k, v in long_to_short_root_mapping.items()} def get_long_root_name(n): @@ -1636,8 +1632,7 @@ long_to_short_parameter_mapping = { "responseStatusCode": "rsc" } -short_to_long_parameter_mapping = {v: k for k, v in - long_to_short_parameter_mapping.items()} +short_to_long_parameter_mapping = {v: k for k, v in long_to_short_parameter_mapping.items()} def get_long_parameter_name(n): @@ -1648,13 +1643,13 @@ def get_short_parameter_name(n): return long_to_short_parameter_mapping.get(n) -_all_types = {k: v for k, v in globals().iteritems() +_all_types = {k: v for k, v in globals().items() if issubclass(v, OneM2MEntity) and not v.__subclasses__()} _all_types_short = {} _all_types_long = {} -for k, v in _all_types.iteritems(): +for k, v in _all_types.items(): if get_short_resource_name(k): long_name = k short_name = get_short_resource_name(k) @@ -1685,13 +1680,13 @@ for k, v in _all_types.iteritems(): _all_types_long[long_name] = v -_resource_types = {k: v for k, v in _all_types.iteritems() +_resource_types = {k: v for k, v in _all_types.items() if issubclass(v, ResourceC)} _resource_types_short = {} _resource_types_long = {} -for k, v in _resource_types.iteritems(): +for k, v in _resource_types.items(): if get_short_resource_name(k): long_name = k short_name = get_short_resource_name(k) @@ -1725,8 +1720,8 @@ def get_onem2m_resource_type(typename): def get_onem2m_types(): - return _all_types.values() + return list(_all_types.values()) def get_onem2m_resource_types(): - return _resource_types.values() + return list(_resource_types.values()) diff --git a/common/openmtc-onem2m/src/openmtc_onem2m/serializer/__init__.py b/common/openmtc-onem2m/src/openmtc_onem2m/serializer/__init__.py index a587b67..a0d8195 100644 --- a/common/openmtc-onem2m/src/openmtc_onem2m/serializer/__init__.py +++ b/common/openmtc-onem2m/src/openmtc_onem2m/serializer/__init__.py @@ -22,7 +22,7 @@ def create_onem2m_serializer(content_type): def get_onem2m_supported_content_types(): - return _factories.keys() + return list(_factories.keys()) def get_onem2m_decoder(content_type): @@ -37,6 +37,8 @@ def get_onem2m_decoder(content_type): serializer = create_onem2m_serializer(content_type) _serializers[content_type] = serializer return serializer + + get_serializer = get_onem2m_decoder diff --git a/common/openmtc-onem2m/src/openmtc_onem2m/serializer/base.py b/common/openmtc-onem2m/src/openmtc_onem2m/serializer/base.py index 7312150..a1a08ea 100644 --- a/common/openmtc-onem2m/src/openmtc_onem2m/serializer/base.py +++ b/common/openmtc-onem2m/src/openmtc_onem2m/serializer/base.py @@ -22,9 +22,7 @@ def get_typename(tn): return _typename_matcher.findall(tn).pop() -class OneM2MSerializer(LoggerMixin): - __metaclass__ = ABCMeta - +class OneM2MSerializer(LoggerMixin, metaclass=ABCMeta): @abstractmethod def encode_resource(self, resource, response, pretty=False, encoding="utf-8", fields=None): @@ -45,7 +43,7 @@ class OneM2MSerializer(LoggerMixin): res_type = ResourceTypeE(v["type"]) res_cls = get_onem2m_resource_type(res_type.name) return res_cls(v["name"], resourceID=v["value"], resourceType=res_type) - child_resource = map(map_child_resource, child_resource) + child_resource = list(map(map_child_resource, child_resource)) except (TypeError, AttributeError, KeyError, ValueError): raise CSEValueError("Invalid entry in child resources: %s", child_resource) @@ -80,7 +78,7 @@ class OneM2MDictSerializer(OneM2MSerializer): ) representation["notificationEvent"] = { get_short_attribute_name(k) or get_short_member_name(k): v - for k, v in e.iteritems() + for k, v in e.items() } except (AttributeError, KeyError): self.logger.exception("failed to encode notify") @@ -104,7 +102,7 @@ class OneM2MDictSerializer(OneM2MSerializer): "nm": c.basename, "typ": c.resourceType } - representation["childResource"] = map(get_child_rep, representation["childResource"]) + representation["childResource"] = list(map(get_child_rep, representation["childResource"])) if isinstance(resource, URIList): representation = [make_val(path, x) for x in representation] @@ -137,7 +135,7 @@ class OneM2MDictSerializer(OneM2MSerializer): return self.dumps({typename: representation}) def _handle_partial_addressing(self, resource, pretty): - for k, v in resource.iteritems(): + for k, v in resource.items(): if k in ('latest', 'oldest') and isinstance(v, ContentInstance): resource[k] = v.resourceID if pretty: @@ -148,7 +146,7 @@ class OneM2MDictSerializer(OneM2MSerializer): def convert_to_long_keys(d): return {get_long_resource_name(k) or get_long_attribute_name(k) or - get_long_member_name(k) or k: v for k, v in d.iteritems()} + get_long_member_name(k) or k: v for k, v in d.items()} try: if hasattr(s, "read"): @@ -161,7 +159,7 @@ class OneM2MDictSerializer(OneM2MSerializer): self.logger.debug("Read data: %s", data) try: - typename, data = data.items()[0] + typename, data = list(data.items())[0] return get_onem2m_type(get_typename(typename)), data except (AttributeError, IndexError, TypeError): raise CSESyntaxError("Not a valid resource representation") diff --git a/common/openmtc-onem2m/src/openmtc_onem2m/serializer/json/__init__.py b/common/openmtc-onem2m/src/openmtc_onem2m/serializer/json/__init__.py index f14be0e..2d92166 100644 --- a/common/openmtc-onem2m/src/openmtc_onem2m/serializer/json/__init__.py +++ b/common/openmtc-onem2m/src/openmtc_onem2m/serializer/json/__init__.py @@ -33,6 +33,8 @@ def _default(x): return x.strftime("%Y%m%dT%H%M%S") elif isinstance(x, ContentInstance): return x.resourceID + elif isinstance(x, bytes): + return x.decode('utf-8') else: try: # handle model classes return x.values diff --git a/common/openmtc-onem2m/src/openmtc_onem2m/serializer/util.py b/common/openmtc-onem2m/src/openmtc_onem2m/serializer/util.py index a992a6b..9f276be 100644 --- a/common/openmtc-onem2m/src/openmtc_onem2m/serializer/util.py +++ b/common/openmtc-onem2m/src/openmtc_onem2m/serializer/util.py @@ -6,7 +6,7 @@ logger = get_logger(__name__) def decode_onem2m_content(content, content_type): - if content == "": + if not content: content = None if content_type and content is not None: serializer = get_onem2m_decoder(content_type) diff --git a/common/openmtc-onem2m/src/openmtc_onem2m/transport.py b/common/openmtc-onem2m/src/openmtc_onem2m/transport.py index 4bc9394..c703684 100644 --- a/common/openmtc-onem2m/src/openmtc_onem2m/transport.py +++ b/common/openmtc-onem2m/src/openmtc_onem2m/transport.py @@ -212,7 +212,9 @@ class OneM2MRequest(object): self.to = to # Originator ID self.originator = fr # original long name is from - self.request_identifier = rqi or ''.join(random.sample(string.letters + string.digits, 16)) + self.request_identifier = rqi or ''.join( + random.sample(string.ascii_letters + string.digits, 16) + ) # Type of a created resource self.resource_type = ty # Resource content to be transferred. @@ -423,7 +425,7 @@ class OneM2MRequest(object): def __str__(self): return '%s: %s' % (self.__class__.__name__, ' | '.join([ - '%s: %s' % (str(k), str(v)) for k, v in self.__dict__.iteritems() + '%s: %s' % (str(k), str(v)) for k, v in self.__dict__.items() ])) @@ -556,7 +558,7 @@ class OneM2MResponse(object): def __str__(self): return '%s: %s' % (self.__class__.__name__, ' | '.join([ - '%s: %s' % (str(k), str(v)) for k, v in self.__dict__.iteritems() + '%s: %s' % (str(k), str(v)) for k, v in self.__dict__.items() ])) diff --git a/common/openmtc/lib/aplus/__init__.py b/common/openmtc/lib/aplus/__init__.py index 01a2ba8..2f17aab 100644 --- a/common/openmtc/lib/aplus/__init__.py +++ b/common/openmtc/lib/aplus/__init__.py @@ -1,3 +1,4 @@ +import platform import sys from logging import DEBUG from threading import Thread @@ -6,8 +7,8 @@ from traceback import print_stack from futile.logging import LoggerMixin from openmtc.exc import OpenMTCError -if sys.subversion[0] != "CPython": - from inspect import ismethod, getargspec +if platform.python_implementation != "CPython": + from inspect import ismethod, getfullargspec # TODO: kca: can't pass in values for then/error currently @@ -160,11 +161,11 @@ class Promise(LoggerMixin): """ self._errbacks.append(f) - if sys.subversion[0] != "CPython": + if platform.python_implementation != "CPython": def _invoke(self, func, value): try: if value is None: - args, _, _, _ = getargspec(func) + args = getfullargspec(func).args arglen = len(args) if not arglen or (arglen == 1 and ismethod(func)): return func() @@ -181,11 +182,11 @@ class Promise(LoggerMixin): try: if value is None: try: - target = func.im_func + target = func.__func__ except AttributeError: - argcount = func.func_code.co_argcount + argcount = func.__code__.co_argcount else: - argcount = target.func_code.co_argcount - 1 + argcount = target.__code__.co_argcount - 1 if argcount == 0: return func() @@ -365,7 +366,7 @@ def listPromise(*args): if not arg.isFulfilled(): return - value = map(lambda p: p.value, args) + value = [p.value for p in args] ret._fulfill(value) for arg in args: diff --git a/common/openmtc/src/openmtc/configuration.py b/common/openmtc/src/openmtc/configuration.py index d2a768f..78f2052 100644 --- a/common/openmtc/src/openmtc/configuration.py +++ b/common/openmtc/src/openmtc/configuration.py @@ -31,9 +31,7 @@ class ExtraOptionsStrategy(Enum): fatal = "fatal" -class ConfigurationOption(LoggerMixin): - __metaclass__ = ABCMeta - +class ConfigurationOption(LoggerMixin, metaclass=ABCMeta): def __init__(self, type, default=NOT_SET, converter=identity, *args, **kw): super(ConfigurationOption, self).__init__(*args, **kw) @@ -76,7 +74,7 @@ class ListOption(SimpleOption): def _convert(self, v): v = super(ListOption, self)._convert(v) - return map(self._convert_content, v) + return list(map(self._convert_content, v)) def _convert_content(self, v): if not isinstance(v, self.content_type): @@ -92,7 +90,7 @@ class BooleanOption(ConfigurationOption): def _convert(self, v): if isinstance(v, (bool, int)): return bool(v) - if isinstance(v, basestring): + if isinstance(v, str): return v and v.lower() not in ("0", "no", "n", "f", "false") raise ConfigurationValueError("Illegal value for boolean: %s" % (v, )) diff --git a/common/openmtc/src/openmtc/model/__init__.py b/common/openmtc/src/openmtc/model/__init__.py index 0a55181..e65c554 100644 --- a/common/openmtc/src/openmtc/model/__init__.py +++ b/common/openmtc/src/openmtc/model/__init__.py @@ -5,7 +5,7 @@ from enum import Enum from iso8601 import parse_date, ParseError from operator import attrgetter -from futile import basestring, issubclass, NOT_SET +from futile import issubclass, NOT_SET from futile.logging import LoggerMixin from openmtc.model.exc import ModelError, ModelTypeError @@ -26,7 +26,7 @@ class Collection(Sequence, Mapping): def __getitem__(self, index): if isinstance(index, (int, slice)): - return self._map.values()[index] + return list(self._map.values())[index] return self._map[index] def __contains__(self, v): @@ -47,7 +47,7 @@ class Collection(Sequence, Mapping): return self._map.get(k, default) def __iter__(self): - return self._map.itervalues() + return iter(self._map.values()) def __len__(self): return len(self._map) @@ -76,7 +76,7 @@ class Collection(Sequence, Mapping): class Member(LoggerMixin): - def __init__(self, type=unicode, version="1.0", *args, **kw): + def __init__(self, type=str, version="1.0", *args, **kw): super(Member, self).__init__(*args, **kw) self.type = type self.version = version @@ -109,7 +109,7 @@ class Attribute(Member): RO = "RO" WO = "WO" - def __init__(self, type=unicode, default=None, + def __init__(self, type=str, default=None, accesstype=None, mandatory=None, update_mandatory=None, id_attribute=None, path_attribute=None, @@ -157,24 +157,22 @@ class Attribute(Member): return self.default -try: - unicode +class BytesAttribute(Attribute): + def __init__(self, default=None, accesstype=None, + mandatory=None, *args, **kw): + super(BytesAttribute, self).__init__(type=bytes, + default=default, + accesstype=accesstype, + mandatory=mandatory, *args, + **kw) - class UnicodeAttribute(Attribute): - def __init__(self, default=None, accesstype=None, - mandatory=False, *args, **kw): - super(UnicodeAttribute, self).__init__(type=unicode, - default=default, - accesstype=accesstype, - mandatory=mandatory, *args, - **kw) + def convert(self, value, instance): + if isinstance(value, str): + return bytes(value, "utf-8") + return super(BytesAttribute, self).convert(value, instance) - def convert(self, value, instance): - if isinstance(value, str): - return value.decode("utf-8") - return super(UnicodeAttribute, self).convert(value, instance) -except NameError: - UnicodeAttribute = Attribute + +UnicodeAttribute = Attribute class DatetimeAttribute(Attribute): @@ -187,7 +185,7 @@ class DatetimeAttribute(Attribute): **kw) def convert(self, value, instance): - if isinstance(value, basestring): + if isinstance(value, str): try: return parse_date(value) except ParseError as e: @@ -196,7 +194,7 @@ class DatetimeAttribute(Attribute): class ListAttribute(Attribute): - def __init__(self, content_type=unicode, type=list, + def __init__(self, content_type=str, type=list, default=NOT_SET, *args, **kw): super(ListAttribute, self).__init__(type=type, default=default, *args, **kw) @@ -239,7 +237,7 @@ class ListAttribute(Attribute): class StringListAttribute(Attribute): - def __init__(self, content_type=unicode, type=list, + def __init__(self, content_type=str, type=list, default=NOT_SET, *args, **kw): super(StringListAttribute, self).__init__(type=type, default=default, *args, **kw) @@ -427,24 +425,22 @@ class ResourceType(ABCMeta): # TODO: caching @property def attribute_names(self): - return map(attrgetter("name"), self.attributes) + return list(map(attrgetter("name"), self.attributes)) @property def collection_names(self): - return map(attrgetter("name"), self.collections) + return list(map(attrgetter("name"), self.collections)) @property def subresource_names(self): - return map(attrgetter("name"), self.subresources) + return list(map(attrgetter("name"), self.subresources)) @property def member_names(self): - return map(attrgetter("name"), self.__members__) + return list(map(attrgetter("name"), self.__members__)) -class Entity(LoggerMixin): - __metaclass__ = ResourceType - +class Entity(LoggerMixin, metaclass=ResourceType): def __init__(self, *args, **kw): self.set_values(kw) @@ -467,7 +463,7 @@ class Entity(LoggerMixin): # TODO: proper solution? if (v is not None and isinstance(member, ListAttribute) and not isinstance(v, (list, tuple, set))): - v = v.values()[0] + v = list(v.values())[0] setattr(self, member.name, v) except KeyError: pass @@ -487,7 +483,7 @@ class Entity(LoggerMixin): """ if values: raise ModelTypeError("%s resource has no attribute %s" % - (self.typename, values.keys()[0])) + (self.typename, list(values.keys())[0])) @classmethod def get_typename(cls): @@ -569,7 +565,7 @@ class Resource(Entity): __model_version__ = None def __init__(self, path=None, parent=None, *args, **kw): - if path is not None and not isinstance(path, basestring): + if path is not None and not isinstance(path, str): raise TypeError(path) self.__path = path self.parent = parent @@ -629,7 +625,7 @@ class Resource(Entity): # FIXME: move into de-serializer and handle dicts if (v is not None and isinstance(member, ListAttribute) and not isinstance(v, (list, tuple, set))): - v = v.values()[0] + v = list(v.values())[0] setattr(self, member.name, v) except KeyError: try: @@ -637,7 +633,7 @@ class Resource(Entity): # TODO: proper solution? if (v is not None and isinstance(member, ListAttribute) and not isinstance(v, (list, tuple, set))): - v = v.values()[0] + v = list(v.values())[0] setattr(self, member.name, v) except KeyError: pass diff --git a/create-app-structure b/create-app-structure index afeb834..c358681 100755 --- a/create-app-structure +++ b/create-app-structure @@ -289,7 +289,7 @@ cd \$(dirname \${0}) cd ${APP_NAME} -PYTHONPATH=\${PYTHONPATH}:src exec python -m ${PKG_NAME} \$@ +PYTHONPATH=\${PYTHONPATH}:src exec python3 -m ${PKG_NAME} \$@ EOF chmod +x "${START_SCRIPT}" @@ -301,7 +301,7 @@ BIN_SCRIPT="${APP_FOLDER}/bin/openmtc-${APP_SCRIPT}" cat > "${BIN_SCRIPT}" << EOF #!/usr/bin/env bash -exec python -m ${PKG_NAME} \$@ +exec python3 -m ${PKG_NAME} \$@ EOF chmod +x "${BIN_SCRIPT}" @@ -333,7 +333,7 @@ fi # create setup file SETUP_FILE="${APP_FOLDER}/setup-${PKG_NAME}.py" cat > "${SETUP_FILE}" << EOF -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup from distutils.core import setup @@ -489,7 +489,7 @@ mv \${CONFIG_TEMP} \${CONFIG_FILE} echo "done" -exec python -m ${PKG_NAME} \$@ +exec python3 -m ${PKG_NAME} \$@ EOF if [ ${WEB_APP} == "false" ]; then diff --git a/create-binary-dist b/create-binary-dist index 87f4ff2..853c451 100755 --- a/create-binary-dist +++ b/create-binary-dist @@ -47,7 +47,7 @@ if [ ${#find_result[*]} -eq 0 ]; then fi if [ ${#find_result[*]} -gt 1 ]; then - echo "Too many setup files matching the name. Exiting Now!." + echo "Too many setup files matching the name. Exiting Now!. " exit 1 fi @@ -68,7 +68,7 @@ get_target_from_setup_file () local module_name=${setup_file%.py} cd ${working_dir} -python - << END_OF_PYTHON +python3 - << END_OF_PYTHON from importlib import import_module setup = import_module('${module_name}', '${module_name}') print("%s-%s" % (setup.SETUP_NAME, setup.SETUP_VERSION)) @@ -92,7 +92,7 @@ rm -rf ${working_dir}/build # build cd ${working_dir} -python ${setup_file} bdist --plat-name docker >/dev/null 2>${log_file} +python3 ${setup_file} bdist --plat-name docker >/dev/null 2>${log_file} # clean up after rm -rf ${working_dir}/build @@ -113,14 +113,14 @@ rm ${log_file} ################################################################################ # clean binary_package binary_archive="${working_dir}/dist/${binary_prefix}.docker.tar.gz" -printf "### Stripping .py files..." +#printf "### Stripping .py files..." cp ${target_file} ${binary_archive} -gzip -d ${binary_archive} -tar --wildcards --delete -f ${binary_archive%".gz"} "*.py" -gzip ${binary_archive%".gz"} -printf "done\n" +#gzip -d ${binary_archive} +#tar --wildcards --delete -f ${binary_archive%".gz"} "*.py" +#gzip ${binary_archive%".gz"} +#printf "done\n" rm ${target_file} -printf "### Created binary archive at %s.\n" ${binary_archive} +#printf "### Created binary archive at %s.\n" ${binary_archive} ################################################################################ # set correct permissions diff --git a/doc/example-apps/IoT-data-visualization.py b/doc/example-apps/IoT-data-visualization.py index caa0acb..b6d95e2 100644 --- a/doc/example-apps/IoT-data-visualization.py +++ b/doc/example-apps/IoT-data-visualization.py @@ -1,5 +1,7 @@ -import urllib +import urllib.request +import urllib.parse +import urllib.error from openmtc_app.onem2m import XAE import uuid @@ -15,9 +17,9 @@ class DataVisualization(XAE): self.sensor_register = [] self.sensor_values = [] self.name = uuid.uuid1() - self.things_name = urllib.urlopen("https://dweet.io/follow/%s" % self.name) - print "Thing name :", self.name - print "link for the current data type and values :", self.things_name.geturl() + self.things_name = urllib.request.urlopen("https://dweet.io/follow/%s" % self.name) + print("Thing name :", self.name) + print("link for the current data type and values :", self.things_name.geturl()) # start endless loop self.periodic_discover(self.remote_cse, {'labels': ["openmtc:sensor_data"]}, @@ -28,13 +30,13 @@ class DataVisualization(XAE): self.add_container_subscription(uri, self.handle_sensor_data) def handle_sensor_data(self, container, content): - data ={} + data = {} self.sensor_register.append(content[0]['n']) self.sensor_values.append(content[0]['v']) - for i, k in zip(self.sensor_register , self.sensor_values): + for i, k in zip(self.sensor_register, self.sensor_values): data.update({i: k}) - params = urllib.urlencode(data) - urllib.urlopen("https://dweet.io/dweet/for/%s?%s" % (self.name, params)) + params = urllib.parse.urlencode(data) + urllib.request.urlopen("https://dweet.io/dweet/for/%s?%s" % (self.name, params)) if __name__ == "__main__": diff --git a/doc/training/onem2m-examples/onem2m-example-1.py b/doc/training/onem2m-examples/onem2m-example-1.py index a94ff09..1bf844b 100644 --- a/doc/training/onem2m-examples/onem2m-example-1.py +++ b/doc/training/onem2m-examples/onem2m-example-1.py @@ -4,13 +4,13 @@ from openmtc_onem2m.model import AE my_app = AE() -print my_app.path +print(my_app.path) #>>> None -print my_app.App_ID +print(my_app.App_ID) #>>> None -print my_app.parent_path +print(my_app.parent_path) #>>> None -print my_app.labels +print(my_app.labels) #>>> None -print my_app.attributes +print(my_app.attributes) #>>> [UnicodeAttribute(name="AE-ID", type=unicode), UnicodeAttribute(name="App-ID", type=unicode), ListAttribute(name="accessControlPolicyIDs", type=list), ListAttribute(name="announceTo", type=list), UnicodeAttribute(name="announcedAttribute", type=unicode), ListAttribute(name="childResources", type=list), DatetimeAttribute(name="creationTime", type=datetime), DatetimeAttribute(name="expirationTime", type=datetime), UnicodeAttribute(name="labels", type=unicode), DatetimeAttribute(name="lastModifiedTime", type=datetime), UnicodeAttribute(name="name", type=unicode), UnicodeAttribute(name="nodeLink", type=unicode), UnicodeAttribute(name="ontologyRef", type=unicode), ListAttribute(name="pointOfAccess", type=list)] diff --git a/doc/training/onem2m-examples/onem2m-example-10.py b/doc/training/onem2m-examples/onem2m-example-10.py index 3edc1e8..144101a 100644 --- a/doc/training/onem2m-examples/onem2m-example-10.py +++ b/doc/training/onem2m-examples/onem2m-example-10.py @@ -26,13 +26,13 @@ promise = client.send_onem2m_request(onem2m_request) # reteive the OneM2MResponse from the returned promise onem2m_response = promise.get() -print onem2m_response.to +print(onem2m_response.to) #>>> onem2m -print onem2m_response.response_status_code +print(onem2m_response.response_status_code) #>>> STATUS(numeric_code=2001, description='CREATED', http_status_code=201) -print onem2m_response.content +print(onem2m_response.content) #>>> AE(path='None', id='ae0') -print onem2m_response.content.App_ID +print(onem2m_response.content.App_ID) #>>> myApp -print onem2m_response.content.labels +print(onem2m_response.content.labels) #>>> [u'keyword1', u'keyword2'] diff --git a/doc/training/onem2m-examples/onem2m-example-11a.py b/doc/training/onem2m-examples/onem2m-example-11a.py index 2ab6c25..b56840b 100644 --- a/doc/training/onem2m-examples/onem2m-example-11a.py +++ b/doc/training/onem2m-examples/onem2m-example-11a.py @@ -17,12 +17,12 @@ promise = client.send_onem2m_request(onem2m_request) onem2m_response = promise.get() -print onem2m_response.response_status_code +print(onem2m_response.response_status_code) #>>> STATUS(numeric_code=2001, description='CREATED', http_status_code=201) # Build path to retieve from path = "onem2m/" + onem2m_response.content.resourceName -print path +print(path) #>>> onem2m/MYAPP # Retrieve the AE from the CSE @@ -30,18 +30,18 @@ onem2m_request = OneM2MRequest("retrieve", to=path) promise = client.send_onem2m_request(onem2m_request) onem2m_response = promise.get() -print onem2m_response.response_status_code +print(onem2m_response.response_status_code) #>>> STATUS(numeric_code=2000, description='OK', http_status_code=200) -print onem2m_response.content +print(onem2m_response.content) #>>> AE(path='None', id='ae0') # Set the local AE to the retrieved content my_app = None my_app = onem2m_response.content -print my_app.App_ID +print(my_app.App_ID) #>>> myApp -print my_app.resourceName +print(my_app.resourceName) #>>> MYAPP -print my_app.labels +print(my_app.labels) #>>> [u'keyword1', u'keyword2'] diff --git a/doc/training/onem2m-examples/onem2m-example-11b.py b/doc/training/onem2m-examples/onem2m-example-11b.py index 2fabb8a..e428116 100644 --- a/doc/training/onem2m-examples/onem2m-example-11b.py +++ b/doc/training/onem2m-examples/onem2m-example-11b.py @@ -15,7 +15,7 @@ my_app = AE(App_ID="myApp", onem2m_request = OneM2MRequest("create", to="onem2m", ty=AE, pc=my_app) promise = client.send_onem2m_request(onem2m_request) onem2m_response = promise.get() -print onem2m_response.content.labels +print(onem2m_response.content.labels) #>>> [u'keyword1', u'keyword2'] # Retrieve the AE from the CSE and check the labels @@ -23,7 +23,7 @@ path = "onem2m/" + onem2m_response.content.resourceName onem2m_request = OneM2MRequest("retrieve", to=path) promise = client.send_onem2m_request(onem2m_request) onem2m_response = promise.get() -print onem2m_response.content.labels +print(onem2m_response.content.labels) #>>> [u'keyword1', u'keyword2'] # Update the changes labels in the remote resource @@ -33,11 +33,11 @@ tmp_app = AE(labels=["foo", "bar", "coffee"]) onem2m_request = OneM2MRequest("update", to=path, pc=tmp_app) promise = client.send_onem2m_request(onem2m_request) onem2m_response = promise.get() -print onem2m_response.content.labels +print(onem2m_response.content.labels) #>>> [u'foo', u'bar', u'coffee'] # Set the local AE to the retrieved content my_app = None my_app = onem2m_response.content -print my_app.labels +print(my_app.labels) #>>> [u'foo', u'bar', u'coffee'] diff --git a/doc/training/onem2m-examples/onem2m-example-12a.py b/doc/training/onem2m-examples/onem2m-example-12a.py index 6cf6cc3..5914468 100644 --- a/doc/training/onem2m-examples/onem2m-example-12a.py +++ b/doc/training/onem2m-examples/onem2m-example-12a.py @@ -11,18 +11,18 @@ try: promise = client.send_onem2m_request(onem2m_request) onem2m_response = promise.get() except OneM2MErrorResponse as e: - print "CSE reported an error:", e + print("CSE reported an error:", e) raise except OpenMTCError as e: - print "Failed to reach the CSE:", e + print("Failed to reach the CSE:", e) raise else: pass # no exception was raised, the method returned normally. -print onem2m_response.to +print(onem2m_response.to) #>>> onem2m -print onem2m_response.response_status_code +print(onem2m_response.response_status_code) #>>> STATUS(numeric_code=2000, description='OK', http_status_code=200) -print onem2m_response.content +print(onem2m_response.content) #>>> CSEBase(path='None', id='cb0') diff --git a/doc/training/onem2m-examples/onem2m-example-12b.py b/doc/training/onem2m-examples/onem2m-example-12b.py index 7d4f625..12e5c45 100644 --- a/doc/training/onem2m-examples/onem2m-example-12b.py +++ b/doc/training/onem2m-examples/onem2m-example-12b.py @@ -7,31 +7,31 @@ client = OneM2MHTTPClient("http://localhost:8000", False) onem2m_request = OneM2MRequest("retrieve", to="onem2m") onem2m_response = client.send_onem2m_request(onem2m_request).get() -print "---> Request to: http://localhost:8000" + "/" + onem2m_request.to -print onem2m_response.to +print("---> Request to: http://localhost:8000" + "/" + onem2m_request.to) +print(onem2m_response.to) #>>> onem2m -print onem2m_response.response_status_code +print(onem2m_response.response_status_code) #>>> STATUS(numeric_code=2000, description='OK', http_status_code=200) -print onem2m_response.content +print(onem2m_response.content) #>>> CSEBase(path='None', id='cb0') onem2m_request = OneM2MRequest("retrieve", to="~/mn-cse-1/onem2m") onem2m_response = client.send_onem2m_request(onem2m_request).get() -print "---> Request to: http://localhost:8000" + "/" + onem2m_request.to -print onem2m_response.to +print("---> Request to: http://localhost:8000" + "/" + onem2m_request.to) +print(onem2m_response.to) #>>> ~/mn-cse-1/onem2m -print onem2m_response.response_status_code +print(onem2m_response.response_status_code) #>>> STATUS(numeric_code=2000, description='OK', http_status_code=200) -print onem2m_response.content +print(onem2m_response.content) #>>> CSEBase(path='None', id='cb0') client.port = 18000 onem2m_request = OneM2MRequest("retrieve", to="~/mn-cse-1/onem2m") onem2m_response = client.send_onem2m_request(onem2m_request).get() -print "---> Request to: http://localhost:18000" + "/" + onem2m_request.to -print onem2m_response.to +print("---> Request to: http://localhost:18000" + "/" + onem2m_request.to) +print(onem2m_response.to) #>>> ~/mn-cse-1/onem2m -print onem2m_response.response_status_code +print(onem2m_response.response_status_code) #>>> STATUS(numeric_code=2000, description='OK', http_status_code=200) -print onem2m_response.content +print(onem2m_response.content) #>>> CSEBase(path='None', id='cb0') diff --git a/doc/training/onem2m-examples/onem2m-example-2.py b/doc/training/onem2m-examples/onem2m-example-2.py index 11b633a..5979fc3 100644 --- a/doc/training/onem2m-examples/onem2m-example-2.py +++ b/doc/training/onem2m-examples/onem2m-example-2.py @@ -4,13 +4,13 @@ from openmtc_onem2m.model import AE my_app = AE(App_ID="myApp", labels=["keyword1", "keyword2"]) -print my_app.path +print(my_app.path) #>>> None -print my_app.App_ID +print(my_app.App_ID) #>>> myApp -print my_app.parent_path +print(my_app.parent_path) #>>> None -print my_app.labels +print(my_app.labels) #>>> [u'keyword1', u'keyword2'] -print my_app.attributes +print(my_app.attributes) #>>> [UnicodeAttribute(name="AE-ID", type=unicode), UnicodeAttribute(name="App-ID", type=unicode), ListAttribute(name="accessControlPolicyIDs", type=list), ListAttribute(name="announceTo", type=list), UnicodeAttribute(name="announcedAttribute", type=unicode), ListAttribute(name="childResources", type=list), DatetimeAttribute(name="creationTime", type=datetime), DatetimeAttribute(name="expirationTime", type=datetime), UnicodeAttribute(name="labels", type=unicode), DatetimeAttribute(name="lastModifiedTime", type=datetime), UnicodeAttribute(name="name", type=unicode), UnicodeAttribute(name="nodeLink", type=unicode), UnicodeAttribute(name="ontologyRef", type=unicode), ListAttribute(name="pointOfAccess", type=list)] diff --git a/doc/training/onem2m-examples/onem2m-example-3.py b/doc/training/onem2m-examples/onem2m-example-3.py index f4ac0e8..0269be0 100644 --- a/doc/training/onem2m-examples/onem2m-example-3.py +++ b/doc/training/onem2m-examples/onem2m-example-3.py @@ -4,5 +4,5 @@ from openmtc_onem2m.transport import OneM2MRequest request = OneM2MRequest("retrieve", to="onem2m") -print request.to +print(request.to) #>>> onem2m diff --git a/doc/training/onem2m-examples/onem2m-example-4.py b/doc/training/onem2m-examples/onem2m-example-4.py index 526f928..1386f97 100644 --- a/doc/training/onem2m-examples/onem2m-example-4.py +++ b/doc/training/onem2m-examples/onem2m-example-4.py @@ -4,5 +4,5 @@ from openmtc_onem2m.transport import OneM2MRequest request = OneM2MRequest("delete", to="onem2m") -print request.to +print(request.to) #>>> onem2m diff --git a/doc/training/onem2m-examples/onem2m-example-5a.py b/doc/training/onem2m-examples/onem2m-example-5a.py index f16338b..ca9f90e 100644 --- a/doc/training/onem2m-examples/onem2m-example-5a.py +++ b/doc/training/onem2m-examples/onem2m-example-5a.py @@ -7,7 +7,7 @@ my_app = AE(App_ID="myApp") request = OneM2MRequest("create", to="onem2m", pc="my_app") -print request.to +print(request.to) #>>> onem2m -print request.pc +print(request.pc) #>>> myApp diff --git a/doc/training/onem2m-examples/onem2m-example-5b.py b/doc/training/onem2m-examples/onem2m-example-5b.py index 2878d73..c6fe3e7 100644 --- a/doc/training/onem2m-examples/onem2m-example-5b.py +++ b/doc/training/onem2m-examples/onem2m-example-5b.py @@ -13,7 +13,7 @@ request = OneM2MRequest("create", pc=data_string, ty="application/json") -print request.to +print(request.to) #>>> onem2m -print request.pc +print(request.pc) #>>> {"type": "temperature", "value": 15} diff --git a/doc/training/onem2m-examples/onem2m-example-6a.py b/doc/training/onem2m-examples/onem2m-example-6a.py index 82e47af..db26331 100644 --- a/doc/training/onem2m-examples/onem2m-example-6a.py +++ b/doc/training/onem2m-examples/onem2m-example-6a.py @@ -7,7 +7,7 @@ my_app = AE(App_ID="myApp") request = OneM2MRequest("notify", to="onem2m", pc=my_app) -print request.to +print(request.to) #>>> onem2m -print request.pc.App_ID +print(request.pc.App_ID) #>>> myApp diff --git a/doc/training/onem2m-examples/onem2m-example-6b.py b/doc/training/onem2m-examples/onem2m-example-6b.py index f50a47c..50209f7 100644 --- a/doc/training/onem2m-examples/onem2m-example-6b.py +++ b/doc/training/onem2m-examples/onem2m-example-6b.py @@ -13,7 +13,7 @@ request = OneM2MRequest("create", pc=data_string, ty="application/json") -print request.to +print(request.to) #>>> onem2m -print request.pc +print(request.pc) #>>> {"type": "temperature", "value": 15} diff --git a/doc/training/onem2m-examples/onem2m-example-7.py b/doc/training/onem2m-examples/onem2m-example-7.py index 72b0b86..c26c45d 100644 --- a/doc/training/onem2m-examples/onem2m-example-7.py +++ b/doc/training/onem2m-examples/onem2m-example-7.py @@ -7,7 +7,7 @@ my_app = AE(App_ID="myApp", labels=["keyword1", "keyword2"]) request = OneM2MRequest("update", to="onem2m", pc=my_app.labels) -print request.to +print(request.to) #>>> onem2m -print request.pc +print(request.pc) #>>> [u'keyword1', u'keyword2'] diff --git a/doc/training/onem2m-examples/onem2m-example-8b.py b/doc/training/onem2m-examples/onem2m-example-8b.py index 3c37731..3777b72 100644 --- a/doc/training/onem2m-examples/onem2m-example-8b.py +++ b/doc/training/onem2m-examples/onem2m-example-8b.py @@ -13,9 +13,9 @@ promise = client.send_onem2m_request(onem2m_request) # reteive the OneM2MResponse from the returned promise onem2m_response = promise.get() -print onem2m_response.to +print(onem2m_response.to) #>>> onem2m -print onem2m_response.response_status_code +print(onem2m_response.response_status_code) #>>> STATUS(numeric_code=2000, description='OK', http_status_code=200) -print onem2m_response.content +print(onem2m_response.content) #>>> CSEBase(path='None', id='cb0') diff --git a/doc/training/start-app.sh b/doc/training/start-app.sh index b06c332..9e6b6da 100755 --- a/doc/training/start-app.sh +++ b/doc/training/start-app.sh @@ -34,4 +34,4 @@ cd ${base_path} cd .. . ../common/prep-env.sh cd ${base_path} -python ${app_file} +python3 ${app_file} diff --git a/docker/backend-amd64 b/docker/backend-amd64 index c52da10..d4085d2 100644 --- a/docker/backend-amd64 +++ b/docker/backend-amd64 @@ -12,7 +12,7 @@ MAINTAINER rst/tgu # install openmtc dependencies COPY tmp/$MOD_NAME-dependencies.txt /tmp/requirements.txt -RUN pip install --upgrade --requirement /tmp/requirements.txt +RUN pip3 install --upgrade --requirement /tmp/requirements.txt # install openmtc-all COPY tmp/openmtc-$MOD_NAME.tar.gz /tmp/openmtc-$MOD_NAME.tar.gz diff --git a/docker/backend-arm b/docker/backend-arm index 0c0a905..620ad2b 100644 --- a/docker/backend-arm +++ b/docker/backend-arm @@ -12,7 +12,7 @@ MAINTAINER rst/tgu # install openmtc dependencies COPY tmp/$MOD_NAME-dependencies.txt /tmp/requirements.txt -RUN pip install --upgrade --requirement /tmp/requirements.txt +RUN pip3 install --upgrade --requirement /tmp/requirements.txt # install openmtc-all COPY tmp/openmtc-$MOD_NAME.tar.gz /tmp/openmtc-$MOD_NAME.tar.gz diff --git a/docker/base-amd64 b/docker/base-amd64 index a1637b0..e88bbee 100644 --- a/docker/base-amd64 +++ b/docker/base-amd64 @@ -3,7 +3,7 @@ ############################################################ # Set the base image to use debian -FROM debian:jessie +FROM debian:stretch # Set the file maintainer MAINTAINER rst/tgu @@ -20,8 +20,9 @@ RUN printf "Starting update...\n" && \ build-essential \ netbase \ iproute2 \ - python-pip \ - python-dev \ + python3-setuptools \ + python3-pip \ + python3-dev \ jq > /dev/null && \ apt-get clean && \ printf "Installation and cleanup finished.\n" diff --git a/docker/base-arm b/docker/base-arm index b2d49e4..764e31b 100644 --- a/docker/base-arm +++ b/docker/base-arm @@ -3,7 +3,7 @@ ############################################################ # Set the base image to use debian -FROM resin/rpi-raspbian:jessie +FROM resin/rpi-raspbian:stretch # Set the file maintainer MAINTAINER rst/tgu @@ -20,8 +20,9 @@ RUN printf "Starting update...\n" && \ build-essential \ netbase \ iproute2 \ - python-pip \ - python-dev \ + python3-setuptools \ + python3-pip \ + python3-dev \ jq > /dev/null && \ apt-get clean && \ printf "Installation and cleanup finished.\n" diff --git a/docker/configure-backend-and-start b/docker/configure-backend-and-start index 01c2fe6..acf4973 100755 --- a/docker/configure-backend-and-start +++ b/docker/configure-backend-and-start @@ -89,4 +89,4 @@ mv ${CONFIG_TEMP} ${CONFIG_FILE} echo "done" -exec python -m openmtc_gevent.backend_main $@ +exec python3 -m openmtc_gevent.backend_main $@ diff --git a/docker/configure-gateway-and-start b/docker/configure-gateway-and-start index 1afb7fc..5648e66 100755 --- a/docker/configure-gateway-and-start +++ b/docker/configure-gateway-and-start @@ -101,4 +101,4 @@ mv ${CONFIG_TEMP} ${CONFIG_FILE} echo "done" -exec python -m openmtc_gevent.gateway_main $@ +exec python3 -m openmtc_gevent.gateway_main $@ diff --git a/docker/gateway-amd64 b/docker/gateway-amd64 index f1f8044..e53810a 100644 --- a/docker/gateway-amd64 +++ b/docker/gateway-amd64 @@ -12,7 +12,7 @@ MAINTAINER rst/tgu # install openmtc dependencies COPY tmp/$MOD_NAME-dependencies.txt /tmp/requirements.txt -RUN pip install --upgrade --requirement /tmp/requirements.txt +RUN pip3 install --upgrade --requirement /tmp/requirements.txt # install openmtc-all COPY tmp/openmtc-$MOD_NAME.tar.gz /tmp/openmtc-$MOD_NAME.tar.gz diff --git a/docker/gateway-arm b/docker/gateway-arm index 9a7495b..5041d73 100644 --- a/docker/gateway-arm +++ b/docker/gateway-arm @@ -12,7 +12,7 @@ MAINTAINER rst/tgu # install openmtc dependencies COPY tmp/$MOD_NAME-dependencies.txt /tmp/requirements.txt -RUN pip install --upgrade --requirement /tmp/requirements.txt +RUN pip3 install --upgrade --requirement /tmp/requirements.txt # install openmtc-all COPY tmp/openmtc-$MOD_NAME.tar.gz /tmp/openmtc-$MOD_NAME.tar.gz diff --git a/docker/sdk-amd64 b/docker/sdk-amd64 index 238254d..a5a8f0a 100644 --- a/docker/sdk-amd64 +++ b/docker/sdk-amd64 @@ -11,11 +11,11 @@ ENV MOD_NAME=sdk MAINTAINER rst/tgu # update pip to latest version -RUN pip install --upgrade pip +RUN pip3 install --upgrade pip # install openmtc dependencies COPY tmp/$MOD_NAME-dependencies.txt /tmp/requirements.txt -RUN pip install --upgrade --requirement /tmp/requirements.txt +RUN pip3 install --upgrade --requirement /tmp/requirements.txt # install openmtc-sdk COPY tmp/openmtc-$MOD_NAME.tar.gz /tmp/openmtc-$MOD_NAME.tar.gz diff --git a/docker/sdk-arm b/docker/sdk-arm index c5fc42f..19ad23d 100644 --- a/docker/sdk-arm +++ b/docker/sdk-arm @@ -11,11 +11,11 @@ ENV MOD_NAME=sdk MAINTAINER rst/tgu # update pip to latest version -RUN pip install --upgrade pip setuptools +RUN pip3 install --upgrade pip setuptools # install openmtc dependencies COPY tmp/$MOD_NAME-dependencies.txt /tmp/requirements.txt -RUN pip install --upgrade --requirement /tmp/requirements.txt +RUN pip3 install --upgrade --requirement /tmp/requirements.txt # install openmtc-sdk COPY tmp/openmtc-$MOD_NAME.tar.gz /tmp/openmtc-$MOD_NAME.tar.gz diff --git a/futile/src/futile/collections/OrderedSet.py b/futile/src/futile/collections/OrderedSet.py index 5de43a7..9089d0f 100644 --- a/futile/src/futile/collections/OrderedSet.py +++ b/futile/src/futile/collections/OrderedSet.py @@ -103,7 +103,7 @@ if __name__ == '__main__': ## end of http://code.activestate.com/recipes/576694/ }}} ## kca: - print OrderedSet('simsalabim')[1] + print(OrderedSet('simsalabim')[1]) # Test case for exception at shutdown (yes, really...) x = OrderedSet('simsalabim') diff --git a/futile/src/futile/net/PortTester.py b/futile/src/futile/net/PortTester.py index 56290cc..0819b4b 100644 --- a/futile/src/futile/net/PortTester.py +++ b/futile/src/futile/net/PortTester.py @@ -6,7 +6,7 @@ Created on 15.07.2011 from asyncore import dispatcher, loop from socket import AF_INET, SOCK_STREAM, error -from sockethelper import socket +from .sockethelper import socket from futile.exc import errorstr from collections import namedtuple import sys @@ -38,9 +38,9 @@ def test_port(host, port, family = AF_INET, type = SOCK_STREAM): try: with socket(family, type) as s: s.connect((host, port)) - except error, e: + except error as e: return TestResult(False, "%s (%d)" % (e.strerror, e.errno)) - except Exception, e: + except Exception as e: return TestResult(False, errorstr(e)) return TestResult(True) diff --git a/futile/src/futile/net/http/client/RestClientAsync.py b/futile/src/futile/net/http/client/RestClientAsync.py index 8e9a491..8dc4d10 100644 --- a/futile/src/futile/net/http/client/RestClientAsync.py +++ b/futile/src/futile/net/http/client/RestClientAsync.py @@ -285,7 +285,7 @@ class RestClient(LoggerMixin): req.end() except Exception as e: - print "Exception triggered: %s"%e + print("Exception triggered: %s"%e) promise.reject(e) return promise diff --git a/futile/src/futile/net/http/server/ssl/__init__.py b/futile/src/futile/net/http/server/ssl/__init__.py index 3a11e0c..28e4b3c 100644 --- a/futile/src/futile/net/http/server/ssl/__init__.py +++ b/futile/src/futile/net/http/server/ssl/__init__.py @@ -39,7 +39,7 @@ class HTTPSMixin(LoggerMixin): def get_request(self): try: return self.socket.accept() - except error, e: + except error as e: self.logger.exception("Error during accept(): %s", e) raise diff --git a/futile/src/futile/path/__init__.py b/futile/src/futile/path/__init__.py index c193650..453a1e8 100644 --- a/futile/src/futile/path/__init__.py +++ b/futile/src/futile/path/__init__.py @@ -30,10 +30,10 @@ Date: 7 Mar 2004 # it doesn't play nice with other types that implement # __radd__(). Test this. -from __future__ import generators + def quote(p): - from urllib2 import quote + from urllib.parse import quote return quote(p, "") @@ -46,15 +46,15 @@ __all__ = ['path'] _base = str try: if os.path.supports_unicode_filenames: - _base = unicode + _base = str except AttributeError: pass # Pre-2.3 workaround for basestring. try: - basestring + str except NameError: - basestring = (str, unicode) + str = (str, str) # Universal newline support _textmode = 'r' @@ -403,7 +403,7 @@ class path(_base): For example, path('/users').glob('*/bin/*') returns a list of all the files users have in their bin directories. """ - return map(path, glob.glob(_base(self / pattern))) + return list(map(path, glob.glob(_base(self / pattern)))) # --- Reading or writing an entire file at once. @@ -467,11 +467,11 @@ class path(_base): t = f.read() finally: f.close() - return (t.replace(u'\r\n', u'\n') - .replace(u'\r\x85', u'\n') - .replace(u'\r', u'\n') - .replace(u'\x85', u'\n') - .replace(u'\u2028', u'\n')) + return (t.replace('\r\n', '\n') + .replace('\r\x85', '\n') + .replace('\r', '\n') + .replace('\x85', '\n') + .replace('\u2028', '\n')) def write_text(self, text, encoding=None, errors='strict', linesep=os.linesep, append=False): """ Write the given text to this file. @@ -518,7 +518,7 @@ class path(_base): This applies to Unicode text the same as to 8-bit text, except there are three additional standard Unicode end-of-line sequences: - u'\x85', u'\r\x85', and u'\u2028'. + u'\x85', u'\r\x85', and u'\\u2028'. (This is slightly different from when you open a file for writing with fopen(filename, "w") in C or file(filename, 'w') @@ -537,16 +537,16 @@ class path(_base): conversion. """ - if isinstance(text, unicode): + if isinstance(text, str): if linesep is not None: # Convert all standard end-of-line sequences to # ordinary newline characters. - text = (text.replace(u'\r\n', u'\n') - .replace(u'\r\x85', u'\n') - .replace(u'\r', u'\n') - .replace(u'\x85', u'\n') - .replace(u'\u2028', u'\n')) - text = text.replace(u'\n', linesep) + text = (text.replace('\r\n', '\n') + .replace('\r\x85', '\n') + .replace('\r', '\n') + .replace('\x85', '\n') + .replace('\u2028', '\n')) + text = text.replace('\n', linesep) if encoding is None: encoding = sys.getdefaultencoding() bytes = text.encode(encoding, errors) @@ -608,7 +608,7 @@ class path(_base): linesep - The desired line-ending. This line-ending is applied to every line. If a line already has any standard line ending ('\r', '\n', '\r\n', u'\x85', - u'\r\x85', u'\u2028'), that will be stripped off and + u'\r\x85', u'\\u2028'), that will be stripped off and this will be used instead. The default is os.linesep, which is platform-dependent ('\r\n' on Windows, '\n' on Unix, etc.) Specify None to write the lines as-is, @@ -629,15 +629,15 @@ class path(_base): f = self.open(mode) try: for line in lines: - isUnicode = isinstance(line, unicode) + isUnicode = isinstance(line, str) if linesep is not None: # Strip off any existing line-end and add the # specified linesep string. if isUnicode: - if line[-2:] in (u'\r\n', u'\x0d\x85'): + if line[-2:] in ('\r\n', '\x0d\x85'): line = line[:-2] - elif line[-1:] in (u'\r', u'\n', - u'\x85', u'\u2028'): + elif line[-1:] in ('\r', '\n', + '\x85', '\u2028'): line = line[:-1] else: if line[-2:] == '\r\n': @@ -754,10 +754,10 @@ class path(_base): os.renames(self, new) # --- Create/delete operations on directories - def mkdir(self, mode=0750): + def mkdir(self, mode=0o750): os.mkdir(self, mode) - def makedirs(self, mode=0750): + def makedirs(self, mode=0o750): os.makedirs(self, mode) def rmdir(self): @@ -769,7 +769,7 @@ class path(_base): # --- Modifying operations on files - def touch(self, mode = 0640): + def touch(self, mode = 0o640): """ Set the access/modified times of this file to the current time. Create the file if it does not exist. """ @@ -823,15 +823,15 @@ class path(_base): if not self.isfile(): raise Exception("Not a file: '%s'" % (self, )) - def forcedir(self, mode = 0750): + def forcedir(self, mode = 0o750): if not self.isdir(): if self.exists(): raise Exception("Not a directory: '%s'" % (self, )) self.makedirs(mode) - def forcefile(self, mode = 0640): + def forcefile(self, mode = 0o640): if not self.exists(): - return self.touch(mode = 0640) + return self.touch(mode = 0o640) if not self.isfile(): raise Exception("Not a file: %s" % (self ,)) diff --git a/futile/src/futile/serializer/xml.py b/futile/src/futile/serializer/xml.py index f52d672..bad700b 100644 --- a/futile/src/futile/serializer/xml.py +++ b/futile/src/futile/serializer/xml.py @@ -28,7 +28,7 @@ class AbstractXMLSerializer(LoggerMixin): return XML(input) else: return ElementTree().parse(input) - except Exception, e: + except Exception as e: self._handle_parse_error(e) raise ParseError(e) diff --git a/futile/src/futile/subprocess/daemon.py b/futile/src/futile/subprocess/daemon.py index 8d6eab3..3de9441 100644 --- a/futile/src/futile/subprocess/daemon.py +++ b/futile/src/futile/subprocess/daemon.py @@ -86,7 +86,7 @@ class CheckPIDFileController(DaemonController): try: os.kill(pid, 0) return True - except OSError, e: + except OSError as e: if e.errno == errno.ESRCH: return False raise diff --git a/futile/src/futile/threading/RWLock.py b/futile/src/futile/threading/RWLock.py index ecd483b..3febba7 100644 --- a/futile/src/futile/threading/RWLock.py +++ b/futile/src/futile/threading/RWLock.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 ''' Created on 01.04.2011 diff --git a/ipes/CUL868IPE/bin/openmtc-cul-868-ipe b/ipes/CUL868IPE/bin/openmtc-cul-868-ipe index f92e5f3..74c24b0 100755 --- a/ipes/CUL868IPE/bin/openmtc-cul-868-ipe +++ b/ipes/CUL868IPE/bin/openmtc-cul-868-ipe @@ -1,3 +1,3 @@ #!/usr/bin/env bash -exec python -m cul868ipe $@ +exec python3 -m cul868ipe $@ diff --git a/ipes/CUL868IPE/docker/configure-cul868ipe-and-start b/ipes/CUL868IPE/docker/configure-cul868ipe-and-start index c1557b0..15d19c7 100755 --- a/ipes/CUL868IPE/docker/configure-cul868ipe-and-start +++ b/ipes/CUL868IPE/docker/configure-cul868ipe-and-start @@ -64,4 +64,4 @@ mv ${CONFIG_TEMP} ${CONFIG_FILE} echo "done" -exec python -m cul868ipe $@ +exec python3 -m cul868ipe $@ diff --git a/ipes/CUL868IPE/setup-cul868ipe.py b/ipes/CUL868IPE/setup-cul868ipe.py index 0219687..3820aa4 100755 --- a/ipes/CUL868IPE/setup-cul868ipe.py +++ b/ipes/CUL868IPE/setup-cul868ipe.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup from distutils.core import setup diff --git a/ipes/CUL868IPE/src/cul868ipe/__main__.py b/ipes/CUL868IPE/src/cul868ipe/__main__.py index 9db206e..f729366 100644 --- a/ipes/CUL868IPE/src/cul868ipe/__main__.py +++ b/ipes/CUL868IPE/src/cul868ipe/__main__.py @@ -31,16 +31,16 @@ parser.add_argument("devices", nargs="*") args, config = prepare_app(parser, __loader__, __name__, "config.json") # variables -nm = get_value("name", (unicode, str), default_name, args, config) +nm = get_value("name", str, default_name, args, config) cb = config.get("cse_base", "onem2m") -ep = get_value("ep", (unicode, str), default_ep, args, config) +ep = get_value("ep", str, default_ep, args, config) poas = config.get("poas", ["http://auto:28728"]) originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1") ssl_certs = config.get("ssl_certs", {}) s = config.get("sim", False) p = int(config.get("sim_period")) -cul_device = get_value('cul_device', (unicode, str), default_device, args, config) +cul_device = get_value('cul_device', str, default_device, args, config) device_mappings = get_value('device_mappings', dict, {}, args, config) devices = get_value('devices', list, [], args, config) diff --git a/ipes/CUL868IPE/src/cul868ipe/cul_868_coordinator.py b/ipes/CUL868IPE/src/cul868ipe/cul_868_coordinator.py index ed7b0ed..cc4fb47 100644 --- a/ipes/CUL868IPE/src/cul868ipe/cul_868_coordinator.py +++ b/ipes/CUL868IPE/src/cul868ipe/cul_868_coordinator.py @@ -59,7 +59,7 @@ class CUL868Coordinator(LoggerMixin): run_forever(period, self._generate_simulated_data) def _generate_simulated_data(self): - p = choice(self.sim_parsers.keys()) + p = choice(list(self.sim_parsers.keys())) fake_parser = self.sim_parsers[p] dev_id, data = fake_parser(p) handler = self.handlers[p] diff --git a/ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py b/ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py index e281238..31d9f7f 100644 --- a/ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py +++ b/ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py @@ -1,7 +1,7 @@ import time from collections import namedtuple -from cul_868_coordinator import CUL868Coordinator +from .cul_868_coordinator import CUL868Coordinator from openmtc_app.onem2m import XAE from openmtc_onem2m.model import Container @@ -44,7 +44,7 @@ class CUL868IPE(XAE): self.cul = CUL868Coordinator(device=device, sim=sim) - for d in map(lambda s: CULDevice(*s.split(":")[:2]), cul_devices): + for d in [CULDevice(*s.split(":")[:2]) for s in cul_devices]: if d.type == "fs20": house_code, device_code = d.device_id.split("-") self.fs20.append((house_code, device_code)) @@ -85,11 +85,11 @@ class CUL868IPE(XAE): if func: sub_labels.append('openmtc:actuator_data') - sub_labels += map(lambda x: "openmtc:actuator_data:%s" % x, l) if l else [] + sub_labels += ["openmtc:actuator_data:%s" % x for x in l] if l else [] sub_cnt = Container(resourceName=c_id, maxNrOfInstances=0, labels=sub_labels) else: sub_labels.append('openmtc:sensor_data') - sub_labels += map(lambda x: "openmtc:sensor_data:%s" % x, l) if l else [] + sub_labels += ["openmtc:sensor_data:%s" % x for x in l] if l else [] sub_cnt = Container(resourceName=c_id, labels=sub_labels) self.containers[s_id] = s_cnt = self.create_container(dev_cnt, sub_cnt) @@ -123,7 +123,7 @@ class CUL868IPE(XAE): def _get_handle_switch(self, house_code, device_code): def handle_switch(container, content): - if isinstance(content, (str, unicode)): # fallback to old behavior + if isinstance(content, str): # fallback to old behavior if content == 'TOGGLE': self.cul.toggle(house_code, device_code) elif content == 'ON': diff --git a/ipes/CUL868IPE/src/cul868ipe/test_parsers.py b/ipes/CUL868IPE/src/cul868ipe/test_parsers.py index 4f6f71e..0eb1c15 100644 --- a/ipes/CUL868IPE/src/cul868ipe/test_parsers.py +++ b/ipes/CUL868IPE/src/cul868ipe/test_parsers.py @@ -1,4 +1,4 @@ -from parsers import S300THParser, EM1000EMParser, FS20Parser +from .parsers import S300THParser, EM1000EMParser, FS20Parser def test_parsers(): diff --git a/ipes/CUL868IPE/utils.py b/ipes/CUL868IPE/utils.py index d8a733f..532a2cc 100644 --- a/ipes/CUL868IPE/utils.py +++ b/ipes/CUL868IPE/utils.py @@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None): r_prefix = len(root) + 1 for path, dirs, files in os.walk(root, onerror=on_error): is_module = "__init__.py" in files and path != root - excluded = any(map(lambda x: x in path, excluded_list)) - included = any(map(lambda x: x in path, included_list)) + excluded = any([x in path for x in excluded_list]) + included = any([x in path for x in included_list]) if is_module and (not excluded or included): packages.append(package + "." + path[r_prefix:].replace("/", ".")) @@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name): def enable_init_files(init_dir, init_dist_files): for f in init_dist_files: - os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755) + os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755) def move_config_files(config_dir, config_files): @@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None): try: from pwd import getpwnam except ImportError: - print "Could not import the 'pwd' module. Skipping user management" + print("Could not import the 'pwd' module. Skipping user management") else: # assuming DB_DIR was created by setup already try: diff --git a/ipes/cul-868-ipe b/ipes/cul-868-ipe index 4c9fe0c..b7f9d6e 100755 --- a/ipes/cul-868-ipe +++ b/ipes/cul-868-ipe @@ -6,4 +6,4 @@ cd $(dirname ${0}) cd CUL868IPE -PYTHONPATH=${PYTHONPATH}:src exec python -m cul868ipe $@ +PYTHONPATH=${PYTHONPATH}:src exec python3 -m cul868ipe $@ diff --git a/openmtc-app/src/openmtc_app/notification/__init__.py b/openmtc-app/src/openmtc_app/notification/__init__.py index f69c9fa..8b958d4 100644 --- a/openmtc-app/src/openmtc_app/notification/__init__.py +++ b/openmtc-app/src/openmtc_app/notification/__init__.py @@ -9,7 +9,7 @@ from openmtc_onem2m.model import ( Subscription, ) from openmtc_onem2m.serializer import get_onem2m_decoder -from urlparse import urlparse +from urllib.parse import urlparse from openmtc_onem2m.util import split_onem2m_address @@ -67,7 +67,7 @@ class NotificationManager(LoggerMixin): def _get_auto_host(ep): try: import socket - from urlparse import urlparse + from urllib.parse import urlparse s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) netloc = urlparse(ep).netloc.split(':') s.connect((netloc[0], int(netloc[1]))) @@ -156,7 +156,7 @@ class NotificationManager(LoggerMixin): del self.callbacks[sur] def shutdown(self): - for subscription in self.callbacks.keys(): + for subscription in list(self.callbacks.keys()): try: self.unsubscribe(subscription) except OneM2MError: diff --git a/openmtc-app/src/openmtc_app/onem2m.py b/openmtc-app/src/openmtc_app/onem2m.py index 6b791d5..99c68be 100644 --- a/openmtc-app/src/openmtc_app/onem2m.py +++ b/openmtc-app/src/openmtc_app/onem2m.py @@ -94,7 +94,7 @@ class XAE(LoggerMixin): self.key_file = key_file if expiration_time is not None: - if isinstance(expiration_time, (str, unicode)): + if isinstance(expiration_time, str): expiration_time = parse_date(expiration_time) elif isinstance(expiration_time, (int, float)): expiration_time = datetime.fromtimestamp(expiration_time, UTC) @@ -483,7 +483,7 @@ class XAE(LoggerMixin): """ path = getattr(container, "path", container) - if isinstance(content, (str, unicode)): + if isinstance(content, str): fmt = 'text/plain' if fmt is None else fmt text = True if text is None else text elif isinstance(content, (dict, list)): @@ -499,14 +499,14 @@ class XAE(LoggerMixin): cnf = fmt + ':' + str(EncodingTypeE.plain.value) # raise CSENotImplemented("Only json as b64 is supported!") else: - con = b64encode(json_dumps(content)) + con = b64encode(json_dumps(content).encode('utf-8')) cnf = fmt + ':' + str(EncodingTypeE.base64String.value) elif fmt == 'text/plain': if text: con = content cnf = fmt + ':' + str(EncodingTypeE.plain.value) else: - con = b64encode(content) + con = b64encode(content.encode('utf-8')) cnf = fmt + ':' + str(EncodingTypeE.base64String.value) else: # TODO(rst): add handling of other formats or raise not implemented @@ -529,7 +529,7 @@ class XAE(LoggerMixin): content = cin.content try: if int(encoding_type) == EncodingTypeE.base64String: - content = b64decode(content) + content = b64decode(content).decode('utf-8') if media_type == 'application/json': content = json_loads(content) @@ -567,10 +567,8 @@ class XAE(LoggerMixin): def _remove_route(self, route): self.logger.debug("removing route: %s", route) - self.runner.flask_app.url_map._rules = filter( - lambda x: x.rule != route, - self.runner.flask_app.url_map._rules - ) + self.runner.flask_app.url_map._rules = [x for x in self.runner.flask_app.url_map._rules + if x.rule != route] def _add_subscription(self, path, _, handler, delete_handler, filter_criteria=None, expiration_time=None): @@ -865,9 +863,9 @@ class ResourceManagementXAE(XAE): sub_ref = self._cse_id + '/' + sub_ref self._discovered_sensors = {k: v for k, v in self._discovered_sensors.items() if v['sub_ref'] != sub_ref} - self._discovered_devices = {k: v for k, v in self._discovered_devices.items() - if any(filter(lambda x: x.startswith(k), - self._discovered_sensors.keys())) + self._discovered_devices = {k: v for k, v in list(self._discovered_devices.items()) + if any([x for x in list(self._discovered_sensors.keys()) + if x.startswith(k)]) or not sub_ref.startswith(k)} def _handle_sensor_data(self, container, data): diff --git a/openmtc-app/src/openmtc_app/util.py b/openmtc-app/src/openmtc_app/util.py index 4421e13..ffeae12 100644 --- a/openmtc-app/src/openmtc_app/util.py +++ b/openmtc-app/src/openmtc_app/util.py @@ -3,6 +3,7 @@ from json import load as json_load from operator import getitem import futile +from functools import reduce def prepare_app(parser, loader, name, default_config_file): @@ -11,7 +12,7 @@ def prepare_app(parser, loader, name, default_config_file): " specified multiple times.") args = parser.parse_args() - module_ = loader.fullname.split("." + name).pop(0) + module_ = loader.name.split("." + name).pop(0) futile.logging.set_default_level(futile.logging.DEBUG) logger = futile.logging.get_logger(name) diff --git a/openmtc-gevent/bin/openmtc-backend-gevent b/openmtc-gevent/bin/openmtc-backend-gevent index 06bdf53..17e622b 100755 --- a/openmtc-gevent/bin/openmtc-backend-gevent +++ b/openmtc-gevent/bin/openmtc-backend-gevent @@ -1,3 +1,3 @@ #!/bin/sh -exec python -m openmtc_gevent.backend_main $@ +exec python3 -m openmtc_gevent.backend_main $@ diff --git a/openmtc-gevent/bin/openmtc-gateway-gevent b/openmtc-gevent/bin/openmtc-gateway-gevent index f53a58b..dfe41d8 100755 --- a/openmtc-gevent/bin/openmtc-gateway-gevent +++ b/openmtc-gevent/bin/openmtc-gateway-gevent @@ -1,3 +1,3 @@ #!/bin/sh -exec python -m openmtc_gevent.gateway_main $@ +exec python3 -m openmtc_gevent.gateway_main $@ diff --git a/openmtc-gevent/dependencies.txt b/openmtc-gevent/dependencies.txt index 2cc59dc..d325744 100644 --- a/openmtc-gevent/dependencies.txt +++ b/openmtc-gevent/dependencies.txt @@ -1,4 +1,4 @@ -# Dont install via the operating system's package manager +# Don't install via the operating system's package manager # Install all dependencies via the "pip" tool # e.g. $ sudo pip install urllib3 # or $ sudo pip install --requirement dependencies.txt @@ -16,8 +16,6 @@ python_socketio>=1.7.5 flask geventhttpclient enum34 -pyxb==1.2.3 -dtls blist simplejson ujson @@ -25,5 +23,4 @@ pymongo paho-mqtt coapthon rdflib -fyzz yapps diff --git a/openmtc-gevent/run-backend b/openmtc-gevent/run-backend index 879fff3..4a47650 100755 --- a/openmtc-gevent/run-backend +++ b/openmtc-gevent/run-backend @@ -4,4 +4,4 @@ cd $(dirname ${0}) . ./prep-env.sh -exec python src/openmtc_gevent/backend_main.py -f config-backend.json "$@" +exec python3 src/openmtc_gevent/backend_main.py -f config-backend.json "$@" diff --git a/openmtc-gevent/run-gateway b/openmtc-gevent/run-gateway index 7ed0dca..7647c43 100755 --- a/openmtc-gevent/run-gateway +++ b/openmtc-gevent/run-gateway @@ -4,4 +4,4 @@ cd $(dirname ${0}) . ./prep-env.sh -exec python src/openmtc_gevent/gateway_main.py -f config-gateway.json "$@" +exec python3 src/openmtc_gevent/gateway_main.py -f config-gateway.json "$@" diff --git a/openmtc-gevent/src/openmtc_gevent/main.py b/openmtc-gevent/src/openmtc_gevent/main.py index 619323d..fa7a2d1 100644 --- a/openmtc-gevent/src/openmtc_gevent/main.py +++ b/openmtc-gevent/src/openmtc_gevent/main.py @@ -5,7 +5,7 @@ import sys import os import gevent.monkey -if 'threading' in sys.modules and not os.environ.get('SUPPORT_GEVENT'): +if 'threading' in sys.modules and not os.environ.get('GEVENT_SUPPORT'): raise Exception('threading module loaded before monkey patching in ' 'gevent_main!') @@ -60,7 +60,7 @@ gevent.ssl.PROTOCOL_SSLv3 = gevent.ssl.PROTOCOL_TLSv1 # gevent main ################################################################################ from openmtc.configuration import ConfigurationError -from openmtc_server.util.async import async_all +from openmtc_server.util.async_ import async_all _components = [] _plugins = [] @@ -168,7 +168,8 @@ def stop_component(component): def stop_components(): - map(stop_component, reversed(_components)) + for c in reversed(_components): + stop_component(c) logger.debug("Components stopped") @@ -179,8 +180,10 @@ def stop_plugin(plugin): def stop_plugins(): # stop transport plugins after the others - map(stop_plugin, filter(lambda p: not p.name.endswith('TransportPlugin'), _plugins)) - map(stop_plugin, filter(lambda p: p.name.endswith('TransportPlugin'), _plugins)) + for p in [p for p in _plugins if not p.name.endswith('TransportPlugin')]: + stop_plugin(p) + for p in [p for p in _plugins if p.name.endswith('TransportPlugin')]: + stop_plugin(p) def init_component(component, api): @@ -278,7 +281,7 @@ def main(default_config_file, is_gateway): from openmtc_server.platform.default.Event import (ResourceFinishEvent, NetworkEvent) - from GEventNetworkManager import GEventNetworkManager + from .GEventNetworkManager import GEventNetworkManager from openmtc_server.util.db import load_db_module diff --git a/server/openmtc-cse/src/openmtc_cse/methoddomain/__init__.py b/server/openmtc-cse/src/openmtc_cse/methoddomain/__init__.py index 6d73da1..2d189fa 100644 --- a/server/openmtc-cse/src/openmtc_cse/methoddomain/__init__.py +++ b/server/openmtc-cse/src/openmtc_cse/methoddomain/__init__.py @@ -1,4 +1,4 @@ -import controller +from . import controller import openmtc_onem2m.model as model from aplus import Promise from openmtc.util import datetime_now diff --git a/server/openmtc-cse/src/openmtc_cse/methoddomain/controller/__init__.py b/server/openmtc-cse/src/openmtc_cse/methoddomain/controller/__init__.py index 4795c5e..2582c52 100644 --- a/server/openmtc-cse/src/openmtc_cse/methoddomain/controller/__init__.py +++ b/server/openmtc-cse/src/openmtc_cse/methoddomain/controller/__init__.py @@ -1,14 +1,15 @@ +import base64 +import binascii import string from datetime import datetime from itertools import chain from operator import attrgetter from random import choice -from urlparse import urlparse -import binascii -import base64 +from urllib.parse import urlparse +from xml.sax import SAXParseException from iso8601.iso8601 import parse_date, ParseError -from fyzz import parse +from pyparsing import ParseException from rdflib import Graph import openmtc_cse.api as api @@ -39,14 +40,13 @@ from openmtc_server.db import DBError from openmtc_server.db.exc import DBNotFound from openmtc_server.util import match_now_cron from openmtc_server.util import uri_safe -from openmtc_server.util.async import async_all - +from openmtc_server.util.async_ import async_all _resource_id_counter = {} class OneM2MDefaultController(LoggerMixin): - RANDOM_SOURCE = string.letters + string.digits + RANDOM_SOURCE = string.ascii_letters + string.digits result_content_type = None @@ -98,8 +98,7 @@ class OneM2MDefaultController(LoggerMixin): self._abs_cse_id = self._sp_id + self._rel_cse_id # //openmtc.org/mn-cse-1 # default policies - self._default_privileges = map(lambda x: AccessControlRuleC(**x), - self.onem2m_config.get("default_privileges", [])) + self._default_privileges = [AccessControlRuleC(**x) for x in self.onem2m_config.get("default_privileges", [])] # dynamic authorization dynamic_authorization = self.onem2m_config.get("dynamic_authorization", {}) @@ -268,7 +267,7 @@ class OneM2MDefaultController(LoggerMixin): self.logger.debug("Error getting policy: %s:", error) return None - return filter(None, map(get_policy, access_control_policy_ids)) + return [_f for _f in map(get_policy, access_control_policy_ids) if _f] # def _notify_das_server(self, notify_uri, payload): def _notify_das_server(self, resource): @@ -902,7 +901,7 @@ class OneM2MDefaultController(LoggerMixin): self._retrieve_children() def _send_retrieve_response(self): - fields = self.resource.values.keys() + fields = list(self.resource.values.keys()) if self.request.rcn != ResultContentE.attributes_and_child_resource_references: fields = [k for k in fields if k != 'childResource'] return OneM2MResponse(STATUS_OK, pc=self.result, request=self.request, fields=fields) @@ -1329,12 +1328,14 @@ class ContentInstanceController(OneM2MDefaultController): self.parent.oldest = None # handle_old_instances - if 0 < self.parent.maxNrOfInstances <= self.parent.currentNrOfInstances: - remove_oldest_child() + if self.parent.maxNrOfInstances is not None: + if 0 < self.parent.maxNrOfInstances <= self.parent.currentNrOfInstances: + remove_oldest_child() - while (0 < self.parent.maxByteSize < - self.parent.currentByteSize + self.resource.contentSize): - remove_oldest_child() + if self.parent.maxByteSize is not None: + while (0 < self.parent.maxByteSize < + self.parent.currentByteSize + self.resource.contentSize): + remove_oldest_child() # handle_new_instance self.parent.currentNrOfInstances += 1 @@ -1357,7 +1358,7 @@ class ContentInstanceController(OneM2MDefaultController): super(ContentInstanceController, self)._set_mandatory_create_attributes(vals) - vals["contentSize"] = len(vals["content"].encode('utf-8')) + vals["contentSize"] = len(vals["content"]) if not vals.get("contentInfo"): vals["contentInfo"] = 'text/plain:0' @@ -1420,14 +1421,14 @@ class SemanticDescriptorController(OneM2MDefaultController): @staticmethod def _check_descriptor_data(descriptor_data): try: - data = base64.b64decode(descriptor_data) + data = base64.b64decode(descriptor_data).decode('utf-8') except binascii.Error: raise CSEContentsUnacceptable("The descriptor was not correctly base64 encoded.") try: g = Graph() g.parse(data=data, format="application/rdf+xml") - except Exception: + except SAXParseException: raise CSEContentsUnacceptable("The descriptor attribute does not conform to the " "RDF/XML syntax as defined in RDF 1.1 XML Syntax.") @@ -1455,9 +1456,10 @@ class SemanticDescriptorController(OneM2MDefaultController): self._check_descriptor_data(self.values["descriptor"]) elif "semanticOpExec" in values: # verify if the semanticOpExec has a correct SPAROL syntax + g = Graph() try: - parse(values["semanticOpExec"]) - except Exception: + g.parse(values["semanticOpExec"]) + except ParseException: raise CSEContentsUnacceptable("The semanticOpExec attribute does not conform to " "the SPARQL query syntax.") else: diff --git a/server/openmtc-cse/src/openmtc_cse/methoddomain/filtercriteria/__init__.py b/server/openmtc-cse/src/openmtc_cse/methoddomain/filtercriteria/__init__.py index 98b2b35..d10f226 100644 --- a/server/openmtc-cse/src/openmtc_cse/methoddomain/filtercriteria/__init__.py +++ b/server/openmtc-cse/src/openmtc_cse/methoddomain/filtercriteria/__init__.py @@ -10,7 +10,7 @@ _logger = get_logger(__name__) def check_match(resource, filter_criteria): _logger.debug("checking if filter criteria '%s' are matched by " "resource '%s'", filter_criteria, resource) - for criteria, value in filter_criteria.get_values(True).iteritems(): + for criteria, value in filter_criteria.get_values(True).items(): if not value: continue _logger.debug("checking if resource matches: %s=%s", criteria, value) @@ -37,10 +37,10 @@ def parse_filter_criteria(filter_criteria): int_criteria = ('stateTagSmaller', 'stateTagBigger', 'resourceType', 'sizeAbove', 'sizeBelow', 'filterUsage', 'limit') parsed_criteria = {} - for k, v in filter_criteria.iteritems(): + for k, v in filter_criteria.items(): if k in int_criteria: if isinstance(v, list): - parsed_criteria[k] = map(int, v) + parsed_criteria[k] = list(map(int, v)) else: parsed_criteria[k] = int(v) else: diff --git a/server/openmtc-cse/src/openmtc_cse/plugins/announcement_handler/__init__.py b/server/openmtc-cse/src/openmtc_cse/plugins/announcement_handler/__init__.py index d8cbc2a..69227b5 100644 --- a/server/openmtc-cse/src/openmtc_cse/plugins/announcement_handler/__init__.py +++ b/server/openmtc-cse/src/openmtc_cse/plugins/announcement_handler/__init__.py @@ -8,11 +8,11 @@ from openmtc_onem2m.transport import OneM2MRequest, MetaInformation, \ OneM2MOperation from openmtc_server.Plugin import Plugin from copy import deepcopy -from openmtc_server.util.async import async_all +from openmtc_server.util.async_ import async_all from re import sub -from urlparse import urlparse +from urllib.parse import urlparse # url join with coap compatibility -from urlparse import urljoin, uses_relative, uses_netloc +from urllib.parse import urljoin, uses_relative, uses_netloc uses_relative.append('coap') uses_netloc.append('coap') @@ -77,7 +77,7 @@ class AnnouncementHandler(Plugin): return retrieve_remote_cse_list() \ .then( - lambda remote_cse_list: async_all(map(get_cse, remote_cse_list))) \ + lambda remote_cse_list: async_all(list(map(get_cse, remote_cse_list)))) \ .then(handle_remote_cse_list) \ .then(self._started) # return self._started() @@ -277,8 +277,8 @@ class AnnouncementHandler(Plugin): # from the cseList and no further actions for those CSEs are performed. def check_cse_list(): self.logger.debug("check_cse_list: %s vs %s" % ( - db_cse_list, self._cse_links.values())) - return filter(lambda x: x in db_cse_list, self._cse_links.values()) + db_cse_list, list(self._cse_links.values()))) + return [x for x in list(self._cse_links.values()) if x in db_cse_list] # b) Send createXXXAnnouncementResourceRequestIndication (where XXX is # replaced by the type of the resource to be announced) for each CSE in @@ -464,12 +464,12 @@ class AnnouncementHandler(Plugin): # filters out all False in the list def filter_func(l): - return filter(None, l) + return [_f for _f in l if _f] return async_all([ - (async_all(map(create_func, create_list)).then(filter_func) + (async_all(list(map(create_func, create_list))).then(filter_func) .then(lambda l: l + filtered_cses)), - async_all(map(delete_func, delete_list)).then(filter_func) + async_all(list(map(delete_func, delete_list))).then(filter_func) ]) return send_anncs(check_cse_list()) @@ -597,7 +597,7 @@ class AnnouncementHandler(Plugin): # TODO: conversion to set() is questionable update_list = [x for x in cse_list if x not in set(add_list)] - return async_all(map(send_update_annc_pre, update_list)) + return async_all(list(map(send_update_annc_pre, update_list))) self.logger.debug('No attributes changed, returning None') return None diff --git a/server/openmtc-cse/src/openmtc_cse/plugins/notification_handler/__init__.py b/server/openmtc-cse/src/openmtc_cse/plugins/notification_handler/__init__.py index b49c623..d7845bf 100644 --- a/server/openmtc-cse/src/openmtc_cse/plugins/notification_handler/__init__.py +++ b/server/openmtc-cse/src/openmtc_cse/plugins/notification_handler/__init__.py @@ -77,13 +77,13 @@ class NotificationHandler(Plugin): def _get_sub_list(self, pid, net): return [ - v['sub'] for v in self.subscriptions_info.itervalues() + v['sub'] for v in self.subscriptions_info.values() if v['pid'] == pid and net in v['enc'].notificationEventType ] def _delete_subs_from_parent(self, pid): self.subscriptions_info = { - k: v for k, v in self.subscriptions_info.iteritems() if v["pid"] != pid + k: v for k, v in self.subscriptions_info.items() if v["pid"] != pid } def _handle_subscription_created(self, subscription, _): @@ -143,24 +143,16 @@ class NotificationHandler(Plugin): def _handle_subscribable_resource_updated(self, resource, _): self.logger.debug("_handle_subscribable_resource_updated for %s", resource) - map( - lambda sub: self._handle_subscription(resource, sub), - self._get_sub_list( - resource.resourceID, - NotificationEventTypeE.updateOfResource, - ) - ) + for sub in self._get_sub_list( + resource.resourceID, NotificationEventTypeE.updateOfResource,): + self._handle_subscription(resource, sub) def _handle_subscribable_resource_created(self, resource, _): self.logger.debug("_handle_subscribable_resource_created for %s", resource) - map( - lambda sub: self._handle_subscription(resource, sub), - self._get_sub_list( - resource.parentID, - NotificationEventTypeE.createOfDirectChildResource, - ) - ) + for sub in self._get_sub_list( + resource.parentID, NotificationEventTypeE.createOfDirectChildResource,): + self._handle_subscription(resource, sub) def _handle_subscribable_resource_deleted(self, resource, _): self.logger.debug("_handle_subscribable_resource_deleted for %s", resource) diff --git a/server/openmtc-cse/src/openmtc_cse/plugins/registration_handler/__init__.py b/server/openmtc-cse/src/openmtc_cse/plugins/registration_handler/__init__.py index 3ab871a..36e7f15 100644 --- a/server/openmtc-cse/src/openmtc_cse/plugins/registration_handler/__init__.py +++ b/server/openmtc-cse/src/openmtc_cse/plugins/registration_handler/__init__.py @@ -111,7 +111,7 @@ class RegistrationHandler(Plugin): remote_cse_poa = remote_cse.get("poa", []) self.api.add_poa_list(remote_cse_id, remote_cse_poa) - return map(handle_remote_cse_method, remote_cses) + return list(map(handle_remote_cse_method, remote_cses)) def _handle_remote_cse_delete(self, remote_cse): """ Sends a delete request for the RemoteCSE resource. diff --git a/server/openmtc-cse/src/openmtc_cse/plugins/transport_gevent_http/wsgi.py b/server/openmtc-cse/src/openmtc_cse/plugins/transport_gevent_http/wsgi.py index d8711d3..622aca9 100644 --- a/server/openmtc-cse/src/openmtc_cse/plugins/transport_gevent_http/wsgi.py +++ b/server/openmtc-cse/src/openmtc_cse/plugins/transport_gevent_http/wsgi.py @@ -1,4 +1,4 @@ -import urlparse +import urllib.parse import ssl from _socket import gaierror from datetime import datetime @@ -104,8 +104,7 @@ class OpenMTCWSGIApplication(LoggerMixin): for interface in interfaces(): try: ifdata = ifaddresses(interface)[family] - ifaddrs = map(lambda x: x.split("%")[0], pluck("addr", - ifdata)) + ifaddrs = [x.split("%")[0] for x in pluck("addr", ifdata)] addresses.update(ifaddrs) except KeyError: pass @@ -268,7 +267,7 @@ class OpenMTCWSGIApplication(LoggerMixin): if http_request.query_string: from openmtc_cse.methoddomain.filtercriteria import filters - params = urlparse.parse_qs(http_request.query_string) + params = urllib.parse.parse_qs(http_request.query_string.decode("utf-8")) get_param = params.get f_c = {} @@ -288,7 +287,7 @@ class OpenMTCWSGIApplication(LoggerMixin): setattr(onem2m_request, param, values[0]) elif param_long_name == 'attributeList': onem2m_request.pc = AttributeList( - map(get_long_attribute_name, values[0].split(' '))) + list(map(get_long_attribute_name, values[0].split(' ')))) elif param_long_name and hasattr(filters, param_long_name): self.logger.debug("got values for '%s' ('%s'): %s", param_long_name, param, values) @@ -414,9 +413,7 @@ class OpenMTCWSGIApplication(LoggerMixin): setattr(onem2m_request, "_authenticated", False) if subject_alt_name is not None: setattr(onem2m_request, "_authenticated", True) - impersonation_error = not bool(len(filter( - lambda x: x[0] == 'URI' and x[1] == onem2m_request.fr, - subject_alt_name))) + impersonation_error = not bool(len([x for x in subject_alt_name if x[0] == 'URI' and x[1] == onem2m_request.fr])) if impersonation_error: onem2m_response = OneM2MResponse(STATUS_IMPERSONATION_ERROR, request=onem2m_request) diff --git a/server/openmtc-cse/src/openmtc_cse/plugins/transport_gevent_mqtt/__init__.py b/server/openmtc-cse/src/openmtc_cse/plugins/transport_gevent_mqtt/__init__.py index 98d13dc..f4b3c8a 100644 --- a/server/openmtc-cse/src/openmtc_cse/plugins/transport_gevent_mqtt/__init__.py +++ b/server/openmtc-cse/src/openmtc_cse/plugins/transport_gevent_mqtt/__init__.py @@ -17,11 +17,11 @@ class MQTTTransportPlugin(Plugin): self._initialized() def _start(self): - self.api.register_onem2m_client(portmap.keys(), get_client) + self.api.register_onem2m_client(list(portmap.keys()), get_client) interface = self.config.get('interface', '127.0.0.1') port = self.config.get('port', 1883) try: - scheme = portmap.keys()[portmap.values().index(port)] + scheme = list(portmap.keys())[list(portmap.values()).index(port)] except (KeyError, ValueError): scheme = 'mqtt' diff --git a/server/openmtc-cse/src/openmtc_cse/transport/__init__.py b/server/openmtc-cse/src/openmtc_cse/transport/__init__.py index e7ac7c2..ec2e3ab 100644 --- a/server/openmtc-cse/src/openmtc_cse/transport/__init__.py +++ b/server/openmtc-cse/src/openmtc_cse/transport/__init__.py @@ -1,4 +1,4 @@ -from urlparse import urlparse +from urllib.parse import urlparse from netifaces import AF_INET, AF_INET6 from aplus import Promise @@ -64,7 +64,7 @@ class OneM2MTransportDomain(Component): self.events.resource_deleted.register_handler(self._handle_cse_deleted, RemoteCSE) interfaces = self._api.network_manager.get_interfaces().get() - self._addresses = {i.name: filter(self._filter_out_link_local, i.addresses) + self._addresses = {i.name: list(filter(self._filter_out_link_local, i.addresses)) for i in interfaces} @staticmethod @@ -104,7 +104,7 @@ class OneM2MTransportDomain(Component): # interface handling def _handle_interface_created(self, interface): - self._addresses[interface.name] = filter(self._filter_out_link_local, interface.addresses) + self._addresses[interface.name] = list(filter(self._filter_out_link_local, interface.addresses)) self._create_endpoints() def _handle_interface_removed(self, interface): diff --git a/server/openmtc-server/src/openmtc_server/Event.py b/server/openmtc-server/src/openmtc_server/Event.py index 6a3ca16..812a91c 100644 --- a/server/openmtc-server/src/openmtc_server/Event.py +++ b/server/openmtc-server/src/openmtc_server/Event.py @@ -5,9 +5,7 @@ from futile.logging import LoggerMixin from openmtc.model import Resource -class Event(LoggerMixin): - __metaclass__ = ABCMeta - +class Event(LoggerMixin, metaclass=ABCMeta): @abstractmethod def fire(self, *event_data): raise NotImplementedError() @@ -17,9 +15,7 @@ class Event(LoggerMixin): raise NotImplementedError() -class EventSpec(object): - __metaclass__ = ABCMeta - +class EventSpec(object, metaclass=ABCMeta): @abstractmethod def matches(self, item): raise NotImplementedError() diff --git a/server/openmtc-server/src/openmtc_server/TaskRunner.py b/server/openmtc-server/src/openmtc_server/TaskRunner.py index 5b5116d..73b6736 100644 --- a/server/openmtc-server/src/openmtc_server/TaskRunner.py +++ b/server/openmtc-server/src/openmtc_server/TaskRunner.py @@ -2,9 +2,7 @@ from abc import ABCMeta, abstractmethod from futile.logging import LoggerMixin -class TaskRunner(LoggerMixin): - __metaclass__ = ABCMeta - +class TaskRunner(LoggerMixin, metaclass=ABCMeta): @abstractmethod def run_task(self, task, *args, **kw): raise NotImplementedError() diff --git a/server/openmtc-server/src/openmtc_server/__init__.py b/server/openmtc-server/src/openmtc_server/__init__.py index dbeb488..3db05f7 100644 --- a/server/openmtc-server/src/openmtc_server/__init__.py +++ b/server/openmtc-server/src/openmtc_server/__init__.py @@ -13,9 +13,7 @@ class Component(LoggerMixin): pass -class Serializer(LoggerMixin): - __metaclass__ = ABCMeta - +class Serializer(LoggerMixin, metaclass=ABCMeta): @abstractmethod def encode(self, resource): raise NotImplementedError() diff --git a/server/openmtc-server/src/openmtc_server/db/__init__.py b/server/openmtc-server/src/openmtc_server/db/__init__.py index 7601254..02aec72 100644 --- a/server/openmtc-server/src/openmtc_server/db/__init__.py +++ b/server/openmtc-server/src/openmtc_server/db/__init__.py @@ -5,9 +5,7 @@ from openmtc_server.db.exc import DBError from collections import MutableMapping -class DBAdapter(LoggerMixin): - __metaclass__ = ABCMeta - +class DBAdapter(LoggerMixin, metaclass=ABCMeta): def __init__(self, config, *args, **kw): super(DBAdapter, self).__init__(*args, **kw) @@ -36,9 +34,7 @@ class DBAdapter(LoggerMixin): pass -class Shelve(LoggerMixin, MutableMapping): - __metaclass__ = ABCMeta - +class Shelve(LoggerMixin, MutableMapping, metaclass=ABCMeta): @abstractmethod def commit(self): raise NotImplementedError() @@ -48,9 +44,7 @@ class Shelve(LoggerMixin, MutableMapping): raise NotImplementedError() -class Session(object): - __metaclass__ = ABCMeta - +class Session(object, metaclass=ABCMeta): @abstractmethod def store(self, resource): raise NotImplementedError() @@ -96,9 +90,7 @@ class Session(object): raise NotImplementedError() -class BasicSession(Session, LoggerMixin): - __metaclass__ = ABCMeta - +class BasicSession(Session, LoggerMixin, metaclass=ABCMeta): def __init__(self, resource_type, *args, **kw): super(BasicSession, self).__init__(*args, **kw) @@ -129,7 +121,8 @@ class BasicSession(Session, LoggerMixin): def delete_children(self, resource_type, parent): children = self.get_collection(resource_type, parent) - map(self.delete, children) + for c in children: + self.delete(c) def _get_content_instances(self, parent): return self.get_collection(self.cinType, parent) diff --git a/server/openmtc-server/src/openmtc_server/db/nodb2.py b/server/openmtc-server/src/openmtc_server/db/nodb2.py index 5d61816..b1eecdf 100644 --- a/server/openmtc-server/src/openmtc_server/db/nodb2.py +++ b/server/openmtc-server/src/openmtc_server/db/nodb2.py @@ -65,18 +65,18 @@ class NoDB2Session(BasicSession): if parent.__model_name__ == "onem2m": if resource_type is None: - resources = self.children[parent.path].values() - resources = map(dict.values, resources) - resources = reduce(list.__add__, resources, []) + resources = [] + for v in self.children[parent.path].values(): + resources += list(v.values()) elif isinstance(resource_type, (list, tuple, set)): - resources = [v for k, v in self.children[parent.path].items() - if k in resource_type] - resources = map(dict.values, resources) - resources = reduce(list.__add__, resources, []) + resources = [] + for k, v in self.children[parent.path].items(): + if k in resource_type: + resources + list(v.values()) else: - resources = self.children[parent.path][resource_type].values() + resources = list(self.children[parent.path][resource_type].values()) else: - resources = self.children[parent.path][resource_type].values() + resources = list(self.children[parent.path][resource_type].values()) self.logger.debug("Found children: %s", resources) return resources diff --git a/server/openmtc-server/src/openmtc_server/platform/default/TaskRunner.py b/server/openmtc-server/src/openmtc_server/platform/default/TaskRunner.py index 12dd9e8..26ea5e1 100644 --- a/server/openmtc-server/src/openmtc_server/platform/default/TaskRunner.py +++ b/server/openmtc-server/src/openmtc_server/platform/default/TaskRunner.py @@ -1,4 +1,4 @@ -from Queue import Queue, Empty +from queue import Queue, Empty from threading import Thread from openmtc_server.TaskRunner import TaskRunner diff --git a/server/openmtc-server/src/openmtc_server/util/__init__.py b/server/openmtc-server/src/openmtc_server/util/__init__.py index 91de583..d262824 100644 --- a/server/openmtc-server/src/openmtc_server/util/__init__.py +++ b/server/openmtc-server/src/openmtc_server/util/__init__.py @@ -1,4 +1,4 @@ -from urllib import quote +from urllib.parse import quote from datetime import datetime from mimeparse import parse_mime_type diff --git a/server/openmtc-server/src/openmtc_server/util/async.py b/server/openmtc-server/src/openmtc_server/util/async_.py similarity index 100% rename from server/openmtc-server/src/openmtc_server/util/async.py rename to server/openmtc-server/src/openmtc_server/util/async_.py diff --git a/setup-gevent-all.py b/setup-gevent-all.py index 2d367ce..b06fee8 100755 --- a/setup-gevent-all.py +++ b/setup-gevent-all.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup from distutils.core import setup @@ -26,18 +26,18 @@ SETUP_LICENSE = "Fraunhofer FOKUS proprietary" SETUP_REQUIRES = [ "urllib3", "gevent (>=1.0)", "iso8601 (>=0.1.5)", "werkzeug (>=0.9)", "blist", "simplejson", "ujson", "python_socketio", "gevent_websocket", - "flask", "pyxb (==1.2.3)", "enum34", "dtls", "geventhttpclient", + "flask", "enum34", "geventhttpclient", # server only "funcy", "netifaces", "decorator", "mimeparse", "coapthon", "rdflib", - "fyzz", "yapps", "paho_mqtt" + "yapps", "paho_mqtt" ] SETUP_INSTALL_REQUIRES = [ "urllib3", "gevent >= 1.0", "iso8601 >= 0.1.5", "werkzeug >= 0.9", "blist", "simplejson", "ujson", "python_socketio", "gevent_websocket", - "flask", "pyxb == 1.2.3", "enum34", "dtls", "geventhttpclient", + "flask", "enum34", "geventhttpclient", # server only "funcy", "netifaces", "decorator", "mimeparse", "coapthon", "rdflib", - "fyzz", "yapps", "paho_mqtt" + "yapps", "paho_mqtt" ] # packages @@ -77,8 +77,7 @@ CONFIG_DIR = "/etc/openmtc/gevent" CONFIG_DIST_FILES = ("openmtc-gevent/etc/conf/config-backend.json.dist", "openmtc-gevent/etc/conf/config-gateway.json.dist") SSL_CERT_DIR = "/etc/openmtc/certs" -SSL_CERT_FILES = tuple(map(lambda x: os.path.join('openmtc-gevent/certs/', x), - os.listdir('openmtc-gevent/certs'))) +SSL_CERT_FILES = tuple([os.path.join('openmtc-gevent/certs/', x) for x in os.listdir('openmtc-gevent/certs')]) DATA_FILES = [ (DB_DIR, ""), (LOG_DIR, ""), diff --git a/setup-sdk.py b/setup-sdk.py index 8d2df28..3b2e80b 100755 --- a/setup-sdk.py +++ b/setup-sdk.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup from distutils.core import setup @@ -20,12 +20,12 @@ SETUP_LICENSE = "Fraunhofer FOKUS proprietary" SETUP_REQUIRES = [ "urllib3", "gevent (>=1.0)", "iso8601 (>=0.1.5)", "werkzeug (>=0.9)", "blist", "simplejson", "ujson", "python_socketio", "gevent_websocket", - "flask", "pyxb (==1.2.3)", "enum34", "dtls", "geventhttpclient" + "flask", "enum34", "geventhttpclient" ] SETUP_INSTALL_REQUIRES = [ "urllib3", "gevent >= 1.0", "iso8601 >= 0.1.5", "werkzeug >= 0.9", "blist", "simplejson", "ujson", "python_socketio", "gevent_websocket", - "flask", "pyxb == 1.2.3", "enum34", "dtls", "geventhttpclient" + "flask", "enum34", "geventhttpclient" ] # packages diff --git a/tests/interoperability/basic.yaml b/tests/interoperability/basic.yaml index 684dc00..4792827 100644 --- a/tests/interoperability/basic.yaml +++ b/tests/interoperability/basic.yaml @@ -25,11 +25,13 @@ - name: "RemoteCSE Create" - url: "/onem2m/" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:csr": {"csi":"/mn-cse-1", "cb":"onem2m", "rr":true, "cst":2, "rn":"mn-cse-1"}}' #pc - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:csr.ty', comparator: 'eq', expected: 16} - test: @@ -37,10 +39,11 @@ - name: "remoteCSE Retrieve" - url: "/onem2m/mn-cse-1" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:csr.ty', comparator: 'eq', expected: 16} - test: @@ -48,11 +51,13 @@ - name: "RemoteCSE Update" - url: "/onem2m/mn-cse-1" - method: "PUT" #Update - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:csr": {"rr":false}}' #pc - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2004'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:csr.ty', comparator: 'eq', expected: 16} - test: @@ -60,10 +65,11 @@ - name: "remoteCSE Delete" - url: "/onem2m/mn-cse-1" - method: "DELETE" #Delete - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2002'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: [raw_body: "", expected: ""] ############################################################################### @@ -74,11 +80,13 @@ - name: "AE Create" - url: "/onem2m/" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:ae": {"api":"/myAE","rr":true,"rn":"myAE"}}' #pc - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:ae.ty', comparator: 'eq', expected: 2} - test: @@ -86,10 +94,11 @@ - name: "AE Retrieve" - url: "/onem2m/myAE" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:ae.ty', comparator: 'eq', expected: 2} - test: @@ -97,11 +106,13 @@ - name: "AE Update" - url: "/onem2m/myAE" - method: "PUT" #Update - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:csr": {"rr":false}}' #pc - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2004'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:ae.ty', comparator: 'eq', expected: 2} - test: @@ -109,10 +120,11 @@ - name: "AE Delete" - url: "/onem2m/myAE" - method: "DELETE" #Delete - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2002'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: [raw_body: "", expected: ""] ############################################################################### @@ -123,11 +135,13 @@ - name: "AE Create" - url: "/onem2m/" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:ae": {"api":"/myAE","rr":true,"rn":"myAE"}}' #pc - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:ae.ty', comparator: 'eq', expected: 2} - test: @@ -135,11 +149,13 @@ - name: "Container Create" - url: "/onem2m/myAE" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:cnt": {"rn":"myContainer"}}' #pc, , "li" = "Container1" - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cnt.ty', comparator: 'eq', expected: 3} - test: @@ -147,10 +163,11 @@ - name: "Container Retrieve" - url: "/onem2m/myAE/myContainer" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cnt.ty', comparator: 'eq', expected: 3} - test: @@ -158,11 +175,13 @@ - name: "Container Update" - url: "/onem2m/myAE/myContainer" - method: "PUT" #Update - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:cnt": {"mni": 4}}' #pc - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2004'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cnt.ty', comparator: 'eq', expected: 3} - test: @@ -170,10 +189,11 @@ - name: "Container Delete" - url: "/onem2m/myAE/myContainer" - method: "DELETE" #Delete - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2002'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: [raw_body: "", expected: ""] - test: @@ -181,10 +201,11 @@ - name: "AE Delete" - url: "/onem2m/myAE" - method: "DELETE" #Delete - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2002'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: [raw_body: "", expected: ""] ############################################################################### @@ -195,11 +216,13 @@ - name: "AE Create" - url: "/onem2m/" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:ae": {"api":"/myAE","rr":true,"rn":"myAE"}}' #pc - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:ae.ty', comparator: 'eq', expected: 2} - test: @@ -207,11 +230,13 @@ - name: "Container Create" - url: "/onem2m/myAE" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:cnt": {"rn":"myContainer"}}' #pc, , "li" = "Container1" - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cnt.ty', comparator: 'eq', expected: 3} - test: @@ -219,11 +244,13 @@ - name: "ContentInstance Create" - url: "/onem2m/myAE/myContainer" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:cin": {"con":"Type" , "rn":"Testcontent", "cnf": "text/plain:0" }}' #pc, , "li" = "Container1" - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cin.ty', comparator: 'eq', expected: 4} - test: @@ -231,8 +258,11 @@ - name: "Container Retrieve" - url: "/onem2m/myAE/myContainer" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: + - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} + - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cnt.cni', comparator: 'eq', expected: 1} - test: @@ -240,10 +270,11 @@ - name: "ContentInstance Retrieve" - url: "/onem2m/myAE/myContainer/Testcontent" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cin.ty', comparator: 'eq', expected: 4} - test: @@ -251,10 +282,11 @@ - name: "ContentInstance Delete" - url: "/onem2m/myAE/myContainer/Testcontent" - method: "DELETE" #Delete - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2002'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: [raw_body: "", expected: ""] - test: @@ -262,11 +294,13 @@ - name: "ContentInstance Create" - url: "/onem2m/myAE/myContainer" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:cin": {"con":"Type" , "rn":"Testcontent", "cnf": "text/plain:0" }}' #pc, , "li" = "Container1" - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cin.ty', comparator: 'eq', expected: 4} - test: @@ -274,10 +308,11 @@ - name: "latest ContentInstance Delete" - url: "/onem2m/myAE/myContainer/la" - method: "DELETE" #Delete - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2002'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: [raw_body: "", expected: ""] - test: @@ -285,11 +320,13 @@ - name: "ContentInstance Create" - url: "/onem2m/myAE/myContainer" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:cin": {"con":"Type" , "rn":"Testcontent", "cnf": "text/plain:0" }}' #pc, , "li" = "Container1" - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cin.ty', comparator: 'eq', expected: 4} - test: @@ -297,10 +334,11 @@ - name: "oldest ContentInstance Delete" - url: "/onem2m/myAE/myContainer/ol" - method: "DELETE" #Delete - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2002'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: [raw_body: "", expected: ""] - test: @@ -308,11 +346,13 @@ - name: "ContentInstance Create" - url: "/onem2m/myAE/myContainer" - method: "POST" #Create - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a', + Content-Type: application/vnd.onem2m-res+json} - body: '{"m2m:cin": {"con":"Type" , "rn":"Testcontent", "cnf": "text/plain:0" }}' #pc, , "li" = "Container1" - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2001'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cin.ty', comparator: 'eq', expected: 4} - test: @@ -320,10 +360,11 @@ - name: "latest ContentInstance Retrieve" - url: "/onem2m/myAE/myContainer/la" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cin.ty', comparator: 'eq', expected: 4} - test: @@ -331,10 +372,11 @@ - name: "oldest ContentInstance Retrieve" - url: "/onem2m/myAE/myContainer/ol" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: {jsonpath_mini: 'm2m:cin.ty', comparator: 'eq', expected: 4} - test: @@ -342,10 +384,11 @@ - name: "Container Delete" - url: "/onem2m/myAE/myContainer" - method: "DELETE" #Delete - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2002'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: [raw_body: "", expected: ""] - test: @@ -353,10 +396,11 @@ - name: "AE Delete" - url: "/onem2m/myAE" - method: "DELETE" #Delete - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar'} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2002'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - compare: [raw_body: "", expected: ""] ############################################################################### @@ -367,57 +411,63 @@ - name: "Discovery all resources" - url: "/onem2m?fu=1" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0, f} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - test: - group: "Openmtc Test 8.1.6" - name: "Discovery with filter criteria" - url: "/onem2m?fu=1&lbl=key1" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0, f} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - test: - group: "Openmtc Test 8.1.6" - name: "Discovery with limit filter criteria" - url: "/onem2m?fu=1&lim=2" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0, f} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} - test: - group: "Openmtc Test 8.1.6" - name: "Discovery with mulriple filter criteria" - url: "/onem2m?fu=1&lbl=key1&lbl=key2&lim=1" - method: "GET" #Retrieve - - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0, f} + - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} - validators: - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} + - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} #- test: # - group: "Openmtc Test 8.1.6" # - name: "Discovery with level filter criteria" # - url: "/onem2m?fu=1&lvl=2" # - method: "GET" #Retrieve -# - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0, f} +# - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} # - validators: # - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} # - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} +# - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} #- test: # - group: "Openmtc Test 8.1.6" # - name: "Discovery with offset filter criteria" # - url: "/onem2m?fu=1&ofst=1" # - method: "GET" #Retrieve -# - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', Content-Type: application/vnd.onem2m-res+json, Content-Location: CAE0, f} +# - headers: {'x-m2m-origin':'CAE0', 'x-m2m-ri': 'foobar', 'x-m2m-rvi': '2a'} # - validators: # - compare: {header: x-m2m-rsc, comparator: 'eq', expected: '2000'} # - compare: {header: x-m2m-ri, comparator: 'eq', expected: 'foobar'} +# - compare: {header: x-m2m-rvi, comparator: 'eq', expected: '2a'} diff --git a/util/json_benchmark.py b/util/json_benchmark.py index 3315c1f..0fa88b0 100644 --- a/util/json_benchmark.py +++ b/util/json_benchmark.py @@ -57,16 +57,16 @@ loops = 1000 enc_table = [] dec_table = [] -print "Running tests (%d loops each)" % loops +print("Running tests (%d loops each)" % loops) for title, mod, enc, dec in tests: - print title + print(title) - print " [Encode]", enc + print(" [Encode]", enc) result = timeit(enc, mod, number=loops) enc_table.append([title, result]) - print " [Decode]", dec + print(" [Decode]", dec) result = timeit(dec, mod, number=loops) dec_table.append([title, result]) @@ -76,8 +76,8 @@ enc_table.insert(0, ['Package', 'Seconds']) dec_table.sort(key=lambda x: x[1]) dec_table.insert(0, ['Package', 'Seconds']) -print "\nEncoding Test (%d loops)" % loops -print tabulate(enc_table, headers="firstrow") +print("\nEncoding Test (%d loops)" % loops) +print(tabulate(enc_table, headers="firstrow")) -print "\nDecoding Test (%d loops)" % loops -print tabulate(dec_table, headers="firstrow") +print("\nDecoding Test (%d loops)" % loops) +print(tabulate(dec_table, headers="firstrow")) diff --git a/utils.py b/utils.py index d8a733f..532a2cc 100644 --- a/utils.py +++ b/utils.py @@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None): r_prefix = len(root) + 1 for path, dirs, files in os.walk(root, onerror=on_error): is_module = "__init__.py" in files and path != root - excluded = any(map(lambda x: x in path, excluded_list)) - included = any(map(lambda x: x in path, included_list)) + excluded = any([x in path for x in excluded_list]) + included = any([x in path for x in included_list]) if is_module and (not excluded or included): packages.append(package + "." + path[r_prefix:].replace("/", ".")) @@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name): def enable_init_files(init_dir, init_dist_files): for f in init_dist_files: - os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755) + os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755) def move_config_files(config_dir, config_files): @@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None): try: from pwd import getpwnam except ImportError: - print "Could not import the 'pwd' module. Skipping user management" + print("Could not import the 'pwd' module. Skipping user management") else: # assuming DB_DIR was created by setup already try: