获取磁链的信息.
    
    在新建磁链任务时, 要先获取这个磁链的信息, 比如里面包含哪些文件, 文件的名
    称与大小等.

    source_url - 磁链的url, 以magent:开头.
    save_path  - 保存到哪个目录
544899
def cloud_query_magnetinfo(cookie, tokens, source_url, save_path):
    '''
    '''
    url = ''.join([
        const.PAN_URL,
        'rest/2.0/services/cloud_dl?channel=chunlei&clienttype=0&web=1',
        '&bdstoken=', tokens['bdstoken'],
    ])
    data = ''.join([
        'method=query_magnetinfo&app_id=250528',
        '&source_url=', encoder.encode_uri_component(source_url),
        '&save_path=', encoder.encode_uri_component(save_path),
        '&type=4',
    ])
    req = net.urlopen(url, headers={'Cookie': cookie.header_output()},
                      data=data.encode())
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None
859892
def _save(self, url, path, data):
        """"""
        worker = self._workers[url]
        path = self._paths[url]

        if len(data):
            try:
                with open(path, 'wb') as f:
                    f.write(data)
            except Exception:
                logger.error((url, path))

        # Clean up
        worker.finished = True
        worker.sig_download_finished.emit(url, path)
        worker.sig_finished.emit(worker, path, None)
        self._get_requests.pop(url)
        self._workers.pop(url)
        self._paths.pop(url)
1144914
def to_dir_path_url(url_info: URLInfo) -> str:
    ''''''
    dir_name = posixpath.dirname(url_info.path)

    if not dir_name.endswith('/'):
        url_template = 'ftp://{}{}/'
    else:
        url_template = 'ftp://{}{}'

    return url_template.format(url_info.hostname_with_port, dir_name)
1011097
function analyUrl(ctx, path) {
    // 如果是标准的url，则以http或者https开头
    // 则直接发送请求不做处理
    let isUrl = /^(http:\/\/|https:\/\/)/;
    if (isUrl.test(path)) {
      return {
        url: path,
        method: ctx.method
      }
    }

    // 否则，用"?"切分URL："?"前部用以解析真实的URL
    let urlQueryArr = path.split('?');
    let urlPrefix = urlQueryArr[0] || '';

    // url前部只能包含1个或2个":"，否则报错
    let urlReg = urlPrefix.split(':');
    if (urlReg.length < 2 || urlReg.length > 3) {
      throw `Illegal proxy path：${path} !`;
    }

    let [apiName, urlMethod, urlPath] = urlReg;
    let urlOrigin = getOriginApi(api, apiName);

    if (!urlPath) {
      urlPath = urlMethod;
      urlMethod = ctx.method;
    }

    // 拼接URL
    let urlHref = url_opera.resolve(urlOrigin, urlPath)
    return {
      url: path.replace(urlPrefix, urlHref),
      method: urlMethod.toUpperCase()
    }
  }
696526
def _get_dest_file_and_url(self, filepath, page_meta={}):
        

        filename = filepath.split("/")[-1]
        filepath_base = filepath.replace(filename, "").rstrip("/")
        slug = page_meta.get("slug")
        fname = slugify(slug) if slug else filename \
            .replace(".html", "") \
            .replace(".md", "") \
            .replace(".jade", "")

        if page_meta.get("pretty_url") is False:
            dest_file = os.path.join(filepath_base, "%s.html" % fname)
        else:
            dest_dir = filepath_base
            if filename not in ["index.html", "index.md", "index.jade"]:
                dest_dir = os.path.join(filepath_base, fname)
            dest_file = os.path.join(dest_dir, "index.html")

        url = "/" + dest_file.replace("index.html", "")
        return dest_file, url
528611
function (path, cb) {
    if ($bc_.pN) {
      try {
        var params = {}
        // 限制内部属性：
        params['callback'] = params['callback'] || $bc_._get_callback(function (obj) {
          cb && cb(obj)
        }, true)
        params['path'] = path || ($bc_.pN.path.tempDir() + '/tmp_dir001')

        return $bc_.pN.window.getOtherAppInfo(JSON.stringify(params))
      } catch (e) {
        console.error(e)
      }
    }

    return ''
  }
419151
def url_path(request, base_url=None, is_full=False, *args, **kwargs):
    
    if not base_url:
        base_url = request.path
        if is_full:
            protocol = 'https' if request.is_secure() else 'http'
            base_url = '%s://%s%s' % (protocol, request.get_host(), base_url)

    params = url_params(request, *args, **kwargs)
    url = '%s%s' % (base_url, params)
    return url
364017
def get_max_url_file_name_length(savepath):
        
        number_occurrences = savepath.count('%max_url_file_name')
        number_occurrences += savepath.count('%appendmd5_max_url_file_name')

        savepath_copy = savepath
        size_without_max_url_file_name = len(
            savepath_copy.replace('%max_url_file_name', '')
                .replace('%appendmd5_max_url_file_name', '')
        )

        # Windows: max file path length is 260 characters including
        # NULL (string end)
        max_size = 260 - 1 - size_without_max_url_file_name
        max_size_per_occurrence = max_size / number_occurrences

        return max_size_per_occurrence
999390
def save_facts(self, path, mode=SaveMode.LOCAL_SAVE):
        
        ret = lib.EnvSaveFacts(self._env, path.encode(), mode)
        if ret == -1:
            raise CLIPSError(self._env)

        return ret
943166
def path_to_url(path):
    # type: (Union[str, Text]) -> str
    
    path = os.path.normpath(os.path.abspath(path))
    url = urllib_parse.urljoin('file:', urllib_request.pathname2url(path))
    return url
616009
def get_file_url_for_heroku_app(self, source_app):
        
        self.print_message("Getting backup url for Heroku app '%s'" % source_app)
        args = [
            "heroku",
            "pg:backups:url",
            "--app=%s" % source_app,
        ]
        if self.args.use_pgbackups:
            args = [
                "heroku",
                "pgbackups:url",
                "--app=%s" % source_app,
            ]
        return subprocess.check_output(args).strip().decode('ascii')
1211150
def get_real_layer_path(self, path):
        
        filename = path.split('/')[-1]
        local_path = path
        filetype = os.path.splitext(filename)[1]

        # Url
        if re.match(r'^[a-zA-Z]+://', path):
            local_path = os.path.join(DATA_DIRECTORY, filename)

            if not os.path.exists(local_path):
                sys.stdout.write('* Downloading %s...\n' % filename)
                self.download_file(path, local_path)
            elif self.args.redownload:
                os.remove(local_path)

                sys.stdout.write('* Redownloading %s...\n' % filename)
                self.download_file(path, local_path)
        # Non-existant file
        elif not os.path.exists(local_path):
            raise Exception('%s does not exist' % local_path)

        real_path = path

        # Zip files
        if filetype == '.zip':
            slug = os.path.splitext(filename)[0]
            real_path = os.path.join(DATA_DIRECTORY, slug)

            if not os.path.exists(real_path):
                sys.stdout.write('* Unzipping...\n')
                self.unzip_file(local_path, real_path)

        return real_path
130601
function dumpSourceToFile(sourcecode, errname, err_id, options, ex) {
    var dumpfile;

    try {
        var dumpPaths = [(options.outfile ? path.dirname(options.outfile) : null), options.inputPath, process.cwd()];
        var dumpName = path.basename(options.inputFilename || options.moduleName || (options.outfile ? path.dirname(options.outfile) : null) || options.defaultModuleName || errname)
        .replace(/\.[a-z]{1,5}$/i, '')          // remove extension .y, .yacc, .jison, ...whatever
        .replace(/[^a-z0-9_]/ig, '_');          // make sure it's legal in the destination filesystem: the least common denominator.
        if (dumpName === '' || dumpName === '_') {
            dumpName = '__bugger__';
        }
        err_id = err_id || 'XXX';

        var ts = new Date();
        var tm = ts.getUTCFullYear() +
            '_' + pad(ts.getUTCMonth() + 1) +
            '_' + pad(ts.getUTCDate()) +
            'T' + pad(ts.getUTCHours()) +
            '' + pad(ts.getUTCMinutes()) +
            '' + pad(ts.getUTCSeconds()) +
            '.' + pad(ts.getUTCMilliseconds(), 3) +
            'Z';

        dumpName += '.fatal_' + err_id + '_dump_' + tm + '.js';

        for (var i = 0, l = dumpPaths.length; i < l; i++) {
            if (!dumpPaths[i]) {
                continue;
            }

            try {
                dumpfile = path.normalize(dumpPaths[i] + '/' + dumpName);
                fs.writeFileSync(dumpfile, sourcecode, 'utf8');
                console.error("****** offending generated " + errname + " source code dumped into file: ", dumpfile);
                break;          // abort loop once a dump action was successful!
            } catch (ex3) {
                //console.error("generated " + errname + " source code fatal DUMPING error ATTEMPT: ", i, " = ", ex3.message, " -- while attempting to dump into file: ", dumpfile, "\n", ex3.stack);
                if (i === l - 1) {
                    throw ex3;
                }
            }
        }
    } catch (ex2) {
        console.error("generated " + errname + " source code fatal DUMPING error: ", ex2.message, " -- while attempting to dump into file: ", dumpfile, "\n", ex2.stack);
    }

    // augment the exception info, when available:
    if (ex) {
        ex.offending_source_code = sourcecode;
        ex.offending_source_title = errname;
        ex.offending_source_dumpfile = dumpfile;
    }    
}
1344901
def link(source_path):
    """"""
    if not os.path.isfile(source_path):
        raise SourceNotFound(source_path)
    with open(source_path, 'r') as f:
        content = f.read()
    block_map = BlockMap()  # The map will be populated with the following function call.
    all_block = convert_lines_to_block(
            content.splitlines(), block_map, LinkStack(source_path), source_path)
    return all_block, block_map.get_variables()
586784
function createContentURL() {
        var path = '';
        var name = element.text();
        // Use $window.location.pathname to get the path with the baseURL included.
        // $location.path() does not include the baseURL. This is important to support how the docs
        // are deployed with baseURLs like /latest, /HEAD, /1.1.13, etc.
        if (scope.$root.$window && scope.$root.$window.location) {
          path = scope.$root.$window.location.pathname;
        }
        name = name
          .trim()                           // Trim text due to browsers extra whitespace.
          .replace(/'/g, '')                // Transform apostrophes words to a single one.
          .replace(unsafeCharRegex, '-')    // Replace unsafe chars with a dash symbol.
          .replace(/-{2,}/g, '-')           // Remove repeating dash symbols.
          .replace(/^-|-$/g, '')            // Remove preceding or ending dashes.
          .toLowerCase();                   // Link should be lower-case for accessible URL.
        scope.name = name;
        scope.href = path + '#' + name;
      }
1369895
function linkToSrc(shortPath, lineNumber) {
    var splitPath = shortPath.split("/");
    return '<a href="{{srcroot}}' + shortPath+'">' + splitPath[splitPath.length - 1] + '</a>, <a href="{{srcroot}}' + shortPath+'#L'+lineNumber+'">' + lineNumber + '</a>';
    
}
621319
function(csspath,imgpath,absolute) {
        var host
            , cssroot
            , fullpath
            , url_parsed
            , opt = this.opt;


        url_parsed = mod_url.parse(imgpath);
        hash = url_parsed.hash;
        if(url_parsed.protocol && !url_parsed.protocol.match(/^http/)){
            return false;
        }
        if(absolute){
            fullpath = url_parsed.pathname;
            host = url_parsed.host;
        }else{
            cssroot = mod_path.dirname(csspath);
            fullpath = mod_path.join(cssroot,url_parsed.pathname);
        }

        var ext = mod_path.extname(fullpath);


        var name = fullpath.split(ext)[0];
        var version_match = name.match(/([\w\/\.\-\_]+)(\.v\d+)/);
        var version;
        if(version_match){
            version = version_match[2];
            name = version_match[1];
        }



        var real_full_path = fullpath;
            real_full_path = real_full_path.replace(/^(.*)(\.v\d+)+(\.(png|jpg|gif))$/,"$1$3");


        var warn_message;

        if(absolute){
            return false;
        }
        if(!grunt.file.exists(real_full_path)){
            warn_message  = "image not exists " + csspath + " -> " + fullpath;
            if(opt.allow_image_miss){
                grunt.log.warn(warn_message);
            }else{
                grunt.fail.warn(warn_message);
            }
            return false;
        }else{
            var parsed = {
                hash:hash,
                csspath:csspath,
                search:url_parsed.search,
                absolute:absolute,
                ext:ext,
                md5:mod_md5(grunt.file.read(real_full_path, { encoding: null })),
                name:name
            };
            parsed.host = (host || this.calculateCDNHost(
                mod_url.parse(this.connector(parsed)).pathname
            ));
            return parsed;
        }

    }