For a torrent where we don't have the metainfo, request metainfo pieces from peers.
347336
def requestMetadataPieces(infoHash)
      torrentData = @torrentData[infoHash]
      if ! torrentData
        @logger.error "Request metadata pices: torrent data for torrent #{QuartzTorrent.bytesToHex(infoHash)} not found."
        return
      end
      
      return if torrentData.paused || torrentData.queued

      # We may not have completed the extended handshake with the peer which specifies the torrent size.
      # In this case torrentData.metainfoPieceState is not yet set.
      return if ! torrentData.metainfoPieceState

      @logger.info "#{QuartzTorrent.bytesToHex(infoHash)}: Obtained all pieces of metainfo." if torrentData.metainfoPieceState.complete?

      pieces = torrentData.metainfoPieceState.findRequestablePieces
      classifiedPeers = ClassifiedPeers.new torrentData.peers.all
      peers = torrentData.metainfoPieceState.findRequestablePeers(classifiedPeers)
  
      if peers.size > 0
        # For now, just request all pieces from the first peer.
        pieces.each do |pieceIndex|
          msg = ExtendedMetaInfo.new
          msg.msgType = :request
          msg.piece = pieceIndex
          withPeersIo(peers.first, "requesting metadata piece") do |io|
            sendMessageToPeer msg, io, peers.first
            torrentData.metainfoPieceState.setPieceRequested(pieceIndex, true)
            @logger.debug "#{QuartzTorrent.bytesToHex(infoHash)}: Requesting metainfo piece from #{peers.first}: piece #{pieceIndex}"
          end
        end
      else
        @logger.error "#{QuartzTorrent.bytesToHex(infoHash)}: No peers found that have metadata."
      end

    end
1275118
def timerExpired(metadata)
      if metadata.is_a?(Array) && metadata[0] == :manage_peers
        managePeers(metadata[1])
      elsif metadata.is_a?(Array) && metadata[0] == :request_blocks
        requestBlocks(metadata[1])
      elsif metadata.is_a?(Array) && metadata[0] == :check_piece_manager
        checkPieceManagerResults(metadata[1])
      elsif metadata.is_a?(Array) && metadata[0] == :handshake_timeout
        handleHandshakeTimeout(metadata[1])
      elsif metadata.is_a?(Array) && metadata[0] == :removetorrent
        handleRemoveTorrent(metadata[1], metadata[2])
      elsif metadata.is_a?(Array) && metadata[0] == :pausetorrent
        handlePause(metadata[1], metadata[2])
      elsif metadata.is_a?(Array) && metadata[0] == :get_torrent_data
        @torrentData.each do |k,v|
          begin
            if metadata[3].nil? || k == metadata[3]
              v = TorrentDataDelegate.new(v, self)
              metadata[1][k] = v
            end
          rescue
            @logger.error "Error building torrent data response for user: #{$!}"
            @logger.error "#{$!.backtrace.join("\n")}"
          end
        end
        metadata[2].signal
      elsif metadata.is_a?(Array) && metadata[0] == :update_torrent_data
        delegate = metadata[1]
        if ! @torrentData.has_key?(infoHash)
          delegate.state = :deleted 
        else
          delegate.internalRefresh
        end
        metadata[2].signal
      elsif metadata.is_a?(Array) && metadata[0] == :request_metadata_pieces
        requestMetadataPieces(metadata[1])
      elsif metadata.is_a?(Array) && metadata[0] == :check_metadata_piece_manager
        checkMetadataPieceManagerResults(metadata[1])
      elsif metadata.is_a?(Array) && metadata[0] == :runproc
        metadata[1].call
      else
        @logger.info "Unknown timer #{metadata} expired."
      end
    end
1053435
def BuildCloudMetadataRequests():
  """"""
  amazon_collection_map = {
      "/".join((AMAZON_URL_BASE, "instance-id")): "instance_id",
      "/".join((AMAZON_URL_BASE, "ami-id")): "ami_id",
      "/".join((AMAZON_URL_BASE, "hostname")): "hostname",
      "/".join((AMAZON_URL_BASE, "public-hostname")): "public_hostname",
      "/".join((AMAZON_URL_BASE, "instance-type")): "instance_type",
  }
  google_collection_map = {
      "/".join((GOOGLE_URL_BASE, "instance/id")): "instance_id",
      "/".join((GOOGLE_URL_BASE, "instance/zone")): "zone",
      "/".join((GOOGLE_URL_BASE, "project/project-id")): "project_id",
      "/".join((GOOGLE_URL_BASE, "instance/hostname")): "hostname",
      "/".join((GOOGLE_URL_BASE, "instance/machine-type")): "machine_type",
  }

  return CloudMetadataRequests(requests=_MakeArgs(amazon_collection_map,
                                                  google_collection_map))
571351
def size(self):
        
        if 'length' in self.metainfo['info']:   # Singlefile
            return self.metainfo['info']['length']
        elif 'files' in self.metainfo['info']:  # Multifile torrent
            return sum(fileinfo['length']
                       for fileinfo in self.metainfo['info']['files'])
680930
def _process_metadata_response(topics, zk, default_min_isr):
    """"""
    not_in_sync_partitions = []
    for topic_name, partitions in topics.items():
        min_isr = get_min_isr(zk, topic_name) or default_min_isr
        if min_isr is None:
            continue
        for metadata in partitions.values():
            cur_isr = len(metadata.isr)
            if cur_isr < min_isr:
                not_in_sync_partitions.append({
                    'isr': cur_isr,
                    'min_isr': min_isr,
                    'topic': metadata.topic,
                    'partition': metadata.partition,
                })

    return not_in_sync_partitions
775416
def parse_torrent_file(torrent):
    """"""
    link_re = re.compile(r'^(http?s|ftp)')
    if link_re.match(torrent):
        response = requests.get(torrent, headers=HEADERS, timeout=20)
        data = parse_torrent_buffer(response.content)
    elif os.path.isfile(torrent):
        with open(torrent, 'rb') as f:
            data = parse_torrent_buffer(f.read())
    else:
        data = None
    return data
1039694
def get_sync_info(self, name, key=None):
        """"""
        peer_target = self.peer
        if self.is_local():
            info = self.cur_dir_meta.dir["peer_sync"].get(peer_target.get_id())
        else:
            info = peer_target.cur_dir_meta.dir["peer_sync"].get(self.get_id())
        if name is not None:
            info = info.get(name) if info else None
        if info and key:
            info = info.get(key)
        return info
1304937
def get_media_requests(self, item, info):
        
        key_generator = item.get(self.QINIU_KEY_GENERATOR_FIELD)
        return [Request(x, meta={'qiniu_key_generator': key_generator}) for x in item.get(self.FILES_URLS_FIELD, [])]
795216
def _req_lixian_get_id(self, torrent=False):
        """"""
        url = 'http://115.com/'
        params = {
            'ct': 'lixian',
            'ac': 'get_id',
            'torrent': 1 if torrent else None,
            '_': get_timestamp(13)
        }
        req = Request(method='GET', url=url, params=params)
        res = self.http.send(req)
        return res.content
1207261
function getMetadata (dir) {
  var json = path.join(dir, 'meta.json')
  var js = path.join(dir, 'meta.js')
  var opts = {}

  if (exists(json)) {
    opts = metadata.sync(json)
  } else if (exists(js)) {
    var req = require(path.resolve(js))
    if (req !== Object(req)) {
      throw new Error('meta.js needs to expose an object')
    }
    opts = req
  }

  return opts
}
766726
def http_meta_data(self):
        """"""

        # For each flow process the contents
        for flow in self.input_stream:

            # Client to Server
            if flow['direction'] == 'CTS':
                try:
                    request = dpkt.http.Request(flow['payload'])
                    request_data = data_utils.make_dict(request)
                    request_data['uri'] = self._clean_uri(request['uri'])
                    flow['http'] = {'type':'HTTP_REQUEST', 'data':request_data}
                except (dpkt.dpkt.NeedData, dpkt.dpkt.UnpackError):
                    flow['http'] = None

            # Server to Client
            else:
                try:
                    response = dpkt.http.Response(flow['payload'])
                    flow['http'] = {'type': 'HTTP_RESPONSE', 'data': data_utils.make_dict(response)}
                except (dpkt.dpkt.NeedData, dpkt.dpkt.UnpackError):
                    flow['http'] = None

            # Mark non-TCP HTTP
            if flow['http'] and flow['protocol'] != 'TCP':
                flow['http'].update({'weird': 'UDP-HTTP'})

            # All done
            yield flow
190817
def files(self):
        
        files = []
        info = self._struct.get('info')

        if not info:
            return files

        if 'files' in info:
            base = info['name']

            for f in info['files']:
                files.append(TorrentFile(join(base, *f['path']), f['length']))

        else:
            files.append(TorrentFile(info['name'], info['length']))

        return files
633667
def require_peer(self, uuid, endpoint, public_key):
        
        return lib.zyre_require_peer(self._as_parameter_, uuid, endpoint, public_key)
308948
def copy_meta_from(self, ido):
        """"""
        self._active_scalar_info = ido.active_scalar_info
        self._active_vectors_info = ido.active_vectors_info
        if hasattr(ido, '_textures'):
            self._textures = ido._textures
605192
def metadata(ctx, drafts, path):
    """"""
    _rws = partial(rws_call, ctx)
    if len(path) == 0:
        _rws(MetadataStudiesRequest(), default_attr='oid')
    elif len(path) == 1:
        if drafts:
            _rws(StudyDraftsRequest(path[0]), default_attr='oid')
        else:
            _rws(StudyVersionsRequest(path[0]), default_attr='oid')
    elif len(path) == 2:
        _rws(StudyVersionRequest(path[0], path[1]))
    else:
        click.echo('Too many arguments')
985875
def parse_torrent_buffer(torrent):
    """"""
    md = {}
    try:
        metadata = bencode.bdecode(torrent)
    except bencode.BTL.BTFailure:
        print 'Not a valid encoded torrent'
        return None
    if 'announce-list' in metadata:
        md['trackers'] = []
        for tracker in metadata['announce-list']:
            md['trackers'].append(tracker[0])
    if 'announce' in metadata:
        md['trackers'].append(metadata['announce'])
    md['trackers'] = list(set(md['trackers']))
    if 'name' in metadata['info']:
        md['name'] = metadata['info']['name']
    webseeds = []
    if 'httpseeds' in metadata:
        webseeds = metadata['httpseeds']
    if 'url-list' in metadata:
        webseeds += md['url-list']
    if webseeds:
        md['webseeds'] = webseeds
    if 'created by' in metadata:
        md['creator'] = metadata['created by']
    if 'creation date' in metadata:
        utc_dt = datetime.utcfromtimestamp(metadata['creation date'])
        md['created'] = utc_dt.strftime('%Y-%m-%d %H:%M:%S')
    if 'comment' in metadata:
        md['comment'] = metadata['comment']
    md['piece_size'] = metadata['info']['piece length']
    if 'length' in metadata['info']:
        md['file'] = {'path': metadata['info']['name'],
                      'length': metadata['info']['length']}
    if 'files' in metadata['info']:
        md['files'] = []
        for item in metadata['info']['files']:
            md['files'].append(
                {'path': item['path'][0], 'length': item['length']})
    # TODO check if torrent is private and encoding
    hashcontents = bencode.bencode(metadata['info'])
    digest = hashlib.sha1(hashcontents).digest()
    md['infoHash'] = hashlib.sha1(hashcontents).hexdigest()
    b32hash = base64.b32encode(digest)
    md['infoHash_b32'] = b32hash
    md['pieces'] = _split_pieces(metadata['info']['pieces'])
    md['total_size'] = hsize(sum([x['length'] for x in md['files']]))
    return md
343763
def info_hash(self):
        
        if getattr(self, '_data', None):
            return sha1(bencode(self._data['info'])).hexdigest()
        else:
            raise exceptions.TorrentNotGeneratedException