def docid(url, encoding='ascii'):
    """Get DocID from URL.

    DocID generation depends on bytes of the URL string.
    So, if non-ascii charactors in the URL, encoding should
    be considered properly.

    Args:
        url (str or bytes): Pre-encoded bytes or string will be encoded with the
            'encoding' argument.
        encoding (str, optional): Defaults to 'ascii'. Used to encode url argument
            if it is not pre-encoded into bytes.

    Returns:
        DocID: The DocID object.

    Examples:

        >>> from os_docid import docid

        >>> docid('http://www.google.com/')
        1d5920f4b44b27a8-ed646a3334ca891f-ff90821feeb2b02a33a6f9fc8e5f3fcd

        >>> docid('1d5920f4b44b27a8-ed646a3334ca891f-ff90821feeb2b02a33a6f9fc8e5f3fcd')
        1d5920f4b44b27a8-ed646a3334ca891f-ff90821feeb2b02a33a6f9fc8e5f3fcd

        >>> docid('1d5920f4b44b27a8ed646a3334ca891fff90821feeb2b02a33a6f9fc8e5f3fcd')
        1d5920f4b44b27a8-ed646a3334ca891f-ff90821feeb2b02a33a6f9fc8e5f3fcd

        >>> docid('abc')  
        NotImplementedError: Not supported data format

    """

    if not isinstance(url, bytes):
        url = url.encode(encoding)

    parser = _URL_PARSER
    idx = 0
    for _c in url:
        if _c not in _HEX:
            if not (_c == _SYM_MINUS and (idx == _DOMAINID_LENGTH
                                          or idx == _HOSTID_LENGTH + 1)):
                return parser.parse(url, idx)
        idx += 1
        if idx > 4:
            break
    _l = len(url)
    if _l == _DOCID_LENGTH:
        parser = _DOCID_PARSER
    elif _l == _READABLE_DOCID_LENGTH \
            and url[_DOMAINID_LENGTH] == _SYM_MINUS \
            and url[_HOSTID_LENGTH + 1] == _SYM_MINUS:
        parser = _R_DOCID_PARSER
    else:
        parser = _PARSER

    return parser.parse(url, idx)