summaryrefslogtreecommitdiff
path: root/rest-api-templates
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2018-03-23 07:49:59 -0400
committerCorey Farrell <git@cfware.com>2018-04-09 10:07:38 -0400
commit879e592baf80712ba2e54110ece0e036df892ea0 (patch)
tree3c1334454fb8f040323fc3e721f12b68c7a690db /rest-api-templates
parent72a8e2106ea4f611a755da1a9c20f7bced300cce (diff)
Build System: Enable python3 compatibility.
* Consistently use spaces in rest-api-templates/asterisk_processor.py. * Exclude third-party from docs/full-en_US.xml. * Add docs/full-en_US.xml to .gitignore. * Use list() to convert python3 view. * Use python3 print function. * Replace cmp() with equivalent equation. * Replace reference to out of scope subtype variable with name parameter. * Use unescaping triple bracket notation in mustache templates where needed. This causes behavior of Python2 to be maintained when using Python3. * Fix references to has_websocket / is_websocket in res_ari_resource.c.mustache. * Update calculation of has_websocket to use any(). * Use unicode mode for writing output file in transform.py. * Replace 'from swagger_model import *' with explicit import of required symbols. I have not tested spandspflow2pcap.py or voicemailpwcheck.py, only the print syntax has been fixed. Change-Id: If5c5b556a2800d41a3e2cfef080ac2e151178c33
Diffstat (limited to 'rest-api-templates')
-rw-r--r--rest-api-templates/api.wiki.mustache2
-rw-r--r--rest-api-templates/ari_resource.h.mustache6
-rw-r--r--rest-api-templates/asterisk_processor.py8
-rwxr-xr-xrest-api-templates/make_ari_stubs.py5
-rw-r--r--rest-api-templates/res_ari_resource.c.mustache6
-rw-r--r--rest-api-templates/swagger_model.py19
-rw-r--r--rest-api-templates/transform.py9
7 files changed, 29 insertions, 26 deletions
diff --git a/rest-api-templates/api.wiki.mustache b/rest-api-templates/api.wiki.mustache
index ad12bb695..a51c3e6ce 100644
--- a/rest-api-templates/api.wiki.mustache
+++ b/rest-api-templates/api.wiki.mustache
@@ -5,7 +5,7 @@ h1. {{name_title}}
{{#apis}}
{{#operations}}
-| {{http_method}} | [{{wiki_path}}|#{{nickname}}] | {{#response_class}}{{#is_primitive}}{{name}}{{/is_primitive}}{{^is_primitive}}[{{wiki_name}}|{{wiki_prefix}} REST Data Models#{{singular_name}}]{{/is_primitive}}{{/response_class}} | {{summary}} |
+| {{http_method}} | [{{wiki_path}}|#{{nickname}}] | {{#response_class}}{{#is_primitive}}{{name}}{{/is_primitive}}{{^is_primitive}}[{{wiki_name}}|{{wiki_prefix}} REST Data Models#{{singular_name}}]{{/is_primitive}}{{/response_class}} | {{{summary}}} |
{{/operations}}
{{/apis}}
{{#apis}}
diff --git a/rest-api-templates/ari_resource.h.mustache b/rest-api-templates/ari_resource.h.mustache
index df075af35..c1d880d30 100644
--- a/rest-api-templates/ari_resource.h.mustache
+++ b/rest-api-templates/ari_resource.h.mustache
@@ -76,7 +76,7 @@ int ast_ari_{{c_name}}_{{c_nickname}}_parse_body(
{{/parse_body}}
/*!
- * \brief {{summary}}
+ * \brief {{{summary}}}
{{#notes}}
*
* {{{notes}}}
@@ -99,7 +99,7 @@ void ast_ari_{{c_name}}_{{c_nickname}}(struct ast_tcptls_session_instance *ser,
{{#is_websocket}}
/*!
- * \brief {{summary}}
+ * \brief {{{summary}}}
{{#notes}}
*
* {{{notes}}}
@@ -111,7 +111,7 @@ void ast_ari_{{c_name}}_{{c_nickname}}(struct ast_tcptls_session_instance *ser,
int ast_ari_websocket_{{c_name}}_{{c_nickname}}_init(void);
/*!
- * \brief {{summary}}
+ * \brief {{{summary}}}
{{#notes}}
*
* {{{notes}}}
diff --git a/rest-api-templates/asterisk_processor.py b/rest-api-templates/asterisk_processor.py
index 981294673..5f8dbb576 100644
--- a/rest-api-templates/asterisk_processor.py
+++ b/rest-api-templates/asterisk_processor.py
@@ -23,7 +23,7 @@ Asterisk RESTful HTTP binding code.
import os
import re
-from swagger_model import *
+from swagger_model import Stringify, SwaggerError, SwaggerPostProcessor
try:
from collections import OrderedDict
@@ -183,7 +183,7 @@ class AsteriskProcessor(SwaggerPostProcessor):
raise SwaggerError(
"Should not mix resources in one API declaration", context)
# root_path isn't needed any more
- resource_api.root_path = resource_api.root_path.children()[0]
+ resource_api.root_path = list(resource_api.root_path.children())[0]
if resource_api.name != resource_api.root_path.name:
raise SwaggerError(
"API declaration name should match", context)
@@ -206,10 +206,10 @@ class AsteriskProcessor(SwaggerPostProcessor):
def process_parameter(self, parameter, context):
if parameter.param_type == 'body':
- parameter.is_body_parameter = True;
+ parameter.is_body_parameter = True;
parameter.c_data_type = 'struct ast_json *'
else:
- parameter.is_body_parameter = False;
+ parameter.is_body_parameter = False;
if not parameter.data_type in self.type_mapping:
raise SwaggerError(
"Invalid parameter type %s" % parameter.data_type, context)
diff --git a/rest-api-templates/make_ari_stubs.py b/rest-api-templates/make_ari_stubs.py
index 0aba06d6d..a25773df4 100755
--- a/rest-api-templates/make_ari_stubs.py
+++ b/rest-api-templates/make_ari_stubs.py
@@ -16,19 +16,20 @@
# at the top of the source tree.
#
+from __future__ import print_function
import sys
try:
import pystache
except ImportError:
- print >> sys.stderr, "Pystache required. Please sudo pip install pystache."
+ print("Pystache required. Please sudo pip install pystache.", file=sys.stderr)
sys.exit(1)
import os.path
from asterisk_processor import AsteriskProcessor
from optparse import OptionParser
-from swagger_model import *
+from swagger_model import ResourceListing
from transform import Transform
TOPDIR = os.path.dirname(os.path.abspath(__file__))
diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache
index 67a04d898..85948fba1 100644
--- a/rest-api-templates/res_ari_resource.c.mustache
+++ b/rest-api-templates/res_ari_resource.c.mustache
@@ -55,7 +55,7 @@
#if defined(AST_DEVMODE)
#include "ari/ari_model_validators.h"
#endif
-{{^has_websocket}}
+{{#has_websocket}}
{{! Only include http_websocket if necessary. Otherwise we'll do a lot of
* unnecessary optional_api intialization, which makes optional_api harder
* to debug
@@ -278,7 +278,7 @@ static int load_module(void)
{{#apis}}
{{#operations}}
-{{#has_websocket}}
+{{#is_websocket}}
struct ast_websocket_protocol *protocol;
if (ast_ari_websocket_{{c_name}}_{{c_nickname}}_init() == -1) {
@@ -300,8 +300,6 @@ static int load_module(void)
}
protocol->session_attempted = ast_ari_{{c_name}}_{{c_nickname}}_ws_attempted_cb;
protocol->session_established = ast_ari_{{c_name}}_{{c_nickname}}_ws_established_cb;
-{{/has_websocket}}
-{{#is_websocket}}
res |= ast_websocket_server_add_protocol2({{full_name}}.ws_server, protocol);
{{/is_websocket}}
{{/operations}}
diff --git a/rest-api-templates/swagger_model.py b/rest-api-templates/swagger_model.py
index 3f729d8b5..50c5fb07b 100644
--- a/rest-api-templates/swagger_model.py
+++ b/rest-api-templates/swagger_model.py
@@ -26,6 +26,7 @@ missing, or have incorrect values).
See https://github.com/wordnik/swagger-core/wiki/API-Declaration for the spec.
"""
+from __future__ import print_function
import json
import os.path
import pprint
@@ -75,7 +76,7 @@ def compare_versions(lhs, rhs):
'''
lhs = [int(v) for v in lhs.split('.')]
rhs = [int(v) for v in rhs.split('.')]
- return cmp(lhs, rhs)
+ return (lhs > rhs) - (lhs < rhs)
class ParsingContext(object):
@@ -444,8 +445,7 @@ class Api(Stringify):
op_json = api_json.get('operations')
self.operations = [
Operation().load(j, processor, context) for j in op_json]
- self.has_websocket = \
- filter(lambda op: op.is_websocket, self.operations) != []
+ self.has_websocket = any(op.is_websocket for op in self.operations)
processor.process_api(self, context)
return self
@@ -611,7 +611,7 @@ class ApiDeclaration(Stringify):
except SwaggerError:
raise
except Exception as e:
- print >> sys.stderr, "Error: ", traceback.format_exc()
+ print("Error: ", traceback.format_exc(), file=sys.stderr)
raise SwaggerError(
"Error loading %s" % api_declaration_file, context, e)
@@ -624,8 +624,8 @@ class ApiDeclaration(Stringify):
.replace(".json", ".{format}")
if self.resource_path != expected_resource_path:
- print >> sys.stderr, \
- "%s != %s" % (self.resource_path, expected_resource_path)
+ print("%s != %s" % (self.resource_path, expected_resource_path),
+ file=sys.stderr)
raise SwaggerError("resourcePath has incorrect value", context)
return self
@@ -656,8 +656,7 @@ class ApiDeclaration(Stringify):
if api.path in paths:
raise SwaggerError("API with duplicated path: %s" % api.path, context)
paths.add(api.path)
- self.has_websocket = filter(lambda api: api.has_websocket,
- self.apis) == []
+ self.has_websocket = any(api.has_websocket for api in self.apis)
models = api_decl_json.get('models').items() or []
self.models = [Model().load(id, json, processor, context)
for (id, json) in models]
@@ -666,7 +665,7 @@ class ApiDeclaration(Stringify):
model_dict = dict((m.id, m) for m in self.models)
for m in self.models:
def link_subtype(name):
- res = model_dict.get(subtype)
+ res = model_dict.get(name)
if not res:
raise SwaggerError("%s has non-existing subtype %s",
m.id, name)
@@ -725,7 +724,7 @@ class ResourceListing(Stringify):
except SwaggerError:
raise
except Exception as e:
- print >> sys.stderr, "Error: ", traceback.format_exc()
+ print("Error: ", traceback.format_exc(), file=sys.stderr)
raise SwaggerError(
"Error loading %s" % resource_file, context, e)
diff --git a/rest-api-templates/transform.py b/rest-api-templates/transform.py
index c3a030064..88f7d2e67 100644
--- a/rest-api-templates/transform.py
+++ b/rest-api-templates/transform.py
@@ -21,6 +21,11 @@ import os.path
import pystache
import shutil
import tempfile
+import sys
+
+if sys.version_info[0] == 3:
+ def unicode(v):
+ return str(v)
class Transform(object):
@@ -52,10 +57,10 @@ class Transform(object):
dest_exists = os.path.exists(dest_file)
if dest_exists and not self.overwrite:
return
- with tempfile.NamedTemporaryFile() as out:
+ with tempfile.NamedTemporaryFile(mode='w+') as out:
out.write(renderer.render(self.template, model))
out.flush()
if not dest_exists or not filecmp.cmp(out.name, dest_file):
- print "Writing %s" % dest_file
+ print("Writing %s" % dest_file)
shutil.copyfile(out.name, dest_file)