Encode multi form parameters
543168
public static String encodeForms(Collection<? extends Parameter<String>> queries, Charset charset) {
        StringBuilder sb = new StringBuilder();
        try {
            for (Parameter<String> query : queries) {
                sb.append(URLEncoder.encode(query.name(), charset.name()));
                sb.append('=');
                sb.append(URLEncoder.encode(query.value(), charset.name()));
                sb.append('&');
            }
        } catch (UnsupportedEncodingException e) {
            // should not happen
            throw new RequestsException(e);
        }
        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1);
        }
        return sb.toString();
    }
1151891
protected void encodeOptionalParameters(Map<Integer, ISUPParameter> parameters, ByteArrayOutputStream bos)
            throws ParameterException {

        // NOTE: parameters MUST have as last endOfOptionalParametersParameter+1
        // param
        for (ISUPParameter p : parameters.values()) {

            if (p == null)
                continue;

            byte[] b = ((AbstractISUPParameter) p).encode();
            // System.err.println("ENCODE O: "+p.getCode()+"---> "+Utils.toHex(b));
            // FIXME: this can be slow, maybe we shoudl remove that, and code
            // this explicitly?
            if (b.length > 255) {
                throw new ParameterException("Parameter length is over 255: " + p);
            }
            if (!(p instanceof EndOfOptionalParametersImpl)) {
                bos.write(p.getCode());

                bos.write(b.length);
            }
            try {
                bos.write(b);
            } catch (IOException e) {
                throw new ParameterException("Failed to encode optional parameters.", e);
            }
        }

    }
178513
def wrap_form_params(func):
    

    @functools.wraps(func)
    def wrapper(request, *args, **kwargs):
        ctype, pdict = parse_header(request.headers.get('Content-Type', ''))
        if ctype == "application/x-www-form-urlencoded":
            params = {}
            for key, value in parse_qs(request.body.decode("utf-8")).items():
                if len(value) == 1:
                    params[key] = value[0]
                else:
                    params[key] = value

            request.params = merge_dicts(getattr(request, "params", None), params)
            request.form_params = params
        return func(request, *args, **kwargs)
    return wrapper
1059470
def _EncodeParameters(self, parameters):
        

        if parameters is None:
            return None
        else:
            return urlencode(dict([(k, self._Encode(v)) for k, v in list(parameters.items()) if v is not None]))
261121
def encode(params)
      return nil if params.nil?

      unless params.is_a?(Array)
        unless params.respond_to?(:to_hash)
          raise TypeError, "Can't convert #{params.class} into Hash."
        end

        params = params.to_hash
        params = params.map do |key, value|
          key = key.to_s if key.is_a?(Symbol)
          [key, value]
        end
        # Useful default for OAuth and caching.
        # Only to be used for non-Array inputs. Arrays should preserve order.
        params.sort!
      end

      # The params have form [['key1', 'value1'], ['key2', 'value2']].
      buffer = +''
      params.each do |parent, value|
        encoded_parent = escape(parent)
        buffer << "#{encode_pair(encoded_parent, value)}&"
      end
      buffer.chop
    end
106905
public static String encodeForm(Parameter<String> query, Charset charset) {
        try {
            return URLEncoder.encode(query.name(), charset.name()) + "=" + URLEncoder.encode(query.value(),
                    charset.name());
        } catch (UnsupportedEncodingException e) {
            // should not happen
            throw new RequestsException(e);
        }
    }
686318
def encode_mv(vals):
    """'"""
    s = ""
    for val in vals:
        val = val.replace('$', '$$')
        if len(s) > 0:
            s += ';'
        s += '$' + val + '$'

    return s
273458
public static String urlWithForm(String url, Map<String, Object> form, Charset charset, boolean isEncodeParams) {
		if (isEncodeParams && StrUtil.contains(url, '?')) {
			// 在需要编码的情况下，如果url中已经有部分参数，则编码之
			url = encodeParams(url, charset);
		}

		// url和参数是分别编码的
		return urlWithForm(url, toParams(form, charset), charset, false);
	}
464732
function encodeUriParameterValue(value) {
    return encodeURIComponent(value).
    replace(/%40/gi, '@').
    replace(/%3A/gi, ':').
    replace(/%24/g, '$').
    replace(/%2C/gi, ',').
    replace(/%3B/gi, ';').
    replace(/%20/g, '+');
}
71281
def encode_multipart_formdata(self, fields, files, baseName, verbose=False):
        
        BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
        CRLF = '\r\n'
        content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
        if verbose is True:
            print(('Encoding ' + baseName + ' for upload...'))
        fin = self._open(files, 'rb')
        fout = self._open(files + '.b64', 'wb')
        fout.write(bytearray('--' + BOUNDARY + CRLF, 'utf-8'))
        fout.write(bytearray('Content-Disposition: form-data'
                             '; name="file"; filename="' + baseName + '"' + CRLF, "utf-8"))
        fout.write(bytearray('Content-Type: application/octet-stream' + CRLF,
                             'utf-8'))
        fout.write(bytearray(CRLF, 'utf-8'))
        shutil.copyfileobj(fin, fout)
        fout.write(bytearray(CRLF, 'utf-8'))
        fout.write(bytearray('--' + BOUNDARY + '--' + CRLF, 'utf-8'))
        fout.write(bytearray(CRLF, 'utf-8'))
        fout.close()
        fin.close()
        return content_type
945256
function uriEncodeParams( obj ){
    var pairs = [], key;
    for( key in obj ){
        pairs.push( uriEncodeString(key) +'='+ uriEncodeString(obj[key]) );
    }
    return pairs.join('&');
}
677335
def encode_inputs(self):
        """"""
        litmap = dict()
        nvars = 0
        for i, v in enumerate(self.inputs, start=1):
            litmap[v] = i
            litmap[~v] = -i
            litmap[i] = v
            litmap[-i] = ~v
            nvars += 1
        return litmap, nvars
11458
def encode_params_utf8(params):
    
    encoded = []
    for k, v in params:
        encoded.append((
            k.encode('utf-8') if isinstance(k, unicode_type) else k,
            v.encode('utf-8') if isinstance(v, unicode_type) else v))
    return encoded
9536
def encode_multipart_formdata(fields, files):
    
    BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
    CRLF = '\r\n'
    L = []
    for (key, value) in fields:
        L.append('--' + BOUNDARY)
        L.append('Content-Disposition: form-data; name="%s"' % key)
        L.append('')
        L.append(value)
    for (key, filename, value) in files:
        L.append('--' + BOUNDARY)
        L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
        L.append('Content-Type: %s' % guess_content_type(filename))
        L.append('')
        L.append(value)
    L.append('--' + BOUNDARY + '--')
    L.append('')
    body = CRLF.join(L)
    content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
    return content_type, body
196085
function(params) {
			var newparams = ''; 
			
			for (par in params) {
				var obj = params[par];
				if(typeof obj ==  'string'){
					if (params[par]) {
						if(newparams)newparams += "&";
						newparams += par + "=" + params[par];
					}
				}else if(obj instanceof  Array){
					if(newparams)newparams += "&";
					
					var i = 0;
					for(i=0; i<obj.length; i++){
						if (obj[i]) {
							newparams += par + "=" + obj[i];
							if(i != obj.length-1)newparams += ";";
						}
						
					}
				}
			}
			//newparams=newparams.encode();
			//encode(newparams);
			//return escape('?'+newparams);
			return encodeURI('?'+newparams); //The old version (escape('?'+newparams);) gave problems because it encoded ? and &
		}
1113991
function(data) {
			data = data || {};
			var paramNames = Object.keys(data);
			var buf = [];
			for (var i=0; i < paramNames.length; i++) {
				var param = paramNames[i], value = data[param];
				buf.push(x_www_form_urlencode(param) + '=' + x_www_form_urlencode(value)); //$NON-NLS-0$
			}
			return buf.join('&'); //$NON-NLS-0$
		}
197705
def parse_form_encoded(data)
      data.split(/[&;]/).map do |pair|
        key, value = pair.split('=', 2).map { |v| CGI::unescape(v) }
        [key, value] unless [nil, ''].include?(key)
      end.compact
    end