def __repr__(self):
     return '{}({})'.format(
         get_class_name(self), ', '.join([
             f'name={self.name}',
             f'method={self.decorator.method.upper()}',
             f'routes={self.decorator.routes}',
         ]))
Beispiel #2
0
 def emit(self, field, field_no):
     field_type_name = get_class_name(field.schema_type)
     if field_type_name.endswith('Schema'):
         field_type_name = field_type_name[:-len('Schema')]
     return super().emit(
         field_type=field_type_name,
         field_no=field_no,
         field_name=field.name,
     )
Beispiel #3
0
 def emit(self, field, field_no, is_repeated=False):
     field_type_name = get_class_name(field)
     if field_type_name.endswith('Schema'):
         field_type_name = field_type_name[:-len('Schema')]
     return super().emit(
         field_type=field_type_name,
         field_no=field_no,
         field_name=field.name,
         is_repeated=is_repeated
     )
Beispiel #4
0
def get_stripped_schema_name(obj):
    if isinstance(obj, Schema):
        name = get_class_name(obj)
    else:
        assert isinstance(obj, str)
        name = obj
    if name.endswith('Schema'):
        return name[:-len('Schema')]
    else:
        return name
Beispiel #5
0
 def _on_bootstrap_aggregate_response_message_types(self):
     """
     Build a lookup table of protobuf response Message types for use when
     routing requests to their downstream actions.
     """
     grpc = self.grpc
     grpc.response_types = {}
     for action in self.actions.values():
         schema_type_name = get_class_name(action.schemas.response)
         message_type_name = get_stripped_schema_name(
             StringUtils.camel(schema_type_name))
         response_message_type = getattr(self.grpc.pb2, message_type_name)
         grpc.response_types[action.name] = response_message_type
Beispiel #6
0
    def __repr__(self):
        name = get_class_name(self)
        dirty = '*' if self.is_dirty else ''
        id_value = self.internal.state.get(ID)
        if id_value is None:
            id_str = '?'
        elif isinstance(id_value, str):
            id_str = id_value[:7]
        elif isinstance(id_value, uuid.UUID):
            id_str = id_value.hex[:7]
        else:
            id_str = repr(id_value)

        return f'{name}({id_str}){dirty}'
Beispiel #7
0
    def emit(self, field, field_no):
        try:
            adapter = self.msg_gen.get_adapter(field.nested)
        except:
            import ipdb; ipdb.set_trace()
        try:
            if isinstance(adapter, SchemaFieldAdapter):
                nested_field_type = get_class_name(field.nested),
            elif isinstance(adapter, NestedFieldAdapter):
                nested_field_type = get_class_name(field.nested.schema_type)
            else:
                nested_field_type = adapter.type_name
        except:
            raise Exception('Unable to establish nested field type')

        if nested_field_type.endswith('Schema'):
            nested_field_type = nested_field_type[:-len('Schema')]

        return super().emit(
            field_type=nested_field_type,
            field_no=field_no,
            field_name=field.name,
            is_repeated=True,
        )
Beispiel #8
0
 def create(self, record: dict) -> dict:
     record[self.id_column_name] = self.create_id(record)
     prepared_record = self.prepare(record, serialize=True)
     insert_stmt = self.table.insert().values(**prepared_record)
     _id = prepared_record.get('_id', '')
     console.debug(f'SQL: INSERT {str(_id)[:7] + " " if _id else ""}'
                   f'INTO {self.table}')
     try:
         if self.supports_returning:
             insert_stmt = insert_stmt.return_defaults()
             result = self.conn.execute(insert_stmt)
             return dict(record, **(result.returned_defaults or {}))
         else:
             result = self.conn.execute(insert_stmt)
             return self.fetch(_id=record[self.id_column_name])
     except Exception:
         console.error(message=f'failed to insert record',
                       data={
                           'record': record,
                           'resource': get_class_name(self.resource_type),
                       })
         raise
Beispiel #9
0
 def class_name(self) -> Text:
     return get_class_name(self)
Beispiel #10
0
 def get_schema_name(schema: 'Schema') -> Text:
     name = get_class_name(schema)
     if name.endswith('Schema'):
         name = name[:-6]
     return name