def _create(filesystem, content_type=RAW, filename=None, params=None):
    """Create a file.

  Args:
    filesystem: File system to create a file at as string.
    content_type: File content type.
    filename: Requested file name as string. Some file system require this
      to be filled in, some require it to be None.
    params: {string: string} dict of file parameters. Each filesystem
      interprets them differently.
  """
    request = file_service_pb.CreateRequest()
    response = file_service_pb.CreateResponse()

    request.set_filesystem(filesystem)
    request.set_content_type(content_type)

    if filename:
        request.set_filename(filename)

    if params:
        for k, v in params.items():
            param = request.add_parameters()
            param.set_name(k)
            param.set_value(v)

    _make_call('Create', request, response)
    return response.filename()
Esempio n. 2
0
File: file.py Progetto: rca/appscale
def _create(filesystem, content_type=RAW, filename=None, params=None):
    """Create a file.

  Args:
    filesystem: File system to create a file at as string.
    content_type: File content type.
    filename: Requested file name as string. Some file system require this
      to be filled in, some require it to be None.
    params: {string: string} dict of file parameters. Each filesystem
      interprets them differently.
  """
    if not filesystem:
        raise InvalidArgumentError('Filesystem is empty')
    if not isinstance(filesystem, basestring):
        raise InvalidArgumentError('Filesystem should be a string')
    if content_type != RAW:
        raise InvalidArgumentError('Invalid content type')

    request = file_service_pb.CreateRequest()
    response = file_service_pb.CreateResponse()

    request.set_filesystem(filesystem)
    request.set_content_type(content_type)

    if filename:
        if not isinstance(filename, basestring):
            raise InvalidArgumentError('Filename should be a string')
        request.set_filename(filename)

    if params:
        if not isinstance(params, dict):
            raise InvalidArgumentError('Parameters should be a dictionary')
        for k, v in params.items():
            param = request.add_parameters()
            param.set_name(k)
            param.set_value(v)

    _make_call('Create', request, response)
    return response.filename()