Example #1
0
    def __parse_msg(self, msgname, obj):
        req = obj.get("request")
        res = obj.get("response")
        if req is None:
            raise SchemaParseException("No request specified: " +
                                       obj.__str__())
        if res is None:
            raise SchemaParseException("No response specified: " +
                                       obj.__str__())
        fields = dict()
        for field in req:
            fieldname = field.get("name")
            if fieldname is None:
                raise SchemaParseException("No param name: " + field.__str__())
            fieldtype = field.get("type")
            if fieldtype is None:
                raise SchemaParseException("No param type: " + field.__str__())
            fields[fieldname] = schema.Field(
                fieldname, schema._parse(fieldtype, self.__types))
        request = schema._RecordSchema(fields)
        response = schema._parse(res, self.__types)

        erorrs = list()
        erorrs.append(_SYSTEM_ERROR)
        errs = obj.get("errors")
        if errs is not None:
            if not isinstance(errs, list):
                raise SchemaParseException("Errors not an array: " +
                                           errs.__str__())
            for err in errs:
                name = err.__str__()
                sch = self.__types.get(name)
                if sch is None:
                    raise SchemaParseException("Undefined error: " +
                                               name.__str__())
                if sch.iserror is False:
                    raise SchemaParseException("Not an error: " +
                                               name.__str__())
                erorrs.append(sch)

        return self.Message(self, msgname, request, response,
                            schema._UnionSchema(erorrs))
Example #2
0
 def __str__(self):
     str = cStringIO.StringIO()
     str.write("{\"request\": [")
     count = 0
     for field in self.__request.getfields().values():
         str.write("{\"name\": \"")
         str.write(field.getname())
         str.write("\", \"type\": ")
         str.write(field.getschema().str(self.__proto.gettypes()))
         str.write("}")
         count += 1
         if count < len(self.__request.getfields()):
             str.write(", ")
     str.write("], \"response\": " +
               self.__response.str(self.__proto.gettypes()))
     list = self.__errors.getelementtypes()
     if len(list) > 1:
         str.write(",")
         sch = schema._UnionSchema(list.__getslice__(1, len(list)))
         str.write("\"errors\":" + sch.str(self.__proto.gettypes()))
     str.write("}")
     return str.getvalue()
Example #3
0
 def __str__(self):
   str = cStringIO.StringIO()
   str.write("{\"request\": [")
   count = 0
   for field in self.__request.getfields().values():
     str.write("{\"name\": \"")
     str.write(field.getname())
     str.write("\", \"type\": ")
     str.write(field.getschema().str(self.__proto.gettypes()))
     str.write("}")
     count+=1
     if count < len(self.__request.getfields()):
       str.write(", ")
   str.write("], \"response\": "+
             self.__response.str(self.__proto.gettypes()))
   list = self.__errors.getelementtypes()
   if len(list) > 1:
     str.write(",")
     sch = schema._UnionSchema(list.__getslice__(1, len(list)))
     str.write("\"errors\":"+sch.str(self.__proto.gettypes()))
   str.write("}")
   return str.getvalue()
Example #4
0
  def __parse_msg(self, msgname, obj):
    req = obj.get("request")
    res = obj.get("response")
    if req is None:
      raise SchemaParseException("No request specified: "+obj.__str__())
    if res is None:
      raise SchemaParseException("No response specified: "+obj.__str__())
    fields = dict()
    for field in req:
      fieldname = field.get("name")
      if fieldname is None:
        raise SchemaParseException("No param name: "+field.__str__())
      fieldtype = field.get("type")
      if fieldtype is None:
        raise SchemaParseException("No param type: "+field.__str__())
      fields[fieldname] = schema.Field(fieldname, 
                                       schema._parse(fieldtype, self.__types))
    request = schema._RecordSchema(fields)
    response = schema._parse(res, self.__types)

    erorrs = list()
    erorrs.append(_SYSTEM_ERROR)
    errs = obj.get("errors")
    if errs is not None:
      if not isinstance(errs, list):
        raise SchemaParseException("Errors not an array: "+errs.__str__())
      for err in errs:
        name = err.__str__()
        sch = self.__types.get(name)
        if sch is None:
          raise SchemaParseException("Undefined error: "+name.__str__())
        if sch.iserror is False:
          raise SchemaParseException("Not an error: "+name.__str__())
        erorrs.append(sch)

    return self.Message(self, msgname, request, response, 
              schema._UnionSchema(erorrs))
Example #5
0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

import cStringIO, md5
import simplejson
import avro.schema as schema

#The version implemented.
VERSION = 1

_SYSTEM_ERROR = schema._StringSchema()
_SYSTEM_ERRORS = schema._UnionSchema([_SYSTEM_ERROR])


class Protocol(object):
    """A set of messages forming an application protocol."""
    def __init__(self, name=None, namespace=None):
        self.__types = schema._Names()
        self.__messages = dict()
        self.__name = name
        self.__namespace = namespace
        self.__md5 = None

    def getname(self):
        return self.__name

    def getnamespace(self):
Example #6
0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

import cStringIO, md5
import simplejson
import avro.schema as schema

#The version implemented.
VERSION = 1

_SYSTEM_ERROR = schema._StringSchema()
_SYSTEM_ERRORS = schema._UnionSchema([_SYSTEM_ERROR])

class Protocol(object):
  """A set of messages forming an application protocol."""
  def __init__(self, name=None, namespace=None):
    self.__types = schema._Names()
    self.__messages = dict()
    self.__name = name
    self.__namespace = namespace
    self.__md5 = None

  def getname(self):
    return self.__name

  def getnamespace(self):
    return self.__namespace