Support Unicode for reporting
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/756356ab Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/756356ab Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/756356ab Branch: refs/heads/ARIA-1-parser-test-suite Commit: 756356ab61e6418a96a24a7d3b9077454aa295ff Parents: d5fe4f7 Author: Tal Liron <[email protected]> Authored: Mon Sep 11 16:50:53 2017 -0500 Committer: Tal Liron <[email protected]> Committed: Mon Sep 11 16:50:53 2017 -0500 ---------------------------------------------------------------------- aria/orchestrator/topology/instance_handler.py | 36 ++-- aria/orchestrator/topology/template_handler.py | 12 +- aria/parser/consumption/context.py | 6 +- aria/parser/consumption/inputs.py | 2 +- aria/parser/loading/file.py | 14 +- aria/parser/loading/location.py | 6 +- aria/parser/loading/request.py | 14 +- aria/parser/loading/uri.py | 2 +- aria/parser/presentation/field_validators.py | 6 +- aria/parser/presentation/fields.py | 109 ++++++----- aria/parser/presentation/presentation.py | 5 +- aria/parser/presentation/presenter.py | 8 +- aria/parser/presentation/utils.py | 24 +-- aria/parser/reading/jinja.py | 4 +- aria/parser/reading/json.py | 2 +- aria/parser/reading/locator.py | 20 +- aria/parser/reading/reader.py | 4 +- aria/parser/reading/source.py | 2 +- aria/parser/reading/yaml.py | 6 +- aria/parser/validation/issue.py | 18 +- .../simple_v1_0/data_types.py | 34 ++-- .../simple_v1_0/modeling/__init__.py | 8 +- .../simple_v1_0/modeling/capabilities.py | 6 +- .../simple_v1_0/modeling/data_types.py | 47 ++--- .../simple_v1_0/modeling/functions.py | 60 +++--- .../simple_v1_0/modeling/interfaces.py | 48 ++--- .../simple_v1_0/modeling/parameters.py | 8 +- .../simple_v1_0/modeling/requirements.py | 49 ++--- .../modeling/substitution_mappings.py | 28 +-- .../simple_v1_0/presentation/field_getters.py | 2 +- .../presentation/field_validators.py | 44 ++--- .../templates/test_policy_template.py | 186 +++++++++++++++++++ .../templates/test_topology_template.py | 18 +- 33 files changed, 522 insertions(+), 316 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/orchestrator/topology/instance_handler.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/topology/instance_handler.py b/aria/orchestrator/topology/instance_handler.py index 51f26c6..3449414 100644 --- a/aria/orchestrator/topology/instance_handler.py +++ b/aria/orchestrator/topology/instance_handler.py @@ -134,7 +134,7 @@ class Node(common.ActorHandlerBase): def validate(self, **kwargs): if len(self._model.name) > context.ID_MAX_LENGTH: self._topology.report( - '"{0}" has an ID longer than the limit of {1:d} characters: {2:d}'.format( + u'"{0}" has an ID longer than the limit of {1:d} characters: {2:d}'.format( self._model.name, context.ID_MAX_LENGTH, len(self._model.name)), level=self._topology.Issue.BETWEEN_INSTANCES) @@ -170,11 +170,11 @@ class Node(common.ActorHandlerBase): for capability in self._model.capabilities.itervalues(): if not capability.has_enough_relationships: self._topology.report( - 'capability "{0}" of node "{1}" requires at least {2:d} ' - 'relationships but has {3:d}'.format(capability.name, - self._model.name, - capability.min_occurrences, - capability.occurrences), + u'capability "{0}" of node "{1}" requires at least {2:d} ' + u'relationships but has {3:d}'.format(capability.name, + self._model.name, + capability.min_occurrences, + capability.occurrences), level=self._topology.Issue.BETWEEN_INSTANCES) satisfied = False return satisfied @@ -197,8 +197,8 @@ class Node(common.ActorHandlerBase): satisfied = self._satisfy_capability( target_node_capability, target_node_template, requirement_template) else: - self._topology.report('requirement "{0}" of node "{1}" has no target node template'. - format(requirement_template.name, self._model.name), + self._topology.report(u'requirement "{0}" of node "{1}" has no target node template' + .format(requirement_template.name, self._model.name), level=self._topology.Issue.BETWEEN_INSTANCES) satisfied = False return satisfied @@ -237,16 +237,16 @@ class Node(common.ActorHandlerBase): return True else: self._topology.report( - 'requirement "{0}" of node "{1}" targets node ' - 'template "{2}" but its instantiated nodes do not ' - 'have enough capacity'.format( + u'requirement "{0}" of node "{1}" targets node ' + u'template "{2}" but its instantiated nodes do not ' + u'have enough capacity'.format( requirement_template.name, self._model.name, target_node_template.name), level=self._topology.Issue.BETWEEN_INSTANCES) return False else: self._topology.report( - 'requirement "{0}" of node "{1}" targets node template ' - '"{2}" but it has no instantiated nodes'.format( + u'requirement "{0}" of node "{1}" targets node template ' + u'"{2}" but it has no instantiated nodes'.format( requirement_template.name, self._model.name, target_node_template.name), level=self._topology.Issue.BETWEEN_INSTANCES) return False @@ -258,8 +258,8 @@ class Node(common.ActorHandlerBase): if not self._model.node_template.is_target_node_template_valid( requirement_template.target_node_template): self._topology.report( - 'requirement "{0}" of node template "{1}" is for node ' - 'template "{2}" but it does not match constraints'.format( + u'requirement "{0}" of node template "{1}" is for node ' + u'template "{2}" but it does not match constraints'.format( requirement_template.name, requirement_template.target_node_template.name, self._model.node_template.name), @@ -418,7 +418,7 @@ class Operation(common.ActorHandlerBase): self._model.arguments.keys()) if used_reserved_names: self._topology.report( - 'using reserved arguments in operation "{0}": {1}'.format( + u'using reserved arguments in operation "{0}": {1}'.format( self._model.name, formatting.string_list_as_string(used_reserved_names)), level=self._topology.Issue.EXTERNAL) @@ -562,8 +562,8 @@ class SubstitutionMapping(common.InstanceHandlerBase): def validate(self, **_): if (self._model.capability is None) and (self._model.requirement_template is None): self._topology.report( - 'mapping "{0}" refers to neither capability nor a requirement' - ' in node: {1}'.format( + u'mapping "{0}" refers to neither capability nor a requirement' + u' in node: {1}'.format( self._model.name, formatting.safe_repr(self._model.node_style.name)), level=self._topology.Issue.BETWEEN_TYPES) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/orchestrator/topology/template_handler.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/topology/template_handler.py b/aria/orchestrator/topology/template_handler.py index a84a988..86a60f5 100644 --- a/aria/orchestrator/topology/template_handler.py +++ b/aria/orchestrator/topology/template_handler.py @@ -69,7 +69,7 @@ class ServiceTemplate(common.TemplateHandlerBase): plugin = plugin_specification.plugin service.plugins[plugin.name] = plugin else: - self._topology.report('specified plugin not found: {0}'.format( + self._topology.report(u'specified plugin not found: {0}'.format( plugin_specification.name), level=self._topology.Issue.EXTERNAL) service.meta_data = self._topology.instantiate(self._model.meta_data) @@ -117,8 +117,8 @@ class ServiceTemplate(common.TemplateHandlerBase): scaling['default_instances'] > scaling['max_instances'] ]): self._topology.report( - 'invalid scaling parameters for node template "{0}": min={min_instances}, max=' - '{max_instances}, default={default_instances}'.format(self._model.name, **scaling), + u'invalid scaling parameters for node template "{0}": min={min_instances}, max=' + u'{max_instances}, default={default_instances}'.format(self._model.name, **scaling), level=self._topology.Issue.BETWEEN_TYPES) return scaling @@ -475,7 +475,7 @@ class SubstitutionTemplateMapping(common.TemplateHandlerBase): nodes = node_template.nodes if len(nodes) == 0: self._topology.report( - 'mapping "{0}" refers to node template "{1}" but there are no node instances'. + u'mapping "{0}" refers to node template "{1}" but there are no node instances'. format(self._model.mapped_name, self._model.node_template.name), level=self._topology.Issue.BETWEEN_INSTANCES) return None @@ -493,8 +493,8 @@ class SubstitutionTemplateMapping(common.TemplateHandlerBase): def validate(self, **_): if self._model.capability_template is None and self._model.requirement_template is None: self._topology.report( - 'mapping "{0}" refers to neither capability nor a requirement ' - 'in node template: {1}'.format( + u'mapping "{0}" refers to neither capability nor a requirement ' + u'in node template: {1}'.format( self._model.name, formatting.safe_repr(self._model.node_template.name)), level=self._topology.Issue.BETWEEN_TYPES) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/consumption/context.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/context.py b/aria/parser/consumption/context.py index 9164984..91807a4 100644 --- a/aria/parser/consumption/context.py +++ b/aria/parser/consumption/context.py @@ -83,14 +83,14 @@ class ConsumptionContext(object): try: self.out.write(string) except UnicodeEncodeError: - self.out.write(string.encode('utf8')) + self.out.write(string.encode('utf-8')) def has_arg_switch(self, name): - name = '--%s' % name + name = '--{0}'.format(name) return name in self.args def get_arg_value(self, name, default=None): - name = '--%s=' % name + name = '--{0}='.format(name) for arg in self.args: if arg.startswith(name): return arg[len(name):] http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/consumption/inputs.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/inputs.py b/aria/parser/consumption/inputs.py index fe7e192..55f6e92 100644 --- a/aria/parser/consumption/inputs.py +++ b/aria/parser/consumption/inputs.py @@ -46,7 +46,7 @@ class Inputs(Consumer): if not isinstance(inputs, dict): self.context.validation.report( - 'Inputs consumer: inputs are not a dict: %s' % safe_repr(inputs)) + u'Inputs consumer: inputs are not a dict: {0}'.format(safe_repr(inputs))) return for name, value in inputs.iteritems(): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/loading/file.py ---------------------------------------------------------------------- diff --git a/aria/parser/loading/file.py b/aria/parser/loading/file.py index a02bd69..ba1f155 100644 --- a/aria/parser/loading/file.py +++ b/aria/parser/loading/file.py @@ -38,27 +38,27 @@ class FileTextLoader(Loader): self._file = codecs.open(self.path, mode='r', encoding=self.encoding, buffering=1) except IOError as e: if e.errno == 2: - raise DocumentNotFoundException('file not found: "%s"' % self.path, cause=e) + raise DocumentNotFoundException(u'file not found: "{0}"'.format(self.path), cause=e) else: - raise LoaderException('file I/O error: "%s"' % self.path, cause=e) + raise LoaderException(u'file I/O error: "{0}"'.format(self.path), cause=e) except Exception as e: - raise LoaderException('file error: "%s"' % self.path, cause=e) + raise LoaderException(u'file error: "{0}"'.format(self.path), cause=e) def close(self): if self._file is not None: try: self._file.close() except IOError as e: - raise LoaderException('file I/O error: "%s"' % self.path, cause=e) + raise LoaderException(u'file I/O error: "{0}"'.format(self.path), cause=e) except Exception as e: - raise LoaderException('file error: "%s"' % self.path, cause=e) + raise LoaderException(u'file error: "{0}"'.format(self.path), cause=e) def load(self): if self._file is not None: try: return self._file.read() except IOError as e: - raise LoaderException('file I/O error: "%s"' % self.path, cause=e) + raise LoaderException(u'file I/O error: "{0}"'.format(self.path), cause=e) except Exception as e: - raise LoaderException('file error %s' % self.path, cause=e) + raise LoaderException(u'file error {0}'.format(self.path), cause=e) return None http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/loading/location.py ---------------------------------------------------------------------- diff --git a/aria/parser/loading/location.py b/aria/parser/loading/location.py index 902e856..99f6bac 100644 --- a/aria/parser/loading/location.py +++ b/aria/parser/loading/location.py @@ -54,8 +54,8 @@ class UriLocation(Location): def prefix(self): prefix = os.path.dirname(self.uri) if prefix and (as_file(prefix) is None): - # Yes, it's weird, but dirname handles URIs, - # too: http://stackoverflow.com/a/35616478/849021 + # Yes, it's weird, but dirname handles URIs, too: + # http://stackoverflow.com/a/35616478/849021 # We just need to massage it with a trailing slash prefix += '/' return prefix @@ -79,4 +79,4 @@ class LiteralLocation(Location): return isinstance(location, LiteralLocation) and (location.content == self.content) def __str__(self): - return '<%s>' % self.name + return u'<{0}>'.format(self.name) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/loading/request.py ---------------------------------------------------------------------- diff --git a/aria/parser/loading/request.py b/aria/parser/loading/request.py index a809347..5f12055 100644 --- a/aria/parser/loading/request.py +++ b/aria/parser/loading/request.py @@ -57,19 +57,19 @@ class RequestLoader(Loader): try: self._response = SESSION.get(self.uri, headers=self.headers) except InvalidSchema as e: - raise DocumentNotFoundException('document not found: "%s"' % self.uri, cause=e) + raise DocumentNotFoundException(u'document not found: "{0}"'.format(self.uri), cause=e) except ConnectionError as e: - raise LoaderException('request connection error: "%s"' % self.uri, cause=e) + raise LoaderException(u'request connection error: "{0}"'.format(self.uri), cause=e) except Exception as e: - raise LoaderException('request error: "%s"' % self.uri, cause=e) + raise LoaderException(u'request error: "{0}"'.format(self.uri), cause=e) status = self._response.status_code if status == 404: self._response = None - raise DocumentNotFoundException('document not found: "%s"' % self.uri) + raise DocumentNotFoundException(u'document not found: "{0}"'.format(self.uri)) elif status != 200: self._response = None - raise LoaderException('request error %d: "%s"' % (status, self.uri)) + raise LoaderException(u'request error {0:d}: "{1}"'.format(status, self.uri)) class RequestTextLoader(RequestLoader): @@ -81,8 +81,8 @@ class RequestTextLoader(RequestLoader): if self._response is not None: try: if self._response.encoding is None: - self._response.encoding = 'utf8' + self._response.encoding = 'utf-8' return self._response.text except Exception as e: - raise LoaderException('request error: %s' % self.uri, cause=e) + raise LoaderException(u'request error: {0}'.format(self.uri), cause=e) return None http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/loading/uri.py ---------------------------------------------------------------------- diff --git a/aria/parser/loading/uri.py b/aria/parser/loading/uri.py index a5a18e6..cff7a46 100644 --- a/aria/parser/loading/uri.py +++ b/aria/parser/loading/uri.py @@ -76,7 +76,7 @@ class UriTextLoader(Loader): return except DocumentNotFoundException: pass - raise DocumentNotFoundException('document not found at URI: "%s"' % self.location) + raise DocumentNotFoundException(u'document not found at URI: "{0}"'.format(self.location)) def close(self): if self._loader is not None: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/presentation/field_validators.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/field_validators.py b/aria/parser/presentation/field_validators.py index 3da01e3..bd7bfdd 100644 --- a/aria/parser/presentation/field_validators.py +++ b/aria/parser/presentation/field_validators.py @@ -31,7 +31,7 @@ def not_negative_validator(field, presentation, context): field.default_validate(presentation, context) value = getattr(presentation, field.name) if (value is not None) and (value < 0): - context.validation.report('field "{0}" is negative: {1}' + context.validation.report(u'field "{0}" is negative: {1}' .format(field.name, safe_repr(value)), locator=presentation._get_child_locator(field.name), level=Issue.FIELD) @@ -118,8 +118,8 @@ def list_length_validator(length): values = getattr(presentation, field.name) if isinstance(values, list): if len(values) != length: - context.validation.report('field "{0}" does not have exactly {1:d} elements in ' - '"{2}": {3}' + context.validation.report(u'field "{0}" does not have exactly {1:d} elements in ' + u'"{2}": {3}' .format(field.name, length, presentation._fullname, safe_repr(values)), locator=presentation._get_child_locator(field.name), http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/presentation/fields.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/fields.py b/aria/parser/presentation/fields.py index dc8894b..f9ecbbc 100644 --- a/aria/parser/presentation/fields.py +++ b/aria/parser/presentation/fields.py @@ -338,7 +338,7 @@ def has_fields_getitem(self, key): if not isinstance(key, basestring): raise TypeError('key must be a string') if key not in self.__class__.FIELDS: - raise KeyError('no \'%s\' property' % key) + raise KeyError('no \'{0}\' property'.format(key)) return getattr(self, key) @@ -346,7 +346,7 @@ def has_fields_setitem(self, key, value): if not isinstance(key, basestring): raise TypeError('key must be a string') if key not in self.__class__.FIELDS: - raise KeyError('no \'%s\' property' % key) + raise KeyError('no \'{0}\' property'.format(key)) return setattr(self, key, value) @@ -354,7 +354,7 @@ def has_fields_delitem(self, key): if not isinstance(key, basestring): raise TypeError('key must be a string') if key not in self.__class__.FIELDS: - raise KeyError('no \'%s\' property' % key) + raise KeyError('no \'{0}\' property'.format(key)) return setattr(self, key, None) @@ -389,7 +389,7 @@ class Field(object): @property def full_name(self): - return 'field "%s" in "%s"' % (self.name, full_type_name(self.container_cls)) + return u'field "{0}" in "{1}"'.format(self.name, full_type_name(self.container_cls)) @property def full_cls_name(self): @@ -420,7 +420,7 @@ class Field(object): if value is None: return - dumper = getattr(self, '_dump_%s' % self.field_variant) + dumper = getattr(self, '_dump_{0}'.format(self.field_variant)) dumper(context, value) def default_get(self, presentation, context): @@ -457,8 +457,8 @@ class Field(object): if value is None: if self.required: - raise InvalidValueError('required %s does not have a value' % self.full_name, - locator=self.get_locator(raw)) + raise InvalidValueError(u'required {0} does not have a value' + .format(self.full_name, locator=self.get_locator(raw))) else: return None @@ -466,9 +466,9 @@ class Field(object): if self.allowed is not None: if value not in self.allowed: - raise InvalidValueError('%s is not %s' - % (self.full_name, ' or '.join([safe_repr(v) - for v in self.allowed])), + raise InvalidValueError(u'{0} is not {1}' + .format(self.full_name, + ' or '.join([safe_repr(v) for v in self.allowed])), locator=self.get_locator(raw)) # Handle get according to variant @@ -477,9 +477,9 @@ class Field(object): if getter is None: locator = self.get_locator(raw) - location = (' @%s' % locator) if locator is not None else '' - raise AttributeError('%s has unsupported field variant: "%s"%s' - % (self.full_name, self.field_variant, location)) + location = (u' @{0}'.format(locator)) if locator is not None else '' + raise AttributeError(u'{0} has unsupported field variant: "{1}"{2}' + .format(self.full_name, self.field_variant, location)) return getter(presentation, raw, value, context) @@ -563,21 +563,23 @@ class Field(object): try: return self._coerce_primitive(value, context) except ValueError as e: - raise InvalidValueError('%s is not a valid "%s": %s' % - (self.full_name, self.full_cls_name, safe_repr(value)), + raise InvalidValueError(u'{0} is not a valid "{1}": {2}' + .format(self.full_name, self.full_cls_name, + safe_repr(value)), locator=self.get_locator(raw), cause=e) return value def _dump_primitive(self, context, value): if hasattr(value, 'as_raw'): value = as_raw(value) - puts('%s: %s' % (self.name, context.style.literal_style(value))) + puts(u'{0}: {1}'.format(self.name, context.style.literal_style(value))) # primitive list def _get_primitive_list(self, presentation, raw, value, context): if not isinstance(value, list): - raise InvalidValueError('%s is not a list: %s' % (self.full_name, safe_repr(value)), + raise InvalidValueError(u'{0} is not a list: {1}' + .format(self.full_name, safe_repr(value)), locator=self.get_locator(raw)) primitive_list = value if self.cls is not None: @@ -589,23 +591,23 @@ class Field(object): try: primitive = self._coerce_primitive(primitive, context) except ValueError as e: - raise InvalidValueError('%s is not a list of "%s": element %d is %s' - % (self.full_name, - self.full_cls_name, - i, - safe_repr(primitive)), + raise InvalidValueError(u'{0} is not a list of "{1}": element {2:d} is {3}' + .format(self.full_name, + self.full_cls_name, + i, + safe_repr(primitive)), locator=self.get_locator(raw), cause=e) if primitive in primitive_list: - raise InvalidValueError('%s has a duplicate "%s": %s' - % (self.full_name, - self.full_cls_name, - safe_repr(primitive)), + raise InvalidValueError(u'{0} has a duplicate "{1}": {2}' + .format(self.full_name, + self.full_cls_name, + safe_repr(primitive)), locator=self.get_locator(raw)) primitive_list.append(primitive) return FrozenList(primitive_list) def _dump_primitive_list(self, context, value): - puts('%s:' % self.name) + puts(u'{0}:'.format(self.name)) with context.style.indent(): for primitive in value: if hasattr(primitive, 'as_raw'): @@ -616,7 +618,8 @@ class Field(object): def _get_primitive_dict(self, presentation, raw, value, context): if not isinstance(value, dict): - raise InvalidValueError('%s is not a dict: %s' % (self.full_name, safe_repr(value)), + raise InvalidValueError(u'{0} is not a dict: {1}' + .format(self.full_name, safe_repr(value)), locator=self.get_locator(raw)) primitive_dict = value if self.cls is not None: @@ -627,14 +630,16 @@ class Field(object): try: primitive_dict[k] = self._coerce_primitive(v, context) except ValueError as e: - raise InvalidValueError('%s is not a dict of "%s" values: entry "%d" is %s' - % (self.full_name, self.full_cls_name, k, safe_repr(v)), + raise InvalidValueError(u'{0} is not a dict of "{1}" values: entry "{2:d}" ' + u'is {3}' + .format(self.full_name, self.full_cls_name, k, + safe_repr(v)), locator=self.get_locator(raw), cause=e) return FrozenDict(primitive_dict) def _dump_primitive_dict(self, context, value): - puts('%s:' % self.name) + puts(u'{0}:'.format(self.name)) with context.style.indent(): for v in value.itervalues(): if hasattr(v, 'as_raw'): @@ -647,13 +652,13 @@ class Field(object): try: return self.cls(name=self.name, raw=value, container=presentation) except TypeError as e: - raise InvalidValueError('%s cannot not be initialized to an instance of "%s": %s' - % (self.full_name, self.full_cls_name, safe_repr(value)), + raise InvalidValueError(u'{0} cannot not be initialized to an instance of "{1}": {2}' + .format(self.full_name, self.full_cls_name, safe_repr(value)), cause=e, locator=self.get_locator(raw)) def _dump_object(self, context, value): - puts('%s:' % self.name) + puts(u'{0}:'.format(self.name)) with context.style.indent(): if hasattr(value, '_dump'): value._dump(context) @@ -662,13 +667,13 @@ class Field(object): def _get_object_list(self, presentation, raw, value, context): if not isinstance(value, list): - raise InvalidValueError('%s is not a list: %s' - % (self.full_name, safe_repr(value)), + raise InvalidValueError(u'{0} is not a list: {1}' + .format(self.full_name, safe_repr(value)), locator=self.get_locator(raw)) return FrozenList((self.cls(name=self.name, raw=v, container=presentation) for v in value)) def _dump_object_list(self, context, value): - puts('%s:' % self.name) + puts(u'{0}:'.format(self.name)) with context.style.indent(): for v in value: if hasattr(v, '_dump'): @@ -678,13 +683,14 @@ class Field(object): def _get_object_dict(self, presentation, raw, value, context): if not isinstance(value, dict): - raise InvalidValueError('%s is not a dict: %s' % (self.full_name, safe_repr(value)), + raise InvalidValueError(u'{0} is not a dict: {1}' + .format(self.full_name, safe_repr(value)), locator=self.get_locator(raw)) return FrozenDict(((k, self.cls(name=k, raw=v, container=presentation)) for k, v in value.iteritems())) def _dump_object_dict(self, context, value): - puts('%s:' % self.name) + puts(u'{0}:'.format(self.name)) with context.style.indent(): for v in value.itervalues(): if hasattr(v, '_dump'): @@ -694,26 +700,27 @@ class Field(object): def _get_sequenced_object_list(self, presentation, raw, value, context): if not isinstance(value, list): - raise InvalidValueError('%s is not a sequenced list (a list of dicts, ' - 'each with exactly one key): %s' - % (self.full_name, safe_repr(value)), + raise InvalidValueError(u'{0} is not a sequenced list (a list of dicts, ' + u'each with exactly one key): {1}' + .format(self.full_name, safe_repr(value)), locator=self.get_locator(raw)) sequence = [] for v in value: if not isinstance(v, dict): - raise InvalidValueError('%s list elements are not all dicts with ' - 'exactly one key: %s' % (self.full_name, safe_repr(value)), + raise InvalidValueError(u'{0} list elements are not all dicts with ' + u'exactly one key: {1}' + .format(self.full_name, safe_repr(value)), locator=self.get_locator(raw)) if len(v) != 1: - raise InvalidValueError('%s list elements do not all have exactly one key: %s' - % (self.full_name, safe_repr(value)), + raise InvalidValueError(u'{0} list elements do not all have exactly one key: {1}' + .format(self.full_name, safe_repr(value)), locator=self.get_locator(raw)) key, value = v.items()[0] sequence.append((key, self.cls(name=key, raw=value, container=presentation))) return FrozenList(sequence) def _dump_sequenced_object_list(self, context, value): - puts('%s:' % self.name) + puts(u'{0}:'.format(self.name)) for _, v in value: if hasattr(v, '_dump'): v._dump(context) @@ -732,10 +739,10 @@ class Field(object): try: primitive_dict[k] = self._coerce_primitive(v, context) except ValueError as e: - raise InvalidValueError('%s is not a dict of "%s" values:' - ' entry "%s" is %s' - % (self.full_name, self.full_cls_name, - k, safe_repr(v)), + raise InvalidValueError(u'{0} is not a dict of "{1}" values:' + u' entry "{2}" is {3}' + .format(self.full_name, self.full_cls_name, + k, safe_repr(v)), locator=self.get_locator(raw), cause=e) return FrozenDict(primitive_dict) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/presentation/presentation.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/presentation.py b/aria/parser/presentation/presentation.py index 3f9f86d..1e1e4bb 100644 --- a/aria/parser/presentation/presentation.py +++ b/aria/parser/presentation/presentation.py @@ -233,8 +233,9 @@ class AsIsPresentation(PresentationBase): try: validate_primitive(self._raw, self.cls, context.validation.allow_primitive_coersion) except ValueError as e: - context.validation.report('"%s" is not a valid "%s": %s' - % (self._fullname, self._full_cls_name, safe_repr(self._raw)), + context.validation.report(u'"{0}" is not a valid "{1}": {2}' + .format(self._fullname, self._full_cls_name, + safe_repr(self._raw)), locator=self._locator, level=Issue.FIELD, exception=e) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/presentation/presenter.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/presenter.py b/aria/parser/presentation/presenter.py index 9fd296f..d2f3292 100644 --- a/aria/parser/presentation/presenter.py +++ b/aria/parser/presentation/presenter.py @@ -41,10 +41,10 @@ class Presenter(Presentation): if tosca_definitions_version is not None \ and tosca_definitions_version not in self.__class__.ALLOWED_IMPORTED_DSL_VERSIONS: context.validation.report( - 'import "tosca_definitions_version" is not one of %s: %s' - % (' or '.join([safe_repr(v) - for v in self.__class__.ALLOWED_IMPORTED_DSL_VERSIONS]), - presentation.service_template.tosca_definitions_version), + u'import "tosca_definitions_version" is not one of {0}: {1}' + .format(u' or '.join([safe_repr(v) + for v in self.__class__.ALLOWED_IMPORTED_DSL_VERSIONS]), + presentation.service_template.tosca_definitions_version), locator=presentation._get_child_locator('inputs'), level=Issue.BETWEEN_TYPES) return False http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/presentation/utils.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/utils.py b/aria/parser/presentation/utils.py index f0fd390..5041aa6 100644 --- a/aria/parser/presentation/utils.py +++ b/aria/parser/presentation/utils.py @@ -68,7 +68,7 @@ def validate_primitive(value, cls, coerce=False): if coerce: value = cls(value) else: - raise ValueError('not a "%s": %s' % (full_type_name(cls), safe_repr(value))) + raise ValueError(u'not a "{0}": {1}'.format(full_type_name(cls), safe_repr(value))) return value @@ -78,7 +78,8 @@ def validate_no_short_form(context, presentation): """ if not hasattr(presentation, 'SHORT_FORM_FIELD') and not isinstance(presentation._raw, dict): - context.validation.report('short form not allowed for field "%s"' % presentation._fullname, + context.validation.report(u'short form not allowed for field "{0}"' + .format(presentation._fullname), locator=presentation._locator, level=Issue.BETWEEN_FIELDS) @@ -94,8 +95,8 @@ def validate_no_unknown_fields(context, presentation): and hasattr(presentation, 'FIELDS'): for k in presentation._raw: if k not in presentation.FIELDS: - context.validation.report('field "%s" is not supported in "%s"' - % (k, presentation._fullname), + context.validation.report(u'field "{0}" is not supported in "{1}"' + .format(k, presentation._fullname), locator=presentation._get_child_locator(k), level=Issue.BETWEEN_FIELDS) @@ -161,27 +162,28 @@ def get_parent_presentation(context, presentation, *types_dict_names): def report_issue_for_unknown_type(context, presentation, type_name, field_name, value=None): if value is None: value = getattr(presentation, field_name) - context.validation.report('"%s" refers to an unknown %s in "%s": %s' - % (field_name, type_name, presentation._fullname, safe_repr(value)), + context.validation.report(u'"{0}" refers to an unknown {1} in "{2}": {3}' + .format(field_name, type_name, presentation._fullname, + safe_repr(value)), locator=presentation._get_child_locator(field_name), level=Issue.BETWEEN_TYPES) def report_issue_for_parent_is_self(context, presentation, field_name): - context.validation.report('parent type of "%s" is self' % presentation._fullname, + context.validation.report(u'parent type of "{0}" is self'.format(presentation._fullname), locator=presentation._get_child_locator(field_name), level=Issue.BETWEEN_TYPES) def report_issue_for_unknown_parent_type(context, presentation, field_name): - context.validation.report('unknown parent type "%s" in "%s"' - % (getattr(presentation, field_name), presentation._fullname), + context.validation.report(u'unknown parent type "{0}" in "{1}"' + .format(getattr(presentation, field_name), presentation._fullname), locator=presentation._get_child_locator(field_name), level=Issue.BETWEEN_TYPES) def report_issue_for_circular_type_hierarchy(context, presentation, field_name): - context.validation.report('"%s" of "%s" creates a circular type hierarchy' - % (getattr(presentation, field_name), presentation._fullname), + context.validation.report(u'"{0}" of "{1}" creates a circular type hierarchy' + .format(getattr(presentation, field_name), presentation._fullname), locator=presentation._get_child_locator(field_name), level=Issue.BETWEEN_TYPES) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/reading/jinja.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/jinja.py b/aria/parser/reading/jinja.py index 687317a..623103a 100644 --- a/aria/parser/reading/jinja.py +++ b/aria/parser/reading/jinja.py @@ -36,7 +36,7 @@ class JinjaReader(Reader): def read(self): data = self.load() try: - data = str(data) + data = unicode(data) template = Template(data) literal = template.render(CONTEXT) # TODO: might be useful to write the literal result to a file for debugging @@ -52,4 +52,4 @@ class JinjaReader(Reader): self.context, LiteralLocation(literal), LiteralLoader(literal)) return next_reader.read() except Exception as e: - raise ReaderSyntaxError('Jinja: %s' % e, cause=e) + raise ReaderSyntaxError(u'Jinja: {0}'.format(e), cause=e) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/reading/json.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/json.py b/aria/parser/reading/json.py index d144f80..d02aeee 100644 --- a/aria/parser/reading/json.py +++ b/aria/parser/reading/json.py @@ -30,4 +30,4 @@ class JsonReader(Reader): data = unicode(data) return json.loads(data, object_pairs_hook=OrderedDict) except Exception as e: - raise ReaderSyntaxError('JSON: %s' % e, cause=e) + raise ReaderSyntaxError(u'JSON: {0}'.format(e), cause=e) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/reading/locator.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/locator.py b/aria/parser/reading/locator.py index 57b4d50..63f4735 100644 --- a/aria/parser/reading/locator.py +++ b/aria/parser/reading/locator.py @@ -73,23 +73,23 @@ class Locator(object): wrapped, raw_element = wrap(raw_element) if wrapped: raw[i] = raw_element - child_path = '%s.%d' % (path, i) if path else str(i) + child_path = u'{0}.{1:d}'.format(path, i) if path else unicode(i) try: self.children[i].link(raw_element, child_path) except KeyError: - raise ValueError('location map does not match agnostic raw data: %s' % - child_path) + raise ValueError('location map does not match agnostic raw data: {0}' + .format(child_path)) elif isinstance(raw, dict): for k, raw_element in raw.iteritems(): wrapped, raw_element = wrap(raw_element) if wrapped: raw[k] = raw_element - child_path = '%s.%s' % (path, k) if path else k + child_path = u'{0}.{1}'.format(path, k) if path else k try: self.children[k].link(raw_element, child_path) except KeyError: - raise ValueError('location map does not match agnostic raw data: %s' % - child_path) + raise ValueError('location map does not match agnostic raw data: {0}' + .format(child_path)) def merge(self, locator): if isinstance(self.children, dict) and isinstance(locator.children, dict): @@ -101,10 +101,10 @@ class Locator(object): def dump(self, key=None): if key: - puts('%s "%s":%d:%d' % - (Colored.red(key), Colored.blue(self.location), self.line, self.column)) + puts(u'{0} "{1}":{2:d}:{3:d}' + .format(Colored.red(key), Colored.blue(self.location), self.line, self.column)) else: - puts('"%s":%d:%d' % (Colored.blue(self.location), self.line, self.column)) + puts(u'"{0}":{1:d}:{2:d}'.format(Colored.blue(self.location), self.line, self.column)) if isinstance(self.children, list): with indent(2): for loc in self.children: @@ -116,4 +116,4 @@ class Locator(object): def __str__(self): # Should be in same format as Issue.locator_as_str - return '"%s":%d:%d' % (self.location, self.line, self.column) + return u'"{0}":{1:d}:{2:d}'.format(self.location, self.line, self.column) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/reading/reader.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/reader.py b/aria/parser/reading/reader.py index 1a29f11..c4eedbd 100644 --- a/aria/parser/reading/reader.py +++ b/aria/parser/reading/reader.py @@ -32,12 +32,12 @@ class Reader(object): with self.context._locations: for location in self.context._locations: if location.is_equivalent(loader.location): - raise AlreadyReadException('already read: %s' % loader.location) + raise AlreadyReadException(u'already read: {0}'.format(loader.location)) self.context._locations.append(loader.location) data = loader.load() if data is None: - raise ReaderException('loader did not provide data: %s' % loader) + raise ReaderException(u'loader did not provide data: {0}'.format(loader)) return data def read(self): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/reading/source.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/source.py b/aria/parser/reading/source.py index 6fff2f6..77cad12 100644 --- a/aria/parser/reading/source.py +++ b/aria/parser/reading/source.py @@ -32,7 +32,7 @@ class ReaderSource(object): @staticmethod def get_reader(context, location, loader): # pylint: disable=unused-argument - raise ReaderNotFoundError('location: %s' % location) + raise ReaderNotFoundError(u'location: {0}'.format(location)) class DefaultReaderSource(ReaderSource): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/reading/yaml.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/yaml.py b/aria/parser/reading/yaml.py index 0148d3a..f5a9d6f 100644 --- a/aria/parser/reading/yaml.py +++ b/aria/parser/reading/yaml.py @@ -106,12 +106,12 @@ class YamlReader(Reader): line = e.problem_mark.line column = e.problem_mark.column snippet = e.problem_mark.get_snippet() - raise ReaderSyntaxError('YAML %s: %s %s' % - (e.__class__.__name__, problem, context), + raise ReaderSyntaxError(u'YAML {0}: {1} {2}' + .format(e.__class__.__name__, problem, context), location=self.loader.location, line=line, column=column, snippet=snippet, cause=e) except Exception as e: - raise ReaderSyntaxError('YAML: %s' % e, cause=e) + raise ReaderSyntaxError(u'YAML: {0}'.format(e), cause=e) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/aria/parser/validation/issue.py ---------------------------------------------------------------------- diff --git a/aria/parser/validation/issue.py b/aria/parser/validation/issue.py index cc68737..e26408e 100644 --- a/aria/parser/validation/issue.py +++ b/aria/parser/validation/issue.py @@ -102,33 +102,33 @@ class Issue(object): if self.location is not None: if self.line is not None: if self.column is not None: - return '"%s":%d:%d' % (self.location, self.line, self.column) + return u'"{0}":{1:d}:{2:d}'.format(self.location, self.line, self.column) else: - return '"%s":%d' % (self.location, self.line) + return u'"{0}":{1:d}'.format(self.location, self.line) else: - return '"%s"' % self.location + return u'"{0}"'.format(self.location) else: return None @property def heading_as_str(self): - return '%d: %s' % (self.level, self.message) + return u'{0:d}: {1}'.format(self.level, self.message) @property def details_as_str(self): - details_str = '' + details_str = u'' locator = self.locator_as_str if locator is not None: - details_str += '@%s' % locator + details_str += u'@{0}'.format(locator) if self.snippet is not None: - details_str += '\n%s' % self.snippet + details_str += u'\n{0}'.format(self.snippet) return details_str def __str__(self): heading_str = self.heading_as_str details = self.details_as_str if details: - heading_str += ', ' + details + heading_str += u', ' + details return heading_str @@ -149,7 +149,7 @@ class ReporterMixin(object): # Avoid duplicate issues with self._issues: for i in self._issues: - if str(i) == str(issue): + if unicode(i) == unicode(issue): return self._issues.append(issue) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/extensions/aria_extension_tosca/simple_v1_0/data_types.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/data_types.py b/extensions/aria_extension_tosca/simple_v1_0/data_types.py index 05666fd..324707e 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/data_types.py +++ b/extensions/aria_extension_tosca/simple_v1_0/data_types.py @@ -116,7 +116,7 @@ class Timestamp(object): Timezone(tzhour, tzminute)) else: raise ValueError( - 'timestamp must be formatted as YAML ISO8601 variant or "YYYY-MM-DD": {0}' + u'timestamp must be formatted as YAML ISO8601 variant or "YYYY-MM-DD": {0}' .format(safe_repr(value))) @property @@ -129,8 +129,8 @@ class Timestamp(object): def __str__(self): the_datetime = self.as_datetime_utc - return '{0}{1}Z'.format(the_datetime.strftime(Timestamp.CANONICAL), - Timestamp._fraction_as_str(the_datetime)) + return u'{0}{1}Z'.format(the_datetime.strftime(Timestamp.CANONICAL), + Timestamp._fraction_as_str(the_datetime)) def __repr__(self): return repr(self.__str__()) @@ -145,7 +145,7 @@ class Timestamp(object): @staticmethod def _fraction_as_str(the_datetime): - return '{0:g}'.format(the_datetime.microsecond / 1000000.0).lstrip('0') + return u'{0:g}'.format(the_datetime.microsecond / 1000000.0).lstrip('0') @total_ordering @@ -179,8 +179,8 @@ class Version(object): match = re.match(Version.REGEX, str_value, flags=re.UNICODE) if match is None: raise ValueError( - 'version must be formatted as <major_version>.<minor_version>' - '[.<fix_version>[.<qualifier>[-<build_version]]]: {0}'.format(safe_repr(value))) + u'version must be formatted as <major_version>.<minor_version>' + u'[.<fix_version>[.<qualifier>[-<build_version]]]: {0}'.format(safe_repr(value))) self.value = str_value @@ -242,26 +242,26 @@ class Range(object): def __init__(self, entry_schema, constraints, value, aspect): # pylint: disable=unused-argument if not isinstance(value, list): - raise ValueError('range value is not a list: {0}'.format(safe_repr(value))) + raise ValueError(u'range value is not a list: {0}'.format(safe_repr(value))) if len(value) != 2: - raise ValueError('range value does not have exactly 2 elements: {0}' + raise ValueError(u'range value does not have exactly 2 elements: {0}' .format(safe_repr(value))) def is_int(v): return isinstance(v, int) and (not isinstance(v, bool)) # In Python bool is an int if not is_int(value[0]): - raise ValueError('lower bound of range is not a valid integer: {0}' + raise ValueError(u'lower bound of range is not a valid integer: {0}' .format(safe_repr(value[0]))) if value[1] != 'UNBOUNDED': if not is_int(value[1]): - raise ValueError('upper bound of range is not a valid integer or "UNBOUNDED": {0}' + raise ValueError(u'upper bound of range is not a valid integer or "UNBOUNDED": {0}' .format(safe_repr(value[0]))) if value[0] >= value[1]: raise ValueError( - 'upper bound of range is not greater than the lower bound: {0} >= {1}' + u'upper bound of range is not greater than the lower bound: {0} >= {1}' .format(safe_repr(value[0]), safe_repr(value[1]))) self.value = value @@ -293,7 +293,7 @@ class List(list): @staticmethod def _create(context, presentation, entry_schema, constraints, value, aspect): # pylint: disable=unused-argument if not isinstance(value, list): - raise ValueError('"list" data type value is not a list: {0}'.format(safe_repr(value))) + raise ValueError(u'"list" data type value is not a list: {0}'.format(safe_repr(value))) entry_schema_type = entry_schema._get_type(context) entry_schema_constraints = entry_schema.constraints @@ -327,10 +327,10 @@ class Map(StrictDict): @staticmethod def _create(context, presentation, entry_schema, constraints, value, aspect): # pylint: disable=unused-argument if not isinstance(value, dict): - raise ValueError('"map" data type value is not a dict: {0}'.format(safe_repr(value))) + raise ValueError(u'"map" data type value is not a dict: {0}'.format(safe_repr(value))) if entry_schema is None: - raise ValueError('"map" data type does not define "entry_schema"') + raise ValueError(u'"map" data type does not define "entry_schema"') entry_schema_type = entry_schema._get_type(context) entry_schema_constraints = entry_schema.constraints @@ -375,7 +375,7 @@ class Scalar(object): str_value = unicode(value) match = re.match(self.REGEX, str_value, flags=re.UNICODE) # pylint: disable=no-member if match is None: - raise ValueError('scalar must be formatted as <scalar> <unit>: {0}' + raise ValueError(u'scalar must be formatted as <scalar> <unit>: {0}' .format(safe_repr(value))) self.factor = float(match.group('scalar')) @@ -392,7 +392,7 @@ class Scalar(object): unit_size = v break if unit_size is None: - raise ValueError('scalar specified with unsupported unit: {0}' + raise ValueError(u'scalar specified with unsupported unit: {0}' .format(safe_repr(self.unit))) self.value = self.TYPE(self.factor * unit_size) # pylint: disable=no-member @@ -406,7 +406,7 @@ class Scalar(object): ('unit_size', self.UNITS[self.unit]))) # pylint: disable=no-member def __str__(self): - return '{0} {1}'.format(self.value, self.UNIT) # pylint: disable=no-member + return u'{0} {1}'.format(self.value, self.UNIT) # pylint: disable=no-member def __repr__(self): return repr(self.__str__()) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py index d960e05..d7b69f6 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py @@ -400,7 +400,7 @@ def create_operation_template_model(context, service_template, operation): value = yaml.load(value) except yaml.parser.MarkedYAMLError as e: context.validation.report( - 'YAML parser {0} in operation configuration: {1}' + u'YAML parser {0} in operation configuration: {1}' .format(e.problem, value), locator=implementation._locator, level=Issue.FIELD) @@ -519,7 +519,7 @@ def create_workflow_operation_template_model(context, service_template, policy): used_reserved_names = WORKFLOW_DECORATOR_RESERVED_ARGUMENTS.intersection(model.inputs.keys()) if used_reserved_names: - context.validation.report('using reserved arguments in workflow policy "{0}": {1}' + context.validation.report(u'using reserved arguments in workflow policy "{0}": {1}' .format( policy._name, string_list_as_string(used_reserved_names)), @@ -696,7 +696,7 @@ def create_constraint(context, node_filter, constraint_clause, property_name, ca return Pattern(property_name, capability_name, coerce_constraint(constraint_clause.pattern)) else: - raise ValueError('malformed node_filter: {0}'.format(constraint_key)) + raise ValueError(u'malformed node_filter: {0}'.format(constraint_key)) def split_prefix(string): @@ -741,7 +741,7 @@ def extract_implementation_primary(context, service_template, presentation, mode model.function = postfix if model.plugin_specification is None: context.validation.report( - 'no policy for plugin "{0}" specified in operation implementation: {1}' + u'no policy for plugin "{0}" specified in operation implementation: {1}' .format(prefix, primary), locator=presentation._get_child_locator('properties', 'implementation'), level=Issue.BETWEEN_TYPES) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py index 1b95bec..ca32dde 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/capabilities.py @@ -73,8 +73,8 @@ def get_inherited_capability_definitions(context, presentation, for_presentation if not type1._is_descendant(context, type2): context.validation.report( - 'capability definition type "{0}" is not a descendant of overridden ' - 'capability definition type "{1}"' \ + u'capability definition type "{0}" is not a descendant of overridden ' + u'capability definition type "{1}"' \ .format(type1._name, type2._name), locator=our_capability_definition._locator, level=Issue.BETWEEN_TYPES) @@ -141,7 +141,7 @@ def get_template_capabilities(context, presentation): capability_assignment._reset_method_cache() else: context.validation.report( - 'capability "{0}" not declared at node type "{1}" in "{2}"' + u'capability "{0}" not declared at node type "{1}" in "{2}"' .format(capability_name, presentation.type, presentation._fullname), locator=our_capability_assignment._locator, level=Issue.BETWEEN_TYPES) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py index 13ce9a3..c7dbd9e 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/data_types.py @@ -90,8 +90,8 @@ def coerce_data_type_value(context, presentation, data_type, entry_schema, const aspect) else: context.validation.report( - 'assignment to undefined property "%s" in type "%s" in "%s"' - % (name, data_type._fullname, presentation._fullname), + u'assignment to undefined property "{0}" in type "{1}" in "{2}"' + .format(name, data_type._fullname, presentation._fullname), locator=get_locator(v, value, presentation), level=Issue.BETWEEN_TYPES) # Fill in defaults from the definitions, and check if required definitions have not been @@ -108,15 +108,15 @@ def coerce_data_type_value(context, presentation, data_type, entry_schema, const if getattr(definition, 'required', False) and (temp.get(name) is None): context.validation.report( - 'required property "%s" in type "%s" is not assigned a value in "%s"' - % (name, data_type._fullname, presentation._fullname), + u'required property "{0}" in type "{1}" is not assigned a value in "{2}"' + .format(name, data_type._fullname, presentation._fullname), locator=presentation._get_child_locator('definitions'), level=Issue.BETWEEN_TYPES) value = temp elif value is not None: - context.validation.report('value of type "%s" is not a dict in "%s"' - % (data_type._fullname, presentation._fullname), + context.validation.report(u'value of type "{0}" is not a dict in "{1}"' + .format(data_type._fullname, presentation._fullname), locator=get_locator(value, presentation), level=Issue.BETWEEN_TYPES) value = None @@ -131,8 +131,8 @@ def validate_data_type_name(context, presentation): name = presentation._name if get_primitive_data_type(name) is not None: - context.validation.report('data type name is that of a built-in type: %s' - % safe_repr(name), + context.validation.report(u'data type name is that of a built-in type: {0}' + .format(safe_repr(name)), locator=presentation._locator, level=Issue.BETWEEN_TYPES) @@ -216,10 +216,10 @@ def apply_constraint_to_value(context, presentation, constraint_clause, value): constraint_key) def report(message, constraint): - context.validation.report('value %s %s per constraint in "%s": %s' - % (message, safe_repr(constraint), - presentation._name or presentation._container._name, - safe_repr(value)), + context.validation.report(u'value {0} {1} per constraint in "{2}": {3}' + .format(message, safe_repr(constraint), + presentation._name or presentation._container._name, + safe_repr(value)), locator=presentation._locator, level=Issue.BETWEEN_FIELDS) if constraint_key == 'equal': @@ -324,8 +324,8 @@ def get_data_type_value(context, presentation, field_name, type_name): if value is not None: return coerce_data_type_value(context, presentation, the_type, None, None, value, None) else: - context.validation.report('field "%s" in "%s" refers to unknown data type "%s"' - % (field_name, presentation._fullname, type_name), + context.validation.report(u'field "{0}" in "{1}" refers to unknown data type "{2}"' + .format(field_name, presentation._fullname, type_name), locator=presentation._locator, level=Issue.BETWEEN_TYPES) return None @@ -394,8 +394,8 @@ def coerce_value(context, presentation, the_type, entry_schema, constraints, val if the_type == None.__class__: if value is not None: - context.validation.report('field "%s" is of type "null" but has a non-null value: %s' - % (presentation._name, safe_repr(value)), + context.validation.report(u'field "{0}" is of type "null" but has a non-null value: {1}' + .format(presentation._name, safe_repr(value)), locator=presentation._locator, level=Issue.BETWEEN_FIELDS) return None @@ -498,17 +498,18 @@ def report_issue_for_bad_format(context, presentation, the_type, value, aspect, if aspect == 'default': aspect = '"default" value' elif aspect is not None: - aspect = '"%s" aspect' % aspect + aspect = u'"{0}" aspect'.format(aspect) if aspect is not None: - context.validation.report('%s for field "%s" is not a valid "%s": %s' - % (aspect, presentation._name or presentation._container._name, - get_data_type_name(the_type), safe_repr(value)), + context.validation.report(u'{0} for field "{1}" is not a valid "{2}": {3}' + .format(aspect, + presentation._name or presentation._container._name, + get_data_type_name(the_type), safe_repr(value)), locator=presentation._locator, level=Issue.BETWEEN_FIELDS, exception=e) else: - context.validation.report('field "%s" is not a valid "%s": %s' - % (presentation._name or presentation._container._name, - get_data_type_name(the_type), safe_repr(value)), + context.validation.report(u'field "{0}" is not a valid "{1}": {2}' + .format(presentation._name or presentation._container._name, + get_data_type_name(the_type), safe_repr(value)), locator=presentation._locator, level=Issue.BETWEEN_FIELDS, exception=e) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py index ecbfde9..b35e9b2 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py @@ -43,7 +43,7 @@ class Concat(Function): if not isinstance(argument, list): raise InvalidValueError( - 'function "concat" argument must be a list of string expressions: {0}' + u'function "concat" argument must be a list of string expressions: {0}' .format(safe_repr(argument)), locator=self.locator) @@ -84,7 +84,7 @@ class Token(Function): self.locator = presentation._locator if (not isinstance(argument, list)) or (len(argument) != 3): - raise InvalidValueError('function "token" argument must be a list of 3 parameters: {0}' + raise InvalidValueError(u'function "token" argument must be a list of 3 parameters: {0}' .format(safe_repr(argument)), locator=self.locator) @@ -143,7 +143,7 @@ class GetInput(Function): 'inputs', self.input_property_name) if the_input is None: raise InvalidValueError( - 'function "get_input" argument is not a valid input name: {0}' + u'function "get_input" argument is not a valid input name: {0}' .format(safe_repr(argument)), locator=self.locator) @@ -162,7 +162,7 @@ class GetInput(Function): return Evaluation(value, False) # We never return final evaluations! raise InvalidValueError( - 'function "get_input" argument is not a valid input name: {0}' + u'function "get_input" argument is not a valid input name: {0}' .format(safe_repr(self.input_property_name)), locator=self.locator) @@ -179,8 +179,8 @@ class GetProperty(Function): if (not isinstance(argument, list)) or (len(argument) < 2): raise InvalidValueError( - 'function "get_property" argument must be a list of at least 2 string expressions: ' - '{0}'.format(safe_repr(argument)), + u'function "get_property" argument must be a list of at least 2 string expressions:' + u' {0}'.format(safe_repr(argument)), locator=self.locator) self.modelable_entity_name = parse_modelable_entity_name(context, presentation, @@ -230,8 +230,8 @@ class GetProperty(Function): return evaluation raise InvalidValueError( - 'function "get_property" could not find "{0}" in modelable entity "{1}"' - .format('.'.join(self.nested_property_name_or_index), self.modelable_entity_name), + u'function "get_property" could not find "{0}" in modelable entity "{1}"' + .format(u'.'.join(self.nested_property_name_or_index), self.modelable_entity_name), locator=self.locator) @@ -251,8 +251,8 @@ class GetAttribute(Function): if (not isinstance(argument, list)) or (len(argument) < 2): raise InvalidValueError( - 'function "get_attribute" argument must be a list of at least 2 string expressions:' - ' {0}'.format(safe_repr(argument)), + u'function "get_attribute" argument must be a list of at least 2 string ' + u'expressions: {0}'.format(safe_repr(argument)), locator=self.locator) self.modelable_entity_name = parse_modelable_entity_name(context, presentation, @@ -277,8 +277,8 @@ class GetAttribute(Function): return evaluation raise InvalidValueError( - 'function "get_attribute" could not find "{0}" in modelable entity "{1}"' - .format('.'.join(self.nested_attribute_name_or_index), self.modelable_entity_name), + u'function "get_attribute" could not find "{0}" in modelable entity "{1}"' + .format(u'.'.join(self.nested_attribute_name_or_index), self.modelable_entity_name), locator=self.locator) @@ -298,7 +298,7 @@ class GetOperationOutput(Function): if (not isinstance(argument, list)) or (len(argument) != 4): raise InvalidValueError( - 'function "get_operation_output" argument must be a list of 4 parameters: {0}' + u'function "get_operation_output" argument must be a list of 4 parameters: {0}' .format(safe_repr(argument)), locator=self.locator) @@ -349,7 +349,7 @@ class GetNodesOfType(Function): node_types = context.presentation.get('service_template', 'node_types') if (node_types is None) or (self.node_type_name not in node_types): raise InvalidValueError( - 'function "get_nodes_of_type" argument is not a valid node type name: {0}' + u'function "get_nodes_of_type" argument is not a valid node type name: {0}' .format(safe_repr(argument)), locator=self.locator) @@ -380,7 +380,7 @@ class GetArtifact(Function): if (not isinstance(argument, list)) or (len(argument) < 2) or (len(argument) > 4): raise InvalidValueError( - 'function "get_artifact" argument must be a list of 2 to 4 parameters: {0}' + u'function "get_artifact" argument must be a list of 2 to 4 parameters: {0}' .format(safe_repr(argument)), locator=self.locator) @@ -475,7 +475,7 @@ def parse_modelable_entity_name(context, presentation, name, index, value): or {} if (value not in node_templates) and (value not in relationship_templates): raise InvalidValueError( - 'function "{0}" parameter {1:d} is not a valid modelable entity name: {2}' + u'function "{0}" parameter {1:d} is not a valid modelable entity name: {2}' .format(name, index + 1, safe_repr(value)), locator=presentation._locator, level=Issue.BETWEEN_TYPES) return value @@ -548,7 +548,7 @@ def get_modelable_entities(container_holder, name, locator, modelable_entity_nam return modelable_entities - raise InvalidValueError('function "{0}" could not find modelable entity "{1}"' + raise InvalidValueError(u'function "{0}" could not find modelable entity "{1}"' .format(name, modelable_entity_name), locator=locator) @@ -564,9 +564,9 @@ def get_self(container_holder, name, locator): (not isinstance(container, NodeTemplate)) and \ (not isinstance(container, Relationship)) and \ (not isinstance(container, RelationshipTemplate)): - raise InvalidValueError('function "{0}" refers to "SELF" but it is not contained in ' - 'a node or a relationship: {1}'.format(name, - full_type_name(container)), + raise InvalidValueError(u'function "{0}" refers to "SELF" but it is not contained in ' + u'a node or a relationship: {1}'.format(name, + full_type_name(container)), locator=locator) return [container] @@ -586,8 +586,8 @@ def get_hosts(container_holder, name, locator): container = container_holder.container if (not isinstance(container, Node)) and (not isinstance(container, NodeTemplate)): - raise InvalidValueError('function "{0}" refers to "HOST" but it is not contained in ' - 'a node: {1}'.format(name, full_type_name(container)), + raise InvalidValueError(u'function "{0}" refers to "HOST" but it is not contained in ' + u'a node: {1}'.format(name, full_type_name(container)), locator=locator) if not isinstance(container, Node): @@ -611,8 +611,8 @@ def get_source(container_holder, name, locator): container = container_holder.container if (not isinstance(container, Relationship)) and \ (not isinstance(container, RelationshipTemplate)): - raise InvalidValueError('function "{0}" refers to "SOURCE" but it is not contained in ' - 'a relationship: {1}'.format(name, full_type_name(container)), + raise InvalidValueError(u'function "{0}" refers to "SOURCE" but it is not contained in ' + u'a relationship: {1}'.format(name, full_type_name(container)), locator=locator) if not isinstance(container, RelationshipTemplate): @@ -631,8 +631,8 @@ def get_target(container_holder, name, locator): container = container_holder.container if (not isinstance(container, Relationship)) and \ (not isinstance(container, RelationshipTemplate)): - raise InvalidValueError('function "{0}" refers to "TARGET" but it is not contained in ' - 'a relationship: {1}'.format(name, full_type_name(container)), + raise InvalidValueError(u'function "{0}" refers to "TARGET" but it is not contained in ' + u'a relationship: {1}'.format(name, full_type_name(container)), locator=locator) if not isinstance(container, RelationshipTemplate): @@ -665,17 +665,17 @@ def get_modelable_entity_parameter(modelable_entity, parameters, nested_paramete def invalid_modelable_entity_name(name, index, value, locator, contexts): - return InvalidValueError('function "{0}" parameter {1:d} can be "{2}" only in {3}' + return InvalidValueError(u'function "{0}" parameter {1:d} can be "{2}" only in {3}' .format(name, index + 1, value, contexts), locator=locator, level=Issue.FIELD) def invalid_value(name, index, the_type, explanation, value, locator): return InvalidValueError( - 'function "{0}" {1} is not {2}{3}: {4}' + u'function "{0}" {1} is not {2}{3}: {4}' .format(name, - 'parameter {0:d}'.format(index + 1) if index is not None else 'argument', + u'parameter {0:d}'.format(index + 1) if index is not None else 'argument', the_type, - ', {0}'.format(explanation) if explanation is not None else '', + u', {0}'.format(explanation) if explanation is not None else '', safe_repr(value)), locator=locator, level=Issue.FIELD) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/756356ab/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py index 23a03b7..26fb546 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/interfaces.py @@ -177,8 +177,8 @@ def get_template_interfaces(context, presentation, type_name): our_interface_assignment, interface_definition, interface_name) else: context.validation.report( - 'interface definition "%s" not declared at %s "%s" in "%s"' - % (interface_name, type_name, presentation.type, presentation._fullname), + u'interface definition "{0}" not declared at {1} "{2}" in "{3}"' + .format(interface_name, type_name, presentation.type, presentation._fullname), locator=our_interface_assignment._locator, level=Issue.BETWEEN_TYPES) # Check that there are no required inputs that we haven't assigned @@ -272,8 +272,8 @@ def merge_interface(context, presentation, interface_assignment, our_interface_a if operation_definition is None: context.validation.report( - 'interface definition "%s" refers to an unknown operation "%s" in "%s"' - % (interface_name, operation_name, presentation._fullname), + u'interface definition "{0}" refers to an unknown operation "{1}" in "{2}"' + .format(interface_name, operation_name, presentation._fullname), locator=our_operation_template._locator, level=Issue.BETWEEN_TYPES) if (our_input_assignments is not None) or (our_implementation is not None): @@ -303,15 +303,16 @@ def merge_raw_input_definition(context, the_raw_input, our_input, interface_name if input_type1 != input_type2: if operation_name is not None: context.validation.report( - 'interface %s "%s" changes operation input "%s.%s" type from "%s" to "%s" in "%s"' - % (type_name, interface_name, operation_name, our_input._name, input_type1, - input_type2, presentation._fullname), + u'interface {0} "{1}" changes operation input "{2}.{3}" type from "{4}" to "{5}" ' + u'in "{6}"' + .format(type_name, interface_name, operation_name, our_input._name, input_type1, + input_type2, presentation._fullname), locator=input_type2._locator, level=Issue.BETWEEN_TYPES) else: context.validation.report( - 'interface %s "%s" changes input "%s" type from "%s" to "%s" in "%s"' - % (type_name, interface_name, our_input._name, input_type1, input_type2, - presentation._fullname), + u'interface {0} "{1}" changes input "{2}" type from "{3}" to "{4}" in "{5}"' + .format(type_name, interface_name, our_input._name, input_type1, input_type2, + presentation._fullname), locator=input_type2._locator, level=Issue.BETWEEN_TYPES) # Merge @@ -405,8 +406,8 @@ def merge_interface_definition(context, interface, our_source, presentation, typ if (type2 is not None) and not type1._is_descendant(context, type2): context.validation.report( - 'interface definition type "{0}" is not a descendant of overridden ' - 'interface definition type "{1}"' \ + u'interface definition type "{0}" is not a descendant of overridden ' + u'interface definition type "{1}"' \ .format(type1._name, type2._name), locator=our_source._locator, level=Issue.BETWEEN_TYPES) @@ -462,14 +463,14 @@ def assign_raw_inputs(context, values, assignments, definitions, interface_name, if (definitions is not None) and (input_name not in definitions): if operation_name is not None: context.validation.report( - 'interface definition "%s" assigns a value to an unknown operation input' - ' "%s.%s" in "%s"' - % (interface_name, operation_name, input_name, presentation._fullname), + u'interface definition "{0}" assigns a value to an unknown operation input' + u' "{1}.{2}" in "{3}"' + .format(interface_name, operation_name, input_name, presentation._fullname), locator=assignment._locator, level=Issue.BETWEEN_TYPES) else: context.validation.report( - 'interface definition "%s" assigns a value to an unknown input "%s" in "%s"' - % (interface_name, input_name, presentation._fullname), + u'interface definition "{0}" assigns a value to an unknown input "{1}" in "{2}"' + .format(interface_name, input_name, presentation._fullname), locator=assignment._locator, level=Issue.BETWEEN_TYPES) definition = definitions.get(input_name) if definitions is not None else None @@ -498,16 +499,17 @@ def validate_required_inputs(context, presentation, assignment, definition, orig if value is None: if operation_name is not None: context.validation.report( - 'interface definition "%s" does not assign a value to a required' - ' operation input "%s.%s" in "%s"' - % (interface_name, operation_name, input_name, presentation._fullname), + u'interface definition "{0}" does not assign a value to a required' + u' operation input "{1}.{2}" in "{3}"' + .format(interface_name, operation_name, input_name, + presentation._fullname), locator=get_locator(original_assignment, presentation._locator), level=Issue.BETWEEN_TYPES) else: context.validation.report( - 'interface definition "%s" does not assign a value to a required input' - ' "%s" in "%s"' - % (interface_name, input_name, presentation._fullname), + u'interface definition "{0}" does not assign a value to a required' + u' input "{1}" in "{2}"' + .format(interface_name, input_name, presentation._fullname), locator=get_locator(original_assignment, presentation._locator), level=Issue.BETWEEN_TYPES)
