Sends the file identified by id and additional query params to the server
@param {Object} params name-value string pairs
540265
function(id, params){
        var file = this._files[id],
            name = this.getName(id),
            size = this.getSize(id);
                
        this._loaded[id] = 0;
                                
        var xhr = this._xhrs[id] = new XMLHttpRequest();
        var self = this;
                                        
        xhr.upload.onprogress = function(e){
            if (e.lengthComputable){
                self._loaded[id] = e.loaded;
                self._options.onProgress(id, name, e.loaded, e.total);
            }
        };

        xhr.onreadystatechange = function(){            
            if (xhr.readyState == 4){
                self._onComplete(id, xhr);                    
            }
        };

        // build query string
        params = params || {};
        params['qqfile'] = name;
        var queryString = qq.obj2url(params, this._options.action);

        xhr.open("POST", queryString, true);
        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
        xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
        xhr.setRequestHeader("Content-Type", "application/octet-stream");
        xhr.send(file);
    }
36220
function (params) {
        this.query = params.q !== undefined ? String(params.q) : defaultParams.query;
        this.page = params.p !== undefined ? parseInt(params.p, 10) : defaultParams.page;
        switch (params.s) {
          case 'name':
          case 'owner':
          case 'stars':
          case 'updated':
            this.sorting = params.s;
            break;
          default:
            this.sorting = defaultParams.sorting;
        }
        switch (params.o) {
          case 'asc':
          case 'desc':
            this.order = params.o;
            break;
          default:
            this.order = defaultParams.order;
        }
      }
1148551
function (params) {
        params = _.isString(params) ? QueryParam.parse(params) : params;
        this.query.populate(params);
    }
1138840
function(params) {

                corbel.validate.value('id', this.id);

                var options = params ? corbel.utils.clone(params) : {};

                var args = corbel.utils.extend(options, {
                    url: this._buildUriWithDomain(this.id),
                    method: corbel.request.method.GET,
                    query: params ? corbel.utils.serializeParams(params) : null
                });

                return this.request(args);

            }
370558
function sendfile(res, file, options, callback) {
  var done = false;
  var streaming;

  // request aborted
  function onaborted() {
    if (done) return;
    done = true;

    var err = new Error('Request aborted');
    err.code = 'ECONNABORTED';
    callback(err);
  }

  // directory
  function ondirectory() {
    if (done) return;
    done = true;

    var err = new Error('EISDIR, read');
    err.code = 'EISDIR';
    callback(err);
  }

  // errors
  function onerror(err) {
    if (done) return;
    done = true;
    callback(err);
  }

  // ended
  function onend() {
    if (done) return;
    done = true;
    callback();
  }

  // file
  function onfile() {
    streaming = false;
  }

  // finished
  function onfinish(err) {
    if (err && err.code === 'ECONNRESET') return onaborted();
    if (err) return onerror(err);
    if (done) return;

    setImmediate(function () {
      if (streaming !== false && !done) {
        onaborted();
        return;
      }

      if (done) return;
      done = true;
      callback();
    });
  }

  // streaming
  function onstream() {
    streaming = true;
  }

  file.on('directory', ondirectory);
  file.on('end', onend);
  file.on('error', onerror);
  file.on('file', onfile);
  file.on('stream', onstream);
  onFinished(res, onfinish);

  if (options.headers) {
    // set headers on successful transfer
    file.on('headers', function headers(res) {
      var obj = options.headers;
      var keys = Object.keys(obj);

      for (var i = 0; i < keys.length; i++) {
        var k = keys[i];
        res.setHeader(k, obj[k]);
      }
    });
  }

  // pipe
  file.pipe(res);
}
420869
function resolveFilesInParams(params, files) {
	var fileIds = Object.keys(files || {});

	var fileCount = fileIds.length;
	if (fileCount === 0) {
		return;
	}

	// scan all members for files, and collect children

	function addMembers(list, obj) {
		var keys = Object.keys(obj || {});

		for (var i = 0; i < keys.length; i++) {
			list.push({
				owner: obj,
				key: keys[i],
				value: obj[keys[i]]
			});
		}
	}

	var list = [];

	addMembers(list, params);

	for (var i = 0; i < list.length && fileCount > 0; i++) {
		var member = list[i];

		if (!member.value) {
			continue;
		}

		var type = typeof member.value;

		if (type === 'object') {
			// append children to the end of the list

			addMembers(list, member.value);
		} else if (type === 'string' && files[member.value]) {
			// file found for this property, so assign it

			var file = files[member.value];

			logger.verbose('Accepted file', '"' + file.partName + '":', file.fileName);

			member.owner[member.key] = file;

			delete files[member.value];
			fileCount -= 1;
		}
	}
}
1128763
function validateParams(fs, param2) {
  var err;

  if(!fs) {
    err = new Errors.EINVAL('No filesystem provided');
  } else if(!param2) {
    err = new Errors.EINVAL('Second argument must be specified');
  }

  return err;
}
1152079
function send(method, params, callback) {
            if (typeof params === "function") {
                callback = params;
                params = [];
            }

            self.web3.currentProvider.sendAsync({
                jsonrpc: "2.0",
                method,
                params: params || [],
                id: new Date().getTime(),
            }, callback);
        }
242808
function ( params, callback, method, done ) {
			const self = this,
				// store requested action - will be used when parsing a response
				actionName = params.action,
				// "request" options
				options = {
					method: method || 'GET',
					proxy: this.proxy || false,
					jar: this.jar,
					headers: {
						'User-Agent': this.userAgent
					}
				};

			// HTTP request parameters
			params = params || {};

			// force JSON format
			params.format = 'json';

			// handle uploads
			if ( method === 'UPLOAD' ) {
				options.method = 'POST';

				const CRLF = '\r\n',
					postBody = [],
					boundary = `nodemw${Math.random().toString().substr( 2 )}`;

				// encode each field
				Object.keys( params ).forEach( function ( fieldName ) {
					const value = params[ fieldName ];

					postBody.push( `--${boundary}` );
					postBody.push( CRLF );

					if ( typeof value === 'string' ) {
					// properly encode UTF8 in binary-safe POST data
						postBody.push( `Content-Disposition: form-data; name="${fieldName}"` );
						postBody.push( CRLF );
						postBody.push( CRLF );
						postBody.push( new Buffer( value, 'utf8' ) );
					} else {
					// send attachment
						postBody.push( `Content-Disposition: form-data; name="${fieldName}"; filename="foo"` );
						postBody.push( CRLF );
						postBody.push( CRLF );
						postBody.push( value );
					}

					postBody.push( CRLF );
				} );

				postBody.push( `--${boundary}--` );

				// encode post data
				options.headers[ 'content-type' ] = `multipart/form-data; boundary=${boundary}`;
				options.body = postBody;

				params = {};
			}

			// form an URL to API
			options.url = this.formatUrl( {
				protocol: this.protocol,
				port: this.port,
				hostname: this.server,
				pathname: this.path + '/api.php',
				query: ( options.method === 'GET' ) ? params : {}
			} );

			// POST all parameters (avoid "request string too long" errors)
			if ( method === 'POST' ) {
				options.form = params;
			}

			this.logger.debug( 'API action: %s', actionName );
			this.logger.debug( '%s <%s>', options.method, options.url );
			if ( options.form ) {
				this.logger.debug( 'POST fields: %s', Object.keys( options.form ).join( ', ' ) );
			}

			request( options, function ( error, response, body ) {
				response = response || {};

				if ( error ) {
					self.logger.error( 'Request to API failed: %s', error );
					callback( new Error( `Request to API failed: ${error}` ) );
					done();
					return;
				}

				if ( response.statusCode !== 200 ) {
					self.logger.error( 'Request to API failed: HTTP status code was %d for <%s>', response.statusCode || 'unknown', options.url );
					self.logger.debug( 'Body: %s', body );

					self.logger.data( new Error().stack );

					callback( new Error( `Request to API failed: HTTP status code was ${response.statusCode}` ) );
					done();
					return;
				}

				// parse response
				let data,
					info,
					next;

				try {
					data = JSON.parse( body );
					info = data && data[ actionName ];

					// acfrom=Zeppelin Games
					next = data && data[ 'query-continue' ] && data[ 'query-continue' ][ params.list || params.prop ];

					// handle the new continuing queries introduced in MW 1.21
					// (and to be made default in MW 1.26)
					// issue #64
					// @see https://www.mediawiki.org/wiki/API:Query#Continuing_queries
					if ( !next ) {
					// cmcontinue=page|5820414e44205920424f534f4e53|12253446, continue=-||
						next = data && data.continue;
					}
				} catch ( e ) {
					self.logger.error( 'Error parsing JSON response: %s', body );
					self.logger.data( body );

					callback( new Error( 'Error parsing JSON response' ) );
					done();
					return;
				}

				// if (!callback) data.error = {info: 'foo'}; // debug

				if ( data && !data.error ) {
					if ( next ) {
						self.logger.debug( 'There\'s more data' );
						self.logger.debug( next );
					}

					callback( null, info, next, data );
				} else if ( data.error ) {
					self.logger.error( 'Error returned by API: %s', data.error.info );
					self.logger.data( data.error );

					callback( new Error( `Error returned by API: ${data.error.info}` ) );
				}
				done();
			} );
		}
467620
def sents(self: object, fileids: str):
        

        for para in self.paras(fileids):
            for sent in sent_tokenize(para):
                yield sent
743523
function send(object) {
  if (typeof object === 'object') {
    return write(this.filepath, JSON.stringify(object, null, '  '));
  } else {
    return write(this.filepath, object.toString());
  }
}
1194960
function(params, callback) {
                getFileData = {};

                if (params) {
                    if (typeof params.fileId != 'undefined') {
                        getFileData.fileId = params.fileId;
                    }

                    if (typeof params.hashCode == 'string') {
                        getFileData.hashCode = params.hashCode;
                    }

                    if (typeof params.downloadable == 'boolean') {
                        getFileData.downloadable = params.downloadable;
                    }
                }

                httpRequest({
                    url: SERVICE_ADDRESSES.FILESERVER_ADDRESS +
                    SERVICES_PATH.GET_FILE,
                    method: 'GET',
                    data: getFileData
                }, function(result) {
                    if (!result.hasError) {
                        var queryString = '?';
                        for (var i in params) {
                            queryString += i + '=' + params[i] + '&';
                        }
                        queryString = queryString.slice(0, -1);
                        var file = SERVICE_ADDRESSES.FILESERVER_ADDRESS + SERVICES_PATH.GET_FILE + queryString;
                        callback({
                            hasError: result.hasError,
                            result: file
                        });
                    }
                    else {
                        callback({
                            hasError: true
                        });
                    }
                });
            }
750608
function request(
	host,
	method,
	path,
	params,
	query,
	headers,
	options,
	file,
	cb,
	debug
) {
	if (!options) options = {};

	// Remove leading/trailing slash from the path/host so that we can join
	// the two together no matter which way the user chose to provide them.
	if (path[0] === FSLASH) {
		path = path.slice(1);
	}
	if (host[host.length - 1] === FSLASH) {
		host = host.slice(0, host.length - 1);
	}

	var url = host + FSLASH + path;

	var req = superagent[method](url);

	var bar;
	var prev_loaded = 0;
	if (!options.withoutCredentials) req.withCredentials();

	if (!file) {
		// Clean up extra parameters that may have gotten in here
		// if the request came from the CLI module. This is hacky; move elsewhere
		if (params) {
			delete params._;
			delete params.$0;
			req.send(params);
		}
		if (query) {
			delete query._;
			delete query.$0;
			req.query(objectToQueryString(query));
		}
	} else {
		//for file upload params are sent as query params
		req.accept('application/json');
		req.timeout(600000);
		if (query.workspaceFileName && global.paperspace_cli && !query.json) {
			req.on('progress', function _progress(e) {
				if (!bar) bar = new ProgressBar('Uploading ' + node_path.basename(file) + ' [:bar] :rate/bps :percent :etas', {
					complete: '=',
					incomplete: ' ',
					width: 40,
					total: e.total,
				});
				var chunkSize = e.loaded - prev_loaded;
				prev_loaded = e.loaded;
				bar.tick(chunkSize);
			});
		}
		req.attach('file', file);
		delete query._;
		delete query.$0;
		if (query.json) delete query.json;
		req.query(objectToQueryString(query));
	}

	if (headers) {
		for (var headerKey in headers) {
			req.set(headerKey, headers[headerKey]);
		}
	}

	// TODO: Add nicer debug utils? Use the 'debug' module?
	if (debug) {
		console.log(method, url, params, query, headers);
	}

	return req.end(function _requestCallback(err, res) {
		// if content is gzipped, then body is empty object, and content is in 'text'
		var body;
		if (res && res.text) {
			try {
				body = JSON.parse(res.text);
			} catch (parseErr) {
				//console.error(res.text);
				//console.error(parseErr);
				//console.error('res: ' + res)
				//body = {};
				res.body = { message: res.text };
			}
		} else if (res && res.body) { // res.body is expected to be text/json
			body = res.body;
		} else body = {};

		// only return body in callback
		if (cb) return cb(err, body);

		// no callback provided; return the body
		return body;
	});
}
143990
function(params, callback) {
                var url = params.url,
                    fileSize,
                    originalFileName,
                    threadId,
                    fileUniqueId,
                    fileObject,
                    data = params.data,
                    method = (typeof params.method == 'string')
                        ? params.method
                        : 'GET',
                    fileUploadUniqueId = (typeof params.uniqueId == 'string')
                        ? params.uniqueId
                        : 'uniqueId',
                    hasError = false;

                if (!url) {
                    callback({
                        hasError: true,
                        errorCode: 6201,
                        errorMessage: CHAT_ERRORS[6201]
                    });
                    return;
                }

                var hasFile = false;

                httpRequestObject[eval('fileUploadUniqueId')] = new XMLHttpRequest(),
                    settings = params.settings;

                httpRequestObject[eval('fileUploadUniqueId')].timeout = (settings && typeof parseInt(settings.timeout) > 0 && settings.timeout > 0)
                    ? settings.timeout
                    : httpRequestTimeout;

                httpRequestObject[eval('fileUploadUniqueId')]
                    .addEventListener('error', function(event) {
                        if (callback) {
                            if (hasFile) {
                                hasError = true;
                                fireEvent('fileUploadEvents', {
                                    threadId: threadId,
                                    uniqueId: fileUniqueId,
                                    state: 'UPLOAD_ERROR',
                                    progress: 0,
                                    fileInfo: {
                                        fileName: originalFileName,
                                        fileSize: fileSize
                                    },
                                    fileObject: fileObject,
                                    errorCode: 6200,
                                    errorMessage: CHAT_ERRORS[6200] + ' (XMLHttpRequest Error Event Listener)'
                                });
                            }
                            callback({
                                hasError: true,
                                errorCode: 6200,
                                errorMessage: CHAT_ERRORS[6200] + ' (XMLHttpRequest Error Event Listener)'
                            });
                        }
                    }, false);

                httpRequestObject[eval('fileUploadUniqueId')].addEventListener('abort',
                    function(event) {
                        if (callback) {
                            if (hasFile) {
                                hasError = true;
                                fireEvent('fileUploadEvents', {
                                    threadId: threadId,
                                    uniqueId: fileUniqueId,
                                    state: 'UPLOAD_CANCELED',
                                    progress: 0,
                                    fileInfo: {
                                        fileName: originalFileName,
                                        fileSize: fileSize
                                    },
                                    fileObject: fileObject,
                                    errorCode: 6303,
                                    errorMessage: CHAT_ERRORS[6303]
                                });
                            }
                            callback({
                                hasError: true,
                                errorCode: 6303,
                                errorMessage: CHAT_ERRORS[6303]
                            });
                        }
                    }, false);

                try {
                    if (method == 'GET') {
                        if (typeof data === 'object' && data !== null) {
                            var keys = Object.keys(data);

                            if (keys.length > 0) {
                                url += '?';

                                for (var i = 0; i < keys.length; i++) {
                                    var key = keys[i];
                                    url += key + '=' + data[key];
                                    if (i < keys.length - 1) {
                                        url += '&';
                                    }
                                }
                            }
                        }
                        else if (typeof data === 'string' && data !== null) {
                            url += '?' + data;
                        }

                        httpRequestObject[eval('fileUploadUniqueId')].open(method, url, true);

                        if (typeof params.headers === 'object') {
                            for (var key in params.headers) {
                                httpRequestObject[eval('fileUploadUniqueId')].setRequestHeader(key, params.headers[key]);
                            }
                        }

                        httpRequestObject[eval('fileUploadUniqueId')].send();
                    }

                    if (method === 'POST' && data) {

                        httpRequestObject[eval('fileUploadUniqueId')].open(method, url, true);

                        if (typeof params.headers === 'object') {
                            for (var key in params.headers) {
                                httpRequestObject[eval('fileUploadUniqueId')].setRequestHeader(key, params.headers[key]);
                            }
                        }

                        if (typeof data == 'object') {
                            if (data.hasOwnProperty('image') || data.hasOwnProperty('file')) {
                                hasFile = true;
                                var formData = new FormData();
                                for (var key in data) {
                                    formData.append(key, data[key]);
                                }

                                fileSize = data.fileSize;
                                originalFileName = data.originalFileName;
                                threadId = data.threadId;
                                fileUniqueId = data.uniqueId;
                                fileObject = (data['image'])
                                    ? data['image']
                                    : data['file'];

                                httpRequestObject[eval('fileUploadUniqueId')].upload.onprogress = function(event) {
                                    if (event.lengthComputable && !hasError) {
                                        fireEvent('fileUploadEvents', {
                                            threadId: threadId,
                                            uniqueId: fileUniqueId,
                                            state: 'UPLOADING',
                                            progress: Math.round((event.loaded / event.total) * 100),
                                            fileInfo: {
                                                fileName: originalFileName,
                                                fileSize: fileSize
                                            },
                                            fileObject: fileObject
                                        });
                                    }
                                };

                                httpRequestObject[eval('fileUploadUniqueId')].send(formData);
                            }
                            else {
                                httpRequestObject[eval('fileUploadUniqueId')].setRequestHeader(
                                    'Content-Type',
                                    'application/x-www-form-urlencoded');

                                var keys = Object.keys(data);

                                if (keys.length > 0) {
                                    sendData = '';

                                    for (var i = 0; i < keys.length; i++) {
                                        var key = keys[i];
                                        sendData += key + '=' + data[key];
                                        if (i < keys.length - 1) {
                                            sendData += '&';
                                        }
                                    }
                                }

                                httpRequestObject[eval('fileUploadUniqueId')].send(sendData);
                            }
                        }
                        else {
                            httpRequestObject[eval('fileUploadUniqueId')].send(data);
                        }
                    }
                }
                catch (e) {
                    callback && callback({
                        hasError: true,
                        cache: false,
                        errorCode: 6200,
                        errorMessage: CHAT_ERRORS[6200] + ' (Request Catch Error)' + e
                    });
                }

                httpRequestObject[eval('fileUploadUniqueId')].onreadystatechange = function() {
                    if (httpRequestObject[eval('fileUploadUniqueId')].readyState == 4) {
                        if (httpRequestObject[eval('fileUploadUniqueId')].status == 200) {
                            if (hasFile) {
                                hasError = false;
                                fireEvent('fileUploadEvents', {
                                    threadId: threadId,
                                    uniqueId: fileUniqueId,
                                    state: 'UPLOADED',
                                    progress: 100,
                                    fileInfo: {
                                        fileName: originalFileName,
                                        fileSize: fileSize
                                    },
                                    fileObject: fileObject
                                });
                            }

                            callback && callback({
                                hasError: false,
                                cache: false,
                                result: {
                                    responseText: httpRequestObject[eval('fileUploadUniqueId')].responseText,
                                    responseHeaders: httpRequestObject[eval('fileUploadUniqueId')].getAllResponseHeaders()
                                }
                            });
                        }
                        else {
                            if (hasFile) {
                                hasError = true;
                                fireEvent('fileUploadEvents', {
                                    threadId: threadId,
                                    uniqueId: fileUniqueId,
                                    state: 'UPLOAD_ERROR',
                                    progress: 0,
                                    fileInfo: {
                                        fileName: originalFileName,
                                        fileSize: fileSize
                                    },
                                    fileObject: fileObject,
                                    errorCode: 6200,
                                    errorMessage: CHAT_ERRORS[6200] + ' (Request Status != 200)',
                                    statusCode: httpRequestObject[eval('fileUploadUniqueId')].status
                                });
                            }
                            callback && callback({
                                hasError: true,
                                errorMessage: httpRequestObject[eval('fileUploadUniqueId')].responseText,
                                errorCode: httpRequestObject[eval('fileUploadUniqueId')].status
                            });
                        }
                    }
                };
            }
150114
function query(params, callback) {
  const args = utils.getArgs(params, [config], callback);
  const url = `http://${args.options.ip}:${args.options.port}/`;

  return request.get({
    url,
    qs: args.options,
  }, function(err, res, body) {
    if (err) {
      return args.callback(err);
    }
    return args.callback(null, body);
  });
}
415671
function (args, callback) {
        ternserver.addFile(args.file, args.source);
        callback({request: 'addFile'}); //$NON-NLS-1$
      }
1084272
function serializeParams(params) {
  for (var key in params) {
    var param = params[key];
    if (param instanceof MediaObject || (param && (params.object !==
        undefined ||
        params.hub !== undefined || params.sink !== undefined))) {
      if (param && param.id != null) {
        params[key] = param.id;
      }
    }
  };

  return params;
}