Чтение fileset от потока

Я думаю, вы должны передать тип продажи / покупки в качестве параметра:

  {
    path: 'sell/:type',
    component: SellComponent
  },
  {
    path: 'buy/:type',
    component: BuyComponent
  }

или, если вы хотите сохранить структуру:

  {
    path: 'sell-:type',
    component: SellComponent
  },
  {
    path: 'buy-:type',
    component: BuyComponent
  }

И тогда в вашем компоненте получите param от текущего маршрута.

12
задан Constantin 14 February 2009 в 14:14
поделиться

3 ответа

Effbot ответили на Ваш вопрос. Вот полный код для чтения списка файлов из .torrent файла (Python 2.4 +):

import re

def tokenize(text, match=re.compile("([idel])|(\d+):|(-?\d+)").match):
    i = 0
    while i < len(text):
        m = match(text, i)
        s = m.group(m.lastindex)
        i = m.end()
        if m.lastindex == 2:
            yield "s"
            yield text[i:i+int(s)]
            i = i + int(s)
        else:
            yield s

def decode_item(next, token):
    if token == "i":
        # integer: "i" value "e"
        data = int(next())
        if next() != "e":
            raise ValueError
    elif token == "s":
        # string: "s" value (virtual tokens)
        data = next()
    elif token == "l" or token == "d":
        # container: "l" (or "d") values "e"
        data = []
        tok = next()
        while tok != "e":
            data.append(decode_item(next, tok))
            tok = next()
        if token == "d":
            data = dict(zip(data[0::2], data[1::2]))
    else:
        raise ValueError
    return data

def decode(text):
    try:
        src = tokenize(text)
        data = decode_item(src.next, src.next())
        for token in src: # look for more tokens
            raise SyntaxError("trailing junk")
    except (AttributeError, ValueError, StopIteration):
        raise SyntaxError("syntax error")
    return data

if __name__ == "__main__":
    data = open("test.torrent", "rb").read()
    torrent = decode(data)
    for file in torrent["info"]["files"]:
        print "%r - %d bytes" % ("/".join(file["path"]), file["length"])
17
ответ дан 2 December 2019 в 03:43
поделиться

Я использовал бы libtorrent rasterbar, который является небольшой и быстрой библиотекой C++.
Для итерации по файлам, Вы могли использовать torrent_info класс (begin_files (), end_files ()).

Существует также интерфейс Python для libtorrent:

import libtorrent
info = libtorrent.torrent_info('test.torrent')
for f in info.files():
    print "%s - %s" % (f.path, f.size)
20
ответ дан 2 December 2019 в 03:43
поделиться

bencode.py от исходной Магистрали БитТоррент 5.x клиент (http://download.bittorrent.com/dl/BitTorrent-5.2.2.tar.gz) дал бы Вам в значительной степени ссылочную реализацию в Python.

Это имеет зависимость от импорта от пакета BTL, но это тривиально легко удалить. Вы затем посмотрели бы на bencode.bdecode (filecontent) ['информация'] ['файлы'].

2
ответ дан 2 December 2019 в 03:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: