Split given URI into a tuple of (protocol, module URI, attribute chain).

    @param mod_attr_sep: the separator between module name and attribute name.
484020
def split_uri(uri, mod_attr_sep='::'):
    
    uri_parts = uri.split(mod_attr_sep, 1)

    if len(uri_parts) == 2:
        mod_uri, attr_chain = uri_parts
    else:
        mod_uri = uri_parts[0]

        attr_chain = None

    if mod_uri.startswith('py://'):
        protocol = 'py'

        mod_uri = mod_uri[5:]

    elif mod_uri.startswith('file://'):
        protocol = 'file'

        mod_uri = mod_uri[7:]

    # If no protocol prefix is present, and the uri ends with `.py`, then
    # consider the uri as module file path instead of module name.
    elif mod_uri.endswith('.py'):
        protocol = 'file'

    else:
        protocol = 'py'

    info = (protocol, mod_uri, attr_chain)

    return info
638437
def make_initstr(modname, import_tuples, verbose=False):
    
    imports = [tup[0] for tup in import_tuples]
    from_imports = __get_from_imports(import_tuples)
    inject_execstr = _inject_execstr(modname, import_tuples)
    return _initstr(modname, imports, from_imports, inject_execstr)
1103169
def attributes_strToDict(astr_attributes, astr_separator=" "):
  
  adict = {}
  alist = str2lst(astr_attributes, astr_separator)
  for str_pair in alist:
    alistTuple = str2lst(str_pair, "=")
    adict.setdefault(alistTuple[0], alistTuple[1].strip(chr(0x22) + chr(0x27)))
  return adict
912211
def urisplit(uri):
    
    inner_part = re.compile(r'\(\(.*?\)\)')
    m = inner_part.search(uri)
    inner_value = ''
    if m is not None:
        inner_value = uri[m.start():m.end()]
        uri = uri[:m.start()]+'__inner_part__'+uri[m.end():]
    # regex straight from STD 66 section B
    regex = '^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?'
    p = re.match(regex, uri).groups()
    scheme, authority, path, query, fragment = p[1], p[3], p[4], p[6], p[8]
    #if not path: path = None
    authority = authority.replace('__inner_part__', inner_value)
    if authority == '.':
        path = ''.join([authority, path])
        authority = None
    # bugfix: '#' might be a legal character in a file name
    # it only has special meaning in urls
    if scheme not in ['http', 'https']:
        if fragment:
            path = '#'.join([path, fragment])
            fragment = ''
    return (scheme, authority, path, query, fragment)
392368
def urlsplit(url):
    
    p = '((?P<scheme>.*)?.*://)?(?P<host>[^:/ ]+).?(?P<port>[0-9]*).*'
    m = re.search(p, url)
    scheme = m.group('scheme')
    host = m.group('host')
    port = m.group('port')

    _scheme, _netloc, path, query, _fragment = tuple(py_urlsplit(url))

    return scheme, host, port, path, query
1129638
function parseUri(str) {
    var parser = re.uri_parser;
    var parserKeys = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "isColonUri", "relative", "path", "directory", "file", "query", "anchor"];
    var m = parser.exec(str || '');
    var parts = {};

    parserKeys.forEach(function(key, i) {
      parts[key] = m[i] || '';
    });

    return parts;
  }
1187369
function splitIntoSlabs(str) {
  var slabs = str.split('<!-- TEXTBLOCK -->');
  return slabs.map(function(val, index, array) {
    if (index % 2 == 1) {
      var rawAttr = val.match(/<code>(.*)<\/code>/);
      var attrs = JSON.parse(decodeURI(rawAttr[1]));
      return attrs;
    } else {
      return val;
    }
  });
}
1304864
private void parseAttribute(final Attributes atts) {
        final URI attrValue = toURI(atts.getValue(ATTRIBUTE_NAME_HREF));
        if (attrValue == null) {
            return;
        }

        final String attrScope = atts.getValue(ATTRIBUTE_NAME_SCOPE);
        if (isExternal(attrValue, attrScope)) {
            return;
        }

        String attrFormat = atts.getValue(ATTRIBUTE_NAME_FORMAT);
        if (attrFormat == null || ATTR_FORMAT_VALUE_DITA.equals(attrFormat)) {
            final File target = toFile(attrValue);
            topicHref = target.isAbsolute() ? attrValue : currentDir.resolve(attrValue);

            if (attrValue.getFragment() != null) {
                topicId = attrValue.getFragment();
            } else {
                if (attrFormat == null || attrFormat.equals(ATTR_FORMAT_VALUE_DITA) || attrFormat.equals(ATTR_FORMAT_VALUE_DITAMAP)) {
                    topicId = topicHref + QUESTION;
                }
            }
        } else {
            topicHref = null;
            topicId = null;
        }
    }
758546
def split_pkt(pkt, assoclen, icvlen=0):
        
        data = raw(pkt)
        assoc = data[:assoclen]
        if icvlen:
            icv = data[-icvlen:]
            enc = data[assoclen:-icvlen]
        else:
            icv = b''
            enc = data[assoclen:]
        return assoc, enc, icv
1243466
def get_attr(name):
    
    i = name.rfind('.')
    cls = str(name[i+1:])
    module = str(name[:i])

    mod = __import__(module, fromlist=[cls])
    return getattr(mod, cls)
679521
def _import_attr_n_module(module_name, attr):
    
    __import__(module_name)
    module = sys.modules[module_name]
    attr = getattr(module, attr)
    return attr, module
305521
def parse_url(url):
    
    split_url = url.split('/', 3)
    if len(split_url) == 3:
        # http://foo.com
        path = '/'
    elif len(split_url) == 4:
        path = '/' + split_url[3]
    else:
        raise ValueError('Invalid URL: %s' % url)

    try:
        parse_result = urlparse(url)
    except Exception:
        raise ValueError('Invalid URL: %s' % url)

    protocol = parse_result.scheme
    protocol = protocol.lower()
    if protocol not in ('http', 'https'):
        raise ValueError('Invalid URL protocol "%s"' % protocol)

    split_netloc = parse_result.netloc.split(':')
    domain = split_netloc[0]
    domain = domain.lower()

    if len(split_netloc) == 2:
        try:
            port = int(split_netloc[1])
        except:
            raise ValueError('Invalid port: "%s"' % split_netloc[1])
    elif protocol == 'https':
        port = 443
    elif protocol == 'http':
        port = 80
    else:
        raise ValueError('Invalid scheme: "%s"' % protocol)

    return protocol, domain, port, path
524785
def uriunsplit(uri):
    
    (scheme, authority, path, query, fragment) = uri
    result = ''
    if scheme:
        result += scheme + ':'
    if authority:
        result += '//' + authority
    if path:
        result += path
    if query:
        result += '?' + query
    if fragment:
        result += '#' + fragment
    return result
1329809
def links_duplicate_on(attribute, separator)
      links.map do  |link|
        link.send(attribute).split(separator).collect do |value|
          link.dup.update(Hash[attribute, value])
        end
      end.flatten
    end
1241479
def split_file_uri(uri)
      scheme, _, host, _, _, path, _, query, _ = URI.split(uri)

      path = URI::Generic::DEFAULT_PARSER.unescape(path)
      path.force_encoding(Encoding::UTF_8)

      # Hack for parsing Windows "/C:/Users/IEUser" paths
      if File::ALT_SEPARATOR && path[2] == ':'
        path = path[1..-1]
      end

      [scheme, host, path, query]
    end
1038143
def split_vcs_method_from_uri(uri):
    # type: (AnyStr) -> Tuple[Optional[STRING_TYPE], STRING_TYPE]
    """"""
    vcs_start = "{0}+"
    vcs = None  # type: Optional[STRING_TYPE]
    vcs = first([vcs for vcs in VCS_LIST if uri.startswith(vcs_start.format(vcs))])
    if vcs:
        vcs, uri = uri.split("+", 1)
    return vcs, uri
143773
def split_metadata(data, splitter, name_value_delimiter = '=')
      hash = {}
      data.to_s.split(splitter).each do |pair|
        name, value = pair.split(name_value_delimiter, 2)
        hash[name.strip] = value.strip if name && value
      end
      hash
    end