~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/server/schema.py

  • Committer: Thomas Hervé
  • Date: 2013-02-19 08:25:57 UTC
  • Revision ID: thomas@canonical.com-20130219082557-ez2ir12brb041d7f
Enforce the name of list elements in the server schema if not provided [trivial]

Show diffs side-by-side

added added

removed removed

Lines of Context:
321
321
            raise TypeError("Must provide item")
322
322
        super(List, self).__init__(name, optional=optional, default=default,
323
323
                                   doc=doc)
 
324
        if item.name is None:
 
325
            item.name = name
324
326
        self.item = item
325
327
        if default is None:
326
328
            self.default = []
364
366
        if isinstance(value, Arguments):
365
367
            return dict((str(i), self.item.format(v)) for i, v in value)
366
368
        return dict((str(i + 1), self.item.format(v))
367
 
                        for i, v in enumerate(value))
 
369
                    for i, v in enumerate(value))
368
370
 
369
371
 
370
372
class Structure(Parameter):
396
398
        for k, v in value.iteritems():
397
399
            if k in self.fields:
398
400
                if (isinstance(v, dict)
399
 
                    and not self.fields[k].supports_multiple):
 
401
                        and not self.fields[k].supports_multiple):
400
402
                    if len(v) == 1:
401
403
                        # We support "foo.1" as "foo" as long as there is only
402
404
                        # one "foo.#" parameter provided.... -_-
751
753
            # we're processing a structure.
752
754
            fields = {}
753
755
            for node in parameter_description:
754
 
                fields[node[0]] = self._inner_convert_old_schema(node, depth + 1)
 
756
                fields[node[0]] = self._inner_convert_old_schema(
 
757
                    node, depth + 1)
755
758
            return Structure(name, fields=fields)
756
759
        else:
757
760
            # we're processing a list.