本文整理汇总了Python中TriblerGUI.tribler_request_manager.TriblerRequestManager.perform_request方法的典型用法代码示例。如果您正苦于以下问题:Python TriblerRequestManager.perform_request方法的具体用法?Python TriblerRequestManager.perform_request怎么用?Python TriblerRequestManager.perform_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TriblerGUI.tribler_request_manager.TriblerRequestManager
的用法示例。
在下文中一共展示了TriblerRequestManager.perform_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_torrent_to_channel
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def add_torrent_to_channel(self, filename):
with open(filename, "rb") as torrent_file:
torrent_content = b64encode(torrent_file.read())
request_mgr = TriblerRequestManager()
request_mgr.perform_request("mychannel/torrents",
self.on_torrent_to_channel_added, method='PUT',
data={"torrent": torrent_content})
示例2: on_torrents_remove_all_action
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def on_torrents_remove_all_action(self, action):
if action == 0:
request_mgr = TriblerRequestManager()
request_mgr.perform_request("mychannel/torrents", self.on_all_torrents_removed_response, method='DELETE')
self.dialog.close_dialog()
self.dialog = None
示例3: add_torrent_to_channel
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def add_torrent_to_channel(self, filename):
with open(filename, "rb") as torrent_file:
torrent_content = urllib.quote_plus(base64.b64encode(torrent_file.read()))
editchannel_request_mgr = TriblerRequestManager()
editchannel_request_mgr.perform_request("channels/discovered/%s/torrents" %
self.channel_overview['identifier'],
self.on_torrent_to_channel_added, method='PUT',
data='torrent=%s' % torrent_content)
示例4: add_dir_to_channel
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def add_dir_to_channel(self, dirname, recursive=False):
post_data = {
"torrents_dir": dirname,
"recursive": int(recursive)
}
request_mgr = TriblerRequestManager()
request_mgr.perform_request("mychannel/torrents",
self.on_torrent_to_channel_added, method='PUT', data=post_data)
示例5: SubscribedChannelsPage
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
class SubscribedChannelsPage(QWidget):
"""
This page shows all the channels that the user has subscribed to.
"""
def __init__(self):
QWidget.__init__(self)
self.dialog = None
self.request_mgr = None
def initialize(self):
self.window().add_subscription_button.clicked.connect(self.on_add_subscription_clicked)
def load_subscribed_channels(self):
self.window().subscribed_channels_list.set_data_items([(LoadingListItem, None)])
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request("channels/subscribed", self.received_subscribed_channels)
def received_subscribed_channels(self, results):
if not results:
return
self.window().subscribed_channels_list.set_data_items([])
items = []
if len(results['subscribed']) == 0:
self.window().subscribed_channels_list.set_data_items(
[(LoadingListItem, "You are not subscribed to any channel.")])
return
for result in results['subscribed']:
items.append((ChannelListItem, result))
self.window().subscribed_channels_list.set_data_items(items)
def on_add_subscription_clicked(self):
self.dialog = ConfirmationDialog(self, "Add subscribed channel",
"Please enter the identifier of the channel you want to subscribe to below. "
"It can take up to a minute before the channel is visible in your list of "
"subscribed channels.",
[('ADD', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)],
show_input=True)
self.dialog.dialog_widget.dialog_input.setPlaceholderText('Channel identifier')
self.dialog.button_clicked.connect(self.on_subscription_added)
self.dialog.show()
def on_subscription_added(self, action):
if action == 0:
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request("channels/subscribed/%s" % self.dialog.dialog_widget.dialog_input.text(),
self.on_channel_subscribed, method='PUT')
self.dialog.close_dialog()
self.dialog = None
def on_channel_subscribed(self, _):
pass
示例6: on_commit_control_clicked
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def on_commit_control_clicked(self, index):
infohash = index.model().data_items[index.row()][u'infohash']
status = index.model().data_items[index.row()][u'status']
new_status = COMMIT_STATUS_COMMITTED
if status == COMMIT_STATUS_NEW or status == COMMIT_STATUS_COMMITTED:
new_status = COMMIT_STATUS_TODELETE
request_mgr = TriblerRequestManager()
request_mgr.perform_request("mychannel/torrents/%s" % infohash,
lambda response: self.on_torrent_status_updated(response, index),
data={"status": new_status}, method='PATCH')
示例7: on_save_clicked
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def on_save_clicked(self):
self.requests_done = 0
self.pending_requests = []
for torrent in self.torrents_to_create:
request = TriblerRequestManager()
request.perform_request("channels/discovered/%s/playlists/%s/%s" %
(self.channel_info["identifier"], self.playlist_info['id'],
torrent['infohash']), self.on_request_done, method="PUT")
self.pending_requests.append(request)
for torrent in self.torrents_to_remove:
request = TriblerRequestManager()
request.perform_request("channels/discovered/%s/playlists/%s/%s" %
(self.channel_info["identifier"], self.playlist_info['id'], torrent['infohash']),
self.on_request_done, method="DELETE")
self.pending_requests.append(request)
示例8: on_subscribe_control_clicked
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def on_subscribe_control_clicked(self, index):
item = index.model().data_items[index.row()]
# skip LEGACY entries, regular torrents and personal channel
if (u'subscribed' not in item or
item[u'status'] == 1000 or
item[u'my_channel']):
return
status = int(item[u'subscribed'])
public_key = item[u'public_key']
request_mgr = TriblerRequestManager()
request_mgr.perform_request("metadata/channels/%s" % public_key,
(lambda _: self.on_unsubscribed_channel.emit(index)) if status else
(lambda _: self.on_subscribed_channel.emit(index)),
data={"subscribe": int(not status)}, method='POST')
index.model().data_items[index.row()][u'subscribed'] = int(not status)
示例9: on_torrents_remove_all_action
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def on_torrents_remove_all_action(self, action):
if action == 0:
for torrent_ind in xrange(self.window().edit_channel_torrents_list.count()):
torrent_data = self.window().edit_channel_torrents_list.item(torrent_ind).data(Qt.UserRole)
request_mgr = TriblerRequestManager()
request_mgr.perform_request("channels/discovered/%s/torrents/%s" %
(self.channel_overview["identifier"], torrent_data['infohash']),
None, method='DELETE')
self.remove_torrent_requests.append(request_mgr)
self.window().edit_channel_torrents_list.set_data_items([])
if "chant" in self.channel_overview:
self.load_channel_torrents()
self.dialog.close_dialog()
self.dialog = None
示例10: DiscoveredPage
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
class DiscoveredPage(QWidget):
"""
The DiscoveredPage shows an overview of all discovered channels in Tribler.
"""
def __init__(self):
QWidget.__init__(self)
self.discovered_channels = []
self.request_mgr = None
self.initialized = False
def initialize_discovered_page(self):
if not self.initialized:
self.window().core_manager.events_manager.discovered_channel.connect(self.on_discovered_channel)
self.initialized = True
def load_discovered_channels(self):
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request("channels/discovered", self.received_discovered_channels)
def received_discovered_channels(self, results):
if not results or 'channels' not in results:
return
self.discovered_channels = []
self.window().discovered_channels_list.set_data_items([])
items = []
results['channels'].sort(key=lambda x: x['torrents'], reverse=True)
for result in results['channels']:
items.append((ChannelListItem, result))
self.discovered_channels.append(result)
self.update_num_label()
self.window().discovered_channels_list.set_data_items(items)
def on_discovered_channel(self, channel_info):
channel_info['torrents'] = 0
channel_info['subscribed'] = False
channel_info['votes'] = 0
self.window().discovered_channels_list.append_item((ChannelListItem, channel_info))
self.discovered_channels.append(channel_info)
self.update_num_label()
def update_num_label(self):
self.window().num_discovered_channels_label.setText("%d items" % len(self.discovered_channels))
示例11: on_torrents_remove_selected_action
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def on_torrents_remove_selected_action(self, action, items):
if action == 0:
items = [str(item) for item in items]
infohashes = ",".join(items)
post_data = {
"infohashes": infohashes,
"status": COMMIT_STATUS_TODELETE
}
request_mgr = TriblerRequestManager()
request_mgr.perform_request("mychannel/torrents",
lambda response: self.on_torrents_removed_response(response, items),
data=post_data, method='POST')
if self.dialog:
self.dialog.close_dialog()
self.dialog = None
示例12: perform_start_download_request
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def perform_start_download_request(self, uri, anon_download, safe_seeding, destination, selected_files,
total_files=0, callback=None):
# Check if destination directory is writable
is_writable, error = is_dir_writable(destination)
if not is_writable:
gui_error_message = "Insufficient write permissions to <i>%s</i> directory. Please add proper " \
"write permissions on the directory and add the torrent again. %s" \
% (destination, error)
ConfirmationDialog.show_message(self.window(), "Download error <i>%s</i>" % uri, gui_error_message, "OK")
return
selected_files_list = []
if len(selected_files) != total_files: # Not all files included
selected_files_list = [filename for filename in selected_files]
anon_hops = int(self.tribler_settings['download_defaults']['number_hops']) if anon_download else 0
safe_seeding = 1 if safe_seeding else 0
post_data = {
"uri": uri,
"anon_hops": anon_hops,
"safe_seeding": safe_seeding,
"destination": destination,
"selected_files": selected_files_list
}
request_mgr = TriblerRequestManager()
request_mgr.perform_request("downloads", callback if callback else self.on_download_added,
method='PUT', data=post_data)
# Save the download location to the GUI settings
current_settings = get_gui_setting(self.gui_settings, "recent_download_locations", "")
recent_locations = current_settings.split(",") if len(current_settings) > 0 else []
if isinstance(destination, six.text_type):
destination = destination.encode('utf-8')
encoded_destination = hexlify(destination)
if encoded_destination in recent_locations:
recent_locations.remove(encoded_destination)
recent_locations.insert(0, encoded_destination)
if len(recent_locations) > 5:
recent_locations = recent_locations[:5]
self.gui_settings.setValue("recent_download_locations", ','.join(recent_locations))
示例13: perform_start_download_request
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
def perform_start_download_request(self, uri, anon_download, safe_seeding, destination, selected_files,
total_files=0, callback=None):
# Check if destination directory is writable
is_writable, error = is_dir_writable(destination)
if not is_writable:
gui_error_message = "Insufficient write permissions to <i>%s</i> directory. Please add proper " \
"write permissions on the directory and add the torrent again. %s" \
% (destination, error)
ConfirmationDialog.show_message(self.window(), "Download error <i>%s</i>" % uri, gui_error_message, "OK")
return
selected_files_uri = ""
if len(selected_files) != total_files: # Not all files included
selected_files_uri = u'&' + u''.join(u"selected_files[]=%s&" %
quote_plus_unicode(filename) for filename in selected_files)[:-1]
anon_hops = int(self.tribler_settings['download_defaults']['number_hops']) if anon_download else 0
safe_seeding = 1 if safe_seeding else 0
post_data = "uri=%s&anon_hops=%d&safe_seeding=%d&destination=%s%s" % (quote_plus_unicode(uri), anon_hops,
safe_seeding, destination,
selected_files_uri)
post_data = post_data.encode('utf-8') # We need to send bytes in the request, not unicode
request_mgr = TriblerRequestManager()
request_mgr.perform_request("downloads", callback if callback else self.on_download_added,
method='PUT', data=post_data)
# Save the download location to the GUI settings
current_settings = get_gui_setting(self.gui_settings, "recent_download_locations", "")
recent_locations = current_settings.split(",") if len(current_settings) > 0 else []
if isinstance(destination, unicode):
destination = destination.encode('utf-8')
encoded_destination = destination.encode('hex')
if encoded_destination in recent_locations:
recent_locations.remove(encoded_destination)
recent_locations.insert(0, encoded_destination)
if len(recent_locations) > 5:
recent_locations = recent_locations[:5]
self.gui_settings.setValue("recent_download_locations", ','.join(recent_locations))
示例14: MyTorrentsTableViewController
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
class MyTorrentsTableViewController(TorrentsTableViewController):
"""
This class manages the list with the torrents in your own channel.
"""
def __init__(self, *args, **kwargs):
super(MyTorrentsTableViewController, self).__init__(*args, **kwargs)
self.model.row_edited.connect(self._on_row_edited)
def _on_row_edited(self, index, new_value):
infohash = self.model.data_items[index.row()][u'infohash']
attribute_name = self.model.columns[index.column()]
attribute_name = u'tags' if attribute_name == u'category' else attribute_name
attribute_name = u'title' if attribute_name == u'name' else attribute_name
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request(
"mychannel/torrents/%s" % infohash,
self._on_row_update_results,
method='PATCH',
data={attribute_name: new_value})
def _on_row_update_results(self, response):
if response:
self.table_view.window().edit_channel_page.channel_dirty = response['dirty']
self.table_view.window().edit_channel_page.update_channel_commit_views()
def perform_query(self, **kwargs):
kwargs.update({
"rest_endpoint_url": "mychannel/torrents",
"exclude_deleted": self.model.exclude_deleted})
super(MyTorrentsTableViewController, self).perform_query(**kwargs)
def on_query_results(self, response):
if super(MyTorrentsTableViewController, self).on_query_results(response):
self.table_view.window().edit_channel_page.channel_dirty = response['dirty']
self.table_view.window().edit_channel_page.update_channel_commit_views()
示例15: CreateTorrentPage
# 需要导入模块: from TriblerGUI.tribler_request_manager import TriblerRequestManager [as 别名]
# 或者: from TriblerGUI.tribler_request_manager.TriblerRequestManager import perform_request [as 别名]
class CreateTorrentPage(QWidget):
"""
The CreateTorrentPage is the page where users can create torrent files so they can be added to their channel.
"""
def __init__(self):
QWidget.__init__(self)
self.channel_identifier = None
self.request_mgr = None
self.dialog = None
self.selected_item_index = -1
self.initialized = False
def initialize(self):
self.window().create_torrent_name_field.setText('')
self.window().create_torrent_description_field.setText('')
self.window().create_torrent_files_list.clear()
self.window().seed_after_adding_checkbox.setChecked(True)
self.window().edit_channel_create_torrent_progress_label.hide()
if not self.initialized:
self.window().manage_channel_create_torrent_back.setIcon(QIcon(get_image_path('page_back.png')))
self.window().create_torrent_files_list.customContextMenuRequested.connect(self.on_right_click_file_item)
self.window().manage_channel_create_torrent_back.clicked.connect(self.on_create_torrent_manage_back_clicked)
self.window().create_torrent_choose_files_button.clicked.connect(self.on_choose_files_clicked)
self.window().create_torrent_choose_dir_button.clicked.connect(self.on_choose_dir_clicked)
self.window().edit_channel_create_torrent_button.clicked.connect(self.on_create_clicked)
self.initialized = True
def on_create_torrent_manage_back_clicked(self):
self.window().edit_channel_details_stacked_widget.setCurrentIndex(PAGE_EDIT_CHANNEL_TORRENTS)
def on_choose_files_clicked(self):
filenames, _ = QFileDialog.getOpenFileNames(self.window(), "Please select the files", QDir.homePath())
for filename in filenames:
self.window().create_torrent_files_list.addItem(filename)
def on_choose_dir_clicked(self):
chosen_dir = QFileDialog.getExistingDirectory(self.window(), "Please select the directory containing the files",
"", QFileDialog.ShowDirsOnly)
if len(chosen_dir) == 0:
return
files = []
for path, _, dir_files in os.walk(chosen_dir):
for filename in dir_files:
files.append(os.path.join(path, filename))
self.window().create_torrent_files_list.clear()
for filename in files:
self.window().create_torrent_files_list.addItem(filename)
def on_create_clicked(self):
if self.window().create_torrent_files_list.count() == 0:
self.dialog = ConfirmationDialog(self, "Notice", "You should add at least one file to your torrent.",
[('CLOSE', BUTTON_TYPE_NORMAL)])
self.dialog.button_clicked.connect(self.on_dialog_ok_clicked)
self.dialog.show()
return
self.window().edit_channel_create_torrent_button.setEnabled(False)
files_list = []
for ind in xrange(self.window().create_torrent_files_list.count()):
file_str = self.window().create_torrent_files_list.item(ind).text()
files_list.append(file_str)
name = self.window().create_torrent_name_field.text()
description = self.window().create_torrent_description_field.toPlainText()
post_data = {
"name": name,
"description": description,
"files": files_list
}
url = "createtorrent?download=1" if self.window().seed_after_adding_checkbox.isChecked() else "createtorrent"
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request(url, self.on_torrent_created, data=post_data, method='POST')
# Show creating torrent text
self.window().edit_channel_create_torrent_progress_label.show()
def on_dialog_ok_clicked(self, _):
self.dialog.close_dialog()
self.dialog = None
def on_torrent_created(self, result):
if not result:
return
self.window().edit_channel_create_torrent_button.setEnabled(True)
if 'torrent' in result:
self.add_torrent_to_channel(result['torrent'])
def add_torrent_to_channel(self, torrent):
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request("mychannel/torrents", self.on_torrent_to_channel_added,
data={"torrent": torrent}, method='PUT')
#.........这里部分代码省略.........