This produces a canonical string.

RFC 5952 describes canonical representations.
http://en.wikipedia.org/wiki/IPv6_address#Recommended_representation_as_text
http://tools.ietf.org/html/rfc5952
198083
@Override
	public String toCanonicalString() {
		String result;
		if(hasNoStringCache() || (result = stringCache.canonicalString) == null) {
			stringCache.canonicalString = result = toNormalizedString(IPv6StringCache.canonicalParams);
		}
		return result;
	}
362482
def generate_canonical_request(method, parsed_url, headers, signed_headers, content_sha256):
    
    lines = [method, parsed_url.path, parsed_url.query]

    # Headers added to canonical request.
    header_lines = []
    for header in signed_headers:
        value = headers[header.title()]
        value = str(value).strip()
        header_lines.append(header + ':' + str(value))

    lines = lines + header_lines
    lines.append('')

    lines.append(';'.join(signed_headers))
    lines.append(content_sha256)
    return '\n'.join(lines)
1049292
def canonical_text(self, text):
        
        out = []
        line_continues_a_comment = False
        for line in text.splitlines():
            line,comment = self.comment_re.findall(line)[0]
            if line_continues_a_comment == True:
                out[-1] = out[-1] + line.lstrip()
            else:
                out.append(line)
            line_continues_a_comment = len(comment) > 0
        return '\n'.join(out).rstrip()+'\n'
628379
def _to_string(self):
        
        return u"{}+{}@{}".format(text_type(self.definition_id), self.BLOCK_TYPE_PREFIX, self.block_type)
393967
def encode(self, b64=False, always_bytes=True):
        """"""
        if self.binary and not b64:
            encoded_packet = six.int2byte(self.packet_type)
        else:
            encoded_packet = six.text_type(self.packet_type)
            if self.binary and b64:
                encoded_packet = 'b' + encoded_packet
        if self.binary:
            if b64:
                encoded_packet += base64.b64encode(self.data).decode('utf-8')
            else:
                encoded_packet += self.data
        elif isinstance(self.data, six.string_types):
            encoded_packet += self.data
        elif isinstance(self.data, dict) or isinstance(self.data, list):
            encoded_packet += self.json.dumps(self.data,
                                              separators=(',', ':'))
        elif self.data is not None:
            encoded_packet += str(self.data)
        if always_bytes and not isinstance(encoded_packet, binary_types):
            encoded_packet = encoded_packet.encode('utf-8')
        return encoded_packet
599214
def _string_from_ip_int(self, ip_int):
        
        octets = []
        for _ in xrange(4):
            octets.insert(0, str(ip_int & 0xFF))
            ip_int >>= 8
        return '.'.join(octets)
65029
public static String referenceIdentifierToString(byte[] ref, short stratum, byte version) {
	// From the RFC 2030:
	// In the case of NTP Version 3 or Version 4 stratum-0 (unspecified)
	// or stratum-1 (primary) servers, this is a four-character ASCII
	// string, left justified and zero padded to 32 bits.
	if (stratum == 0 || stratum == 1) {
	    return new String(ref);
	}

	// In NTP Version 3 secondary servers, this is the 32-bit IPv4
	// address of the reference source.
	else if (version == 3) {
	    return unsignedByteToShort(ref[0]) + "." + unsignedByteToShort(ref[1]) + "." + unsignedByteToShort(ref[2]) + "." + unsignedByteToShort(ref[3]);
	}

	// In NTP Version 4 secondary servers, this is the low order 32 bits
	// of the latest transmit timestamp of the reference source.
	else if (version == 4) {
	    return "" + ((unsignedByteToShort(ref[0]) / 256.0) + (unsignedByteToShort(ref[1]) / 65536.0) + (unsignedByteToShort(ref[2]) / 16777216.0)
		    + (unsignedByteToShort(ref[3]) / 4294967296.0));
	}

	return "";
    }
209276
def gen_str_to_sign(self, req):
        """"""
        url = urlsplit(req.url)
        bucket_name = url.netloc.split(".", 1)[0]

        logger.debug(req.headers.items())
        ucloud_headers = [
            (k, v.strip())
            for k, v in sorted(req.headers.lower_items())
            if k.startswith("x-ucloud-")
        ]
        canonicalized_headers = "\n".join([
            "{0}:{1}".format(k, v) for k, v in ucloud_headers
        ])

        canonicalized_resource = "/{0}{1}".format(
            bucket_name,
            unquote(url.path)
        )

        str_to_sign = "\n".join([
            req.method,
            req.headers.get("content-md5", ""),
            req.headers.get("content-type", ""),
            req.headers.get("date", self._expires),
            canonicalized_headers + canonicalized_resource
        ])
        return str_to_sign
1134446
def _explode_shorthand_ip_string(self):
        
        if isinstance(self, IPv6Network):
            ip_str = str(self.network_address)
        elif isinstance(self, IPv6Interface):
            ip_str = str(self.ip)
        else:
            ip_str = str(self)

        ip_int = self._ip_int_from_string(ip_str)
        hex_str = '%032x' % ip_int
        parts = [hex_str[x:x+4] for x in range(0, 32, 4)]
        if isinstance(self, (_BaseNetwork, IPv6Interface)):
            return '%s/%d' % (':'.join(parts), self._prefixlen)
        return ':'.join(parts)
144289
def canonical_write( str )
      return self if @io.nil?
      str = str.force_encoding(encoding) if encoding and str.encoding != encoding
      @io.syswrite str
      self
    rescue StandardError => err
      self.level = :off
      ::Logsly::Logging182.log_internal {"appender #{name.inspect} has been disabled"}
      ::Logsly::Logging182.log_internal(-2) {err}
    end
106218
def stringify_address(addr, encoding='utf-8'):
    
    if isinstance(addr, bytes_type):
        return addr
    try:
        addr = addr.encode('ascii')
    except UnicodeEncodeError:
        if '@' in addr:
            localpart, domain = addr.split('@', 1)
            addr = b'@'.join([
                localpart.encode(encoding),
                domain.encode('idna'),
            ])
        else:
            addr = addr.encode(encoding)
    return addr.decode('utf-8')
803910
private static String formatAddress6(int[] hexRepresentation){
       if(hexRepresentation == null){
           throw new NullPointerException();
       }
       if(hexRepresentation.length != IPV6_LEN){
           throw new IllegalArgumentException();
       }
       StringBuilder stringBuilder = new StringBuilder();
       boolean inCompressedSection = false;
       for(int i = 0;i<hexRepresentation.length;i++){
           if(hexRepresentation[i] == -1){
               if(!inCompressedSection){
                   inCompressedSection = true;
                   if(i == 0){
                       stringBuilder.append("::");
                   } else {
                       stringBuilder.append(':');
                   }
               }
           } else {
               inCompressedSection = false;
               stringBuilder.append(Integer.toHexString(hexRepresentation[i]));
               if(i+1<hexRepresentation.length){
                   stringBuilder.append(":");
               }
           }
       }
       return stringBuilder.toString();
    }
412245
def _str(val):
    
    if str == bytes:
        if isinstance(val, str):
            return val
        else:
            return str(val)
    else:
        if isinstance(val, str):
            return val
        else:
            return str(val, 'ascii')
580421
def encode(self, raw_string, add_eos=False):
    """"""
    ret = []
    tokens = _split_string_to_tokens(_native_to_unicode(raw_string))
    for token in tokens:
      ret.extend(self._token_to_subtoken_ids(token))
    if add_eos:
      ret.append(EOS_ID)
    return ret
225953
def ipv6_to_str(ip):
    
    if isinstance(ip, numbers.Integral):
        return addrconv.ipv6.bin_to_text(type_desc.Int16.from_user(ip))
    else:
        return addrconv.ipv6.bin_to_text(ip)
122633
String
rrToString() {
	InetAddress addr;
	try {
		addr = InetAddress.getByAddress(null, address);
	} catch (UnknownHostException e) {
		return null;
	}
	if (addr.getAddress().length == 4) {
		// Deal with Java's broken handling of mapped IPv4 addresses.
		StringBuffer sb = new StringBuffer("0:0:0:0:0:ffff:");
		int high = ((address[12] & 0xFF) << 8) + (address[13] & 0xFF);
		int low = ((address[14] & 0xFF) << 8) + (address[15] & 0xFF);
		sb.append(Integer.toHexString(high));
		sb.append(':');
		sb.append(Integer.toHexString(low));
		return sb.toString();
	}
	return addr.getHostAddress();
}
1156456
def canonical_write( str )
      return self if @io.nil?

      str = str.force_encoding(encoding) if encoding && str.encoding != encoding
      @io.flock_sh { @io.write str }

      if roll_required?
        @io.flock? {
          @age_fn_mtime = nil
          copy_truncate if roll_required?
        }
        @roller.roll_files
      end
      self
    rescue StandardError => err
      self.level = :off
      ::Logging.log_internal {"appender #{name.inspect} has been disabled"}
      ::Logging.log_internal_error(err)
    end