desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
':type: :class:`github.NamedUser.NamedUser`'
@property def committer(self):
self._completeIfNotSet(self._committer) return self._committer.value
':type: list of :class:`github.File.File`'
@property def files(self):
self._completeIfNotSet(self._files) return self._files.value
':type: string'
@property def html_url(self):
self._completeIfNotSet(self._html_url) return self._html_url.value
':type: list of :class:`github.Commit.Commit`'
@property def parents(self):
self._completeIfNotSet(self._parents) return self._parents.value
':type: string'
@property def sha(self):
self._completeIfNotSet(self._sha) return self._sha.value
':type: :class:`github.CommitStats.CommitStats`'
@property def stats(self):
self._completeIfNotSet(self._stats) return self._stats.value
':type: string'
@property def url(self):
self._completeIfNotSet(self._url) return self._url.value
':calls: `POST /repos/:owner/:repo/commits/:sha/comments <http://developer.github.com/v3/repos/comments>`_ :param body: string :param line: integer :param path: string :param position: integer :rtype: :class:`github.CommitComment.CommitComment`'
def create_comment(self, body, line=github.GithubObject.NotSet, path=github.GithubObject.NotSet, position=github.GithubObject.NotSet):
assert isinstance(body, (str, unicode)), body assert ((line is github.GithubObject.NotSet) or isinstance(line, (int, long))), line assert ((path is github.GithubObject.NotSet) or isinstance(path, (str, unicode))), path assert ((position is github.GithubObject.NotSet) or isinstance(position, (int, long))...
':calls: `POST /repos/:owner/:repo/statuses/:sha <http://developer.github.com/v3/repos/statuses>`_ :param state: string :param target_url: string :param description: string :param context: string :rtype: :class:`github.CommitStatus.CommitStatus`'
def create_status(self, state, target_url=github.GithubObject.NotSet, description=github.GithubObject.NotSet, context=github.GithubObject.NotSet):
assert isinstance(state, (str, unicode)), state assert ((target_url is github.GithubObject.NotSet) or isinstance(target_url, (str, unicode))), target_url assert ((description is github.GithubObject.NotSet) or isinstance(description, (str, unicode))), description assert ((context is github.GithubObject.N...
':calls: `GET /repos/:owner/:repo/commits/:sha/comments <http://developer.github.com/v3/repos/comments>`_ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CommitComment.CommitComment`'
def get_comments(self):
return github.PaginatedList.PaginatedList(github.CommitComment.CommitComment, self._requester, (self.url + '/comments'), None)
':calls: `GET /repos/:owner/:repo/statuses/:ref <http://developer.github.com/v3/repos/statuses>`_ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CommitStatus.CommitStatus`'
def get_statuses(self):
return github.PaginatedList.PaginatedList(github.CommitStatus.CommitStatus, self._requester, ((self._parentUrl(self._parentUrl(self.url)) + '/statuses/') + self.sha), None)
':type: string'
@property def body(self):
self._completeIfNotSet(self._body) return self._body.value
':type: datetime.datetime'
@property def created_at(self):
self._completeIfNotSet(self._created_at) return self._created_at.value
':type: integer'
@property def id(self):
self._completeIfNotSet(self._id) return self._id.value
':type: datetime.datetime'
@property def updated_at(self):
self._completeIfNotSet(self._updated_at) return self._updated_at.value
':type: string'
@property def url(self):
self._completeIfNotSet(self._url) return self._url.value
':type: :class:`github.NamedUser.NamedUser`'
@property def user(self):
self._completeIfNotSet(self._user) return self._user.value
':calls: `DELETE /gists/:gist_id/comments/:id <http://developer.github.com/v3/gists/comments>`_ :rtype: None'
def delete(self):
(headers, data) = self._requester.requestJsonAndCheck('DELETE', self.url)
':calls: `PATCH /gists/:gist_id/comments/:id <http://developer.github.com/v3/gists/comments>`_ :param body: string :rtype: None'
def edit(self, body):
assert isinstance(body, (str, unicode)), body post_parameters = {'body': body} (headers, data) = self._requester.requestJsonAndCheck('PATCH', self.url, input=post_parameters) self._useAttributes(data)
'Get a specific element :param day: int :param hour: int :rtype: int'
def get(self, day, hour):
return self._dict[(day, hour)]
':type: string'
@property def diff_url(self):
return self._diff_url.value
':type: string'
@property def html_url(self):
return self._html_url.value
':type: string'
@property def patch_url(self):
return self._patch_url.value
':param login_or_token: string :param password: string :param base_url: string :param timeout: integer :param client_id: string :param client_secret: string :param user_agent: string :param per_page: int'
def __init__(self, login_or_token=None, password=None, base_url=DEFAULT_BASE_URL, timeout=DEFAULT_TIMEOUT, client_id=None, client_secret=None, user_agent='PyGithub/Python', per_page=DEFAULT_PER_PAGE, api_preview=False):
assert ((login_or_token is None) or isinstance(login_or_token, (str, unicode))), login_or_token assert ((password is None) or isinstance(password, (str, unicode))), password assert isinstance(base_url, (str, unicode)), base_url assert isinstance(timeout, (int, long)), timeout assert ((client_id is N...
':type: bool'
def __get_FIX_REPO_GET_GIT_REF(self):
return self.__requester.FIX_REPO_GET_GIT_REF
':type: int'
def __get_per_page(self):
return self.__requester.per_page
'First value is requests remaining, second value is request limit. :type: (int, int)'
@property def rate_limiting(self):
(remaining, limit) = self.__requester.rate_limiting if (limit < 0): self.get_rate_limit() return self.__requester.rate_limiting
'Unix timestamp indicating when rate limiting will reset. :type: int'
@property def rate_limiting_resettime(self):
if (self.__requester.rate_limiting_resettime == 0): self.get_rate_limit() return self.__requester.rate_limiting_resettime
'Don\'t forget you can access the rate limit returned in headers of last Github API v3 response, by :attr:`github.MainClass.Github.rate_limiting` and :attr:`github.MainClass.Github.rate_limiting_resettime`. :calls: `GET /rate_limit <http://developer.github.com/v3/rate_limit>`_ :rtype: :class:`github.RateLimit.RateLimit...
def get_rate_limit(self):
(headers, attributes) = self.__requester.requestJsonAndCheck('GET', '/rate_limit') return RateLimit.RateLimit(self.__requester, headers, attributes, True)
':type: list of string'
@property def oauth_scopes(self):
return self.__requester.oauth_scopes
':calls: `GET /users/:user <http://developer.github.com/v3/users>`_ or `GET /user <http://developer.github.com/v3/users>`_ :param login: string :rtype: :class:`github.NamedUser.NamedUser`'
def get_user(self, login=github.GithubObject.NotSet):
assert ((login is github.GithubObject.NotSet) or isinstance(login, (str, unicode))), login if (login is github.GithubObject.NotSet): return AuthenticatedUser.AuthenticatedUser(self.__requester, {}, {'url': '/user'}, completed=False) else: (headers, data) = self.__requester.requestJsonAndChec...
':calls: `GET /users <http://developer.github.com/v3/users>`_ :param since: integer :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`'
def get_users(self, since=github.GithubObject.NotSet):
assert ((since is github.GithubObject.NotSet) or isinstance(since, (int, long))), since url_parameters = dict() if (since is not github.GithubObject.NotSet): url_parameters['since'] = since return github.PaginatedList.PaginatedList(github.NamedUser.NamedUser, self.__requester, '/users', url_para...
':calls: `GET /orgs/:org <http://developer.github.com/v3/orgs>`_ :param login: string :rtype: :class:`github.Organization.Organization`'
def get_organization(self, login):
assert isinstance(login, (str, unicode)), login (headers, data) = self.__requester.requestJsonAndCheck('GET', ('/orgs/' + login)) return github.Organization.Organization(self.__requester, headers, data, completed=True)
':calls: `GET /repos/:owner/:repo <http://developer.github.com/v3/repos>`_ or `GET /repositories/:id <http://developer.github.com/v3/repos>`_ :rtype: :class:`github.Repository.Repository`'
def get_repo(self, full_name_or_id, lazy=True):
assert isinstance(full_name_or_id, (str, unicode, int, long)), full_name_or_id url_base = ('/repositories/' if (isinstance(full_name_or_id, int) or isinstance(full_name_or_id, long)) else '/repos/') url = ('%s%s' % (url_base, full_name_or_id)) if lazy: return Repository.Repository(self.__request...
':calls: `GET /repositories <http://developer.github.com/v3/repos/#list-all-public-repositories>`_ :param since: integer :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`'
def get_repos(self, since=github.GithubObject.NotSet):
assert ((since is github.GithubObject.NotSet) or isinstance(since, (int, long))), since url_parameters = dict() if (since is not github.GithubObject.NotSet): url_parameters['since'] = since return github.PaginatedList.PaginatedList(github.Repository.Repository, self.__requester, '/repositories',...
':calls: `GET /gists/:id <http://developer.github.com/v3/gists>`_ :param id: string :rtype: :class:`github.Gist.Gist`'
def get_gist(self, id):
assert isinstance(id, (str, unicode)), id (headers, data) = self.__requester.requestJsonAndCheck('GET', ('/gists/' + id)) return github.Gist.Gist(self.__requester, headers, data, completed=True)
':calls: `GET /gists/public <http://developer.github.com/v3/gists>`_ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist`'
def get_gists(self):
return github.PaginatedList.PaginatedList(github.Gist.Gist, self.__requester, '/gists/public', None)
':calls: `GET /legacy/repos/search/:keyword <http://developer.github.com/v3/search/legacy>`_ :param keyword: string :param language: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`'
def legacy_search_repos(self, keyword, language=github.GithubObject.NotSet):
assert isinstance(keyword, (str, unicode)), keyword assert ((language is github.GithubObject.NotSet) or isinstance(language, (str, unicode))), language args = ({} if (language is github.GithubObject.NotSet) else {'language': language}) return Legacy.PaginatedList(('/legacy/repos/search/' + urllib.quote_...
':calls: `GET /legacy/user/search/:keyword <http://developer.github.com/v3/search/legacy>`_ :param keyword: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`'
def legacy_search_users(self, keyword):
assert isinstance(keyword, (str, unicode)), keyword return Legacy.PaginatedList(('/legacy/user/search/' + urllib.quote_plus(keyword, safe='/%:><')), {}, self.__requester, 'users', Legacy.convertUser, github.NamedUser.NamedUser)
':calls: `GET /legacy/user/email/:email <http://developer.github.com/v3/search/legacy>`_ :param email: string :rtype: :class:`github.NamedUser.NamedUser`'
def legacy_search_user_by_email(self, email):
assert isinstance(email, (str, unicode)), email (headers, data) = self.__requester.requestJsonAndCheck('GET', ('/legacy/user/email/' + email)) return github.NamedUser.NamedUser(self.__requester, headers, Legacy.convertUser(data['user']), completed=False)
':calls: `GET /search/repositories <http://developer.github.com/v3/search>`_ :param query: string :param sort: string (\'stars\', \'forks\', \'updated\') :param order: string (\'asc\', \'desc\') :param qualifiers: keyword dict query qualifiers :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Reposi...
def search_repositories(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers):
assert isinstance(query, (str, unicode)), query url_parameters = dict() if (sort is not github.GithubObject.NotSet): assert (sort in ('stars', 'forks', 'updated')), sort url_parameters['sort'] = sort if (order is not github.GithubObject.NotSet): assert (order in ('asc', 'desc')),...
':calls: `GET /search/users <http://developer.github.com/v3/search>`_ :param query: string :param sort: string (\'followers\', \'repositories\', \'joined\') :param order: string (\'asc\', \'desc\') :param qualifiers: keyword dict query qualifiers :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Nam...
def search_users(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers):
assert isinstance(query, (str, unicode)), query url_parameters = dict() if (sort is not github.GithubObject.NotSet): assert (sort in ('followers', 'repositories', 'joined')), sort url_parameters['sort'] = sort if (order is not github.GithubObject.NotSet): assert (order in ('asc',...
':calls: `GET /search/issues <http://developer.github.com/v3/search>`_ :param query: string :param sort: string (\'comments\', \'created\', \'updated\') :param order: string (\'asc\', \'desc\') :param qualifiers: keyword dict query qualifiers :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.I...
def search_issues(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers):
assert isinstance(query, (str, unicode)), query url_parameters = dict() if (sort is not github.GithubObject.NotSet): assert (sort in ('comments', 'created', 'updated')), sort url_parameters['sort'] = sort if (order is not github.GithubObject.NotSet): assert (order in ('asc', 'des...
':calls: `GET /search/code <http://developer.github.com/v3/search>`_ :param query: string :param sort: string (\'indexed\') :param order: string (\'asc\', \'desc\') :param qualifiers: keyword dict query qualifiers :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.ContentFile.ContentFile`'
def search_code(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers):
assert isinstance(query, (str, unicode)), query url_parameters = dict() if (sort is not github.GithubObject.NotSet): assert (sort in ('indexed',)), sort url_parameters['sort'] = sort if (order is not github.GithubObject.NotSet): assert (order in ('asc', 'desc')), order ur...
':calls: `POST /markdown <http://developer.github.com/v3/markdown>`_ :param text: string :param context: :class:`github.Repository.Repository` :rtype: string'
def render_markdown(self, text, context=github.GithubObject.NotSet):
assert isinstance(text, (str, unicode)), text assert ((context is github.GithubObject.NotSet) or isinstance(context, github.Repository.Repository)), context post_parameters = {'text': text} if (context is not github.GithubObject.NotSet): post_parameters['mode'] = 'gfm' post_parameters['c...
':calls: `GET /hooks/:name <http://developer.github.com/v3/repos/hooks/>`_ :param name: string :rtype: :class:`github.HookDescription.HookDescription`'
def get_hook(self, name):
assert isinstance(name, (str, unicode)), name (headers, attributes) = self.__requester.requestJsonAndCheck('GET', ('/hooks/' + name)) return HookDescription.HookDescription(self.__requester, headers, attributes, completed=True)
':calls: `GET /hooks <http://developer.github.com/v3/repos/hooks/>`_ :rtype: list of :class:`github.HookDescription.HookDescription`'
def get_hooks(self):
(headers, data) = self.__requester.requestJsonAndCheck('GET', '/hooks') return [HookDescription.HookDescription(self.__requester, headers, attributes, completed=True) for attributes in data]
':calls: `GET /gitignore/templates <http://developer.github.com/v3/gitignore>`_ :rtype: list of string'
def get_gitignore_templates(self):
(headers, data) = self.__requester.requestJsonAndCheck('GET', '/gitignore/templates') return data
':calls: `GET /gitignore/templates/:name <http://developer.github.com/v3/gitignore>`_ :rtype: :class:`github.GitignoreTemplate.GitignoreTemplate`'
def get_gitignore_template(self, name):
assert isinstance(name, (str, unicode)), name (headers, attributes) = self.__requester.requestJsonAndCheck('GET', ('/gitignore/templates/' + name)) return GitignoreTemplate.GitignoreTemplate(self.__requester, headers, attributes, completed=True)
':calls: `GET /emojis <http://developer.github.com/v3/emojis/>`_ :rtype: dictionary of type => url for emoji`'
def get_emojis(self):
(headers, attributes) = self.__requester.requestJsonAndCheck('GET', '/emojis') return attributes
'Creates an object from raw_data previously obtained by :attr:`github.GithubObject.GithubObject.raw_data`, and optionaly headers previously obtained by :attr:`github.GithubObject.GithubObject.raw_headers`. :param klass: the class of the object to create :param raw_data: dict :param headers: dict :rtype: instance of cla...
def create_from_raw_data(self, klass, raw_data, headers={}):
return klass(self.__requester, headers, raw_data, completed=True)
'Dumps (pickles) a PyGithub object to a file-like object. Some effort is made to not pickle sensitive informations like the Github credentials used in the :class:`Github` instance. But NO EFFORT is made to remove sensitive information from the object\'s attributes. :param obj: the object to pickle :param file: the file...
def dump(self, obj, file, protocol=0):
pickle.dump((obj.__class__, obj.raw_data, obj.raw_headers), file, protocol)
'Loads (unpickles) a PyGithub object from a file-like object. :param f: the file-like object to unpickle from :return: the unpickled object'
def load(self, f):
return self.create_from_raw_data(*pickle.load(f))
'This doesn\'t work with a Github Enterprise installation, because it always targets https://status.github.com. :calls: `GET /api/status.json <https://status.github.com/api>`_ :rtype: :class:`github.Status.Status`'
def get_api_status(self):
(headers, attributes) = self.__requester.requestJsonAndCheck('GET', '/api/status.json', cnx='status') return Status.Status(self.__requester, headers, attributes, completed=True)
'This doesn\'t work with a Github Enterprise installation, because it always targets https://status.github.com. :calls: `GET /api/last-message.json <https://status.github.com/api>`_ :rtype: :class:`github.StatusMessage.StatusMessage`'
def get_last_api_status_message(self):
(headers, attributes) = self.__requester.requestJsonAndCheck('GET', '/api/last-message.json', cnx='status') return StatusMessage.StatusMessage(self.__requester, headers, attributes, completed=True)
'This doesn\'t work with a Github Enterprise installation, because it always targets https://status.github.com. :calls: `GET /api/messages.json <https://status.github.com/api>`_ :rtype: list of :class:`github.StatusMessage.StatusMessage`'
def get_api_status_messages(self):
(headers, data) = self.__requester.requestJsonAndCheck('GET', '/api/messages.json', cnx='status') return [StatusMessage.StatusMessage(self.__requester, headers, attributes, completed=True) for attributes in data]
'Determine whether method is a modifier or a retriever'
def _get_method_type(self):
if (self.method_name[:4] == 'set_'): return 'm' else: return 'r'
'Add call to multicall @param method: L{Method} instance or name of raw RPC method @type method: Method or str @param args: call arguments'
def add(self, method, *args):
if isinstance(method, str): result = find_method(method) if (result == (-1)): method = Method(DummyClass, method, method) else: method = result if (not method.is_available(self.rt_obj)): _handle_unavailable_rpc_method(method, self.rt_obj) self.calls.ap...
'Execute added multicall calls @return: the results (post-processed), in the order they were added @rtype: tuple'
def call(self):
m = xmlrpclib.MultiCall(self.rt_obj._get_conn()) for call in self.calls: (method, args) = call rpc_call = getattr(method, 'rpc_call') getattr(m, rpc_call)(*args) results = m() results = tuple(results) results_processed = [] for (r, c) in zip(results, self.calls): ...
'Alias for set_enabled("yes")'
def enable(self):
self.set_enabled('yes')
'Alias for set_enabled("no")'
def disable(self):
self.set_enabled('no')
'Refresh tracker data @note: All fields are stored as attributes to self. @return: None'
def update(self):
multicall = rtorrent.rpc.Multicall(self) retriever_methods = [m for m in methods if (m.is_retriever() and m.is_available(self._rt_obj))] for method in retriever_methods: multicall.add(method, self.rpc_id) multicall.call()
'Get ServerProxy instance'
def _get_conn(self):
if ((self.username is not None) and (self.password is not None)): if (self.schema == 'scgi'): raise NotImplementedError() if ('authtype' not in self.tp_kwargs): authtype = None else: authtype = self.tp_kwargs['authtype'] if ('check_ssl_cert' not in...
'Get list of raw RPC commands @return: raw RPC commands @rtype: list'
def _get_rpc_methods(self):
return (self._rpc_methods or self._update_rpc_methods())
'Get list of all torrents in specified view @return: list of L{Torrent} instances @rtype: list @todo: add validity check for specified view'
def get_torrents(self, view='main'):
self.torrents = [] methods = rtorrent.torrent.methods retriever_methods = [m for m in methods if (m.is_retriever() and m.is_available(self))] m = rtorrent.rpc.Multicall(self) m.add('d.multicall', view, 'd.get_hash=', *[(method.rpc_call + '=') for method in retriever_methods]) results = m.call()[...
'Carry tracker/peer/file lists over to new torrent list'
def _manage_torrent_cache(self):
for torrent in self._torrent_cache: new_torrent = rtorrent.common.find_torrent(torrent.info_hash, self.torrents) if (new_torrent is not None): new_torrent.files = torrent.files new_torrent.peers = torrent.peers new_torrent.trackers = torrent.trackers self._tor...
'Determine correct "load torrent" RPC method'
def _get_load_function(self, file_type, start, verbose):
func_name = None if (file_type == 'url'): if (start and verbose): func_name = 'load_start_verbose' elif start: func_name = 'load_start' elif verbose: func_name = 'load_verbose' else: func_name = 'load' elif (file_type in ['file'...
'Loads torrent into rTorrent (with various enhancements) @param new_torrent: can be a url, a path to a local file, or the raw data of a torrent file @type new_torrent: str @param start: start torrent when loaded @type start: bool @param verbose: print error messages to rTorrent log @type verbose: bool @param verify_loa...
def load_torrent(self, new_torrent, start=False, verbose=False, verify_load=True):
p = self._get_conn() tp = TorrentParser(new_torrent) new_torrent = xmlrpclib.Binary(tp._raw_torrent) info_hash = tp.info_hash func_name = self._get_load_function('raw', start, verbose) getattr(p, func_name)(new_torrent) if verify_load: new_torrent = None for i in range(MAX_RE...
'Loads torrent into rTorrent @param new_torrent: can be a url, a path to a local file, or the raw data of a torrent file @type new_torrent: str @param file_type: valid options: "url", "file", or "raw" @type file_type: str @param start: start torrent when loaded @type start: bool @param verbose: print error messages to ...
def load_torrent_simple(self, new_torrent, file_type, start=False, verbose=False):
p = self._get_conn() assert (file_type in ['raw', 'file', 'url']), "Invalid file_type, options are: 'url', 'file', 'raw'." func_name = self._get_load_function(file_type, start, verbose) if (file_type == 'file'): assert os.path.isfile(new_torrent), 'Invalid path: "{0}"'.fo...
'Set DHT port @param port: port @type port: int @raise AssertionError: if invalid port is given'
def set_dht_port(self, port):
assert is_valid_port(port), 'Valid port range is 0-65535' self.dht_port = self._p.set_dht_port(port)
'Alias for set_check_hash(True)'
def enable_check_hash(self):
self.set_check_hash(True)
'Alias for set_check_hash(False)'
def disable_check_hash(self):
self.set_check_hash(False)
'Frontend for rtorrent.common.find_torrent'
def find_torrent(self, info_hash):
return rtorrent.common.find_torrent(info_hash, self.get_torrents())
'poll rTorrent to get latest torrent/peer/tracker/file information @note: This essentially refreshes every aspect of the rTorrent connection, so it can be very slow if working with a remote connection that has a lot of torrents loaded. @return: None'
def poll(self):
self.update() torrents = self.get_torrents() for t in torrents: t.poll()
'Refresh rTorrent client info @note: All fields are stored as attributes to self. @return: None'
def update(self):
multicall = rtorrent.rpc.Multicall(self) retriever_methods = [m for m in methods if (m.is_retriever() and m.is_available(self))] for method in retriever_methods: multicall.add(method) multicall.call()
'Refresh peer data @note: All fields are stored as attributes to self. @return: None'
def update(self):
multicall = rtorrent.rpc.Multicall(self) retriever_methods = [m for m in methods if (m.is_retriever() and m.is_available(self._rt_obj))] for method in retriever_methods: multicall.add(method, self.rpc_id) multicall.call()
'A workaround to get special attributes on the ServerProxy without interfering with the magic __getattr__'
def __call__(self, attr):
if (attr == 'close'): return self.__close elif (attr == 'transport'): return self.__transport raise AttributeError(('Attribute %r not found' % (attr,)))
'Inits RequestsTransport. Args: use_https: If true, https else http authtype: None, basic or digest username: Username password: Password check_ssl_cert: Check SSL certificate proxies: A dict of proxies( Ex: {"http": "http://10.10.1.10:3128", "https": "http://10.10.1.10:1080",}) Raises: ValueError: Invalid info'
def __init__(self, use_https=True, authtype=None, username=None, password=None, check_ssl_cert=True, proxies=None):
if issubclass(xmlrpc_client.Transport, object): super(RequestsTransport, self).__init__() else: xmlrpc_client.Transport.__init__(self) self.user_agent = ('Python Requests/' + requests.__version__) self._use_https = use_https self._check_ssl_cert = check_ssl_cert if ((authtype ...
'Replace the xmlrpc request function. Process xmlrpc request via requests library. Args: host: Target host handler: Target PRC handler. request_body: XML-RPC request body. verbose: Debugging flag. Returns: Parsed response. Raises: RequestException: Error in requests'
def request(self, host, handler, request_body, verbose=0):
if verbose: self._debug() if (not self._check_ssl_cert): disable_warnings() headers = {'User-Agent': self.user_agent, 'Content-Type': 'text/xml'} if self._use_https: url = 'https://{host}/{handler}'.format(host=host, handler=handler) else: url = 'http://{host}/{handle...
'Replace the xmlrpc parse_response function. Parse response. Args: response: Requests return data Returns: Response tuple and target method.'
def parse_response(self, response):
(p, u) = self.getparser() p.feed(response.text.encode('utf-8')) p.close() return u.close()
'Debug requests module. Enable verbose logging from requests'
def _debug(self):
import logging try: import http.client as http_client except ImportError: import httplib as http_client http_client.HTTPConnection.debuglevel = 1 logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger('requests.packages.urllib3') ...
'Decode and parse given torrent @param torrent: handles: urls, file paths, string of torrent data @type torrent: str @raise AssertionError: Can be raised for a couple reasons: - If _get_raw_torrent() couldn\'t figure out what X{torrent} is - if X{torrent} isn\'t a valid bencoded torrent file'
def __init__(self, torrent):
self.torrent = torrent self._raw_torrent = None self._torrent_decoded = None self.file_type = None self._get_raw_torrent() assert (self._raw_torrent is not None), "Couldn't get raw_torrent." if (self._torrent_decoded is None): self._decode_torrent() assert isinstance(self._...
'Get raw torrent data by determining what self.torrent is'
def _get_raw_torrent(self):
if self._is_raw(): self.file_type = 'raw' self._raw_torrent = self.torrent return if os.path.isfile(self.torrent): self.file_type = 'file' self._raw_torrent = open(self.torrent, 'rb').read() elif re.search('^(http|ftp):\\/\\/', self.torrent, re.I): self.file_t...
'Refresh file data @note: All fields are stored as attributes to self. @return: None'
def update(self):
multicall = rtorrent.rpc.Multicall(self) retriever_methods = [m for m in methods if (m.is_retriever() and m.is_available(self._rt_obj))] for method in retriever_methods: multicall.add(method, self.rpc_id) multicall.call()
'only calls methods that check instance variables.'
def _call_custom_methods(self):
self._is_hash_checking_queued() self._is_started() self._is_paused()
'Get list of Peer instances for given torrent. @return: L{Peer} instances @rtype: list @note: also assigns return value to self.peers'
def get_peers(self):
self.peers = [] retriever_methods = [m for m in rtorrent.peer.methods if (m.is_retriever() and m.is_available(self._rt_obj))] m = rtorrent.rpc.Multicall(self) m.add('p.multicall', self.info_hash, '', *[(method.rpc_call + '=') for method in retriever_methods]) results = m.call()[0] for result in ...
'Get list of Tracker instances for given torrent. @return: L{Tracker} instances @rtype: list @note: also assigns return value to self.trackers'
def get_trackers(self):
self.trackers = [] retriever_methods = [m for m in rtorrent.tracker.methods if (m.is_retriever() and m.is_available(self._rt_obj))] m = rtorrent.rpc.Multicall(self) m.add('t.multicall', self.info_hash, '', *[(method.rpc_call + '=') for method in retriever_methods]) results = m.call()[0] for resu...
'Get list of File instances for given torrent. @return: L{File} instances @rtype: list @note: also assigns return value to self.files'
def get_files(self):
self.files = [] retriever_methods = [m for m in rtorrent.file.methods if (m.is_retriever() and m.is_available(self._rt_obj))] m = rtorrent.rpc.Multicall(self) m.add('f.multicall', self.info_hash, '', *[(method.rpc_call + '=') for method in retriever_methods]) results = m.call()[0] offset_method_...
'Modify download directory @note: Needs to stop torrent in order to change the directory. Also doesn\'t restart after directory is set, that must be called separately.'
def set_directory(self, d):
m = rtorrent.rpc.Multicall(self) self.multicall_add(m, 'd.try_stop') self.multicall_add(m, 'd.set_directory', d) self.directory = m.call()[(-1)]
'Modify base download directory @note: Needs to stop torrent in order to change the directory. Also doesn\'t restart after directory is set, that must be called separately.'
def set_directory_base(self, d):
m = rtorrent.rpc.Multicall(self) self.multicall_add(m, 'd.try_stop') self.multicall_add(m, 'd.set_directory_base', d)
'Start the torrent'
def start(self):
m = rtorrent.rpc.Multicall(self) self.multicall_add(m, 'd.try_start') self.multicall_add(m, 'd.is_active') self.active = m.call()[(-1)] return self.active
'"Stop the torrent'
def stop(self):
m = rtorrent.rpc.Multicall(self) self.multicall_add(m, 'd.try_stop') self.multicall_add(m, 'd.is_active') self.active = m.call()[(-1)] return self.active
'Pause the torrent'
def pause(self):
m = rtorrent.rpc.Multicall(self) self.multicall_add(m, 'd.pause') return m.call()[(-1)]
'Resume the torrent'
def resume(self):
m = rtorrent.rpc.Multicall(self) self.multicall_add(m, 'd.resume') return m.call()[(-1)]
'Close the torrent and it\'s files'
def close(self):
m = rtorrent.rpc.Multicall(self) self.multicall_add(m, 'd.close') return m.call()[(-1)]
'Delete the torrent @note: doesn\'t delete the downloaded files'
def erase(self):
m = rtorrent.rpc.Multicall(self) self.multicall_add(m, 'd.erase') return m.call()[(-1)]
'(Re)hash check the torrent'
def check_hash(self):
m = rtorrent.rpc.Multicall(self) self.multicall_add(m, 'd.check_hash') return m.call()[(-1)]
'poll rTorrent to get latest peer/tracker/file information'
def poll(self):
self.get_peers() self.get_trackers() self.get_files()
'Refresh torrent data @note: All fields are stored as attributes to self. @return: None'
def update(self):
multicall = rtorrent.rpc.Multicall(self) retriever_methods = [m for m in methods if (m.is_retriever() and m.is_available(self._rt_obj))] for method in retriever_methods: multicall.add(method, self.rpc_id) multicall.call() self._call_custom_methods()
'Enable/disable whether the torrent connects to seeders @param accept_seeds: enable/disable accepting seeders @type accept_seeds: bool'
def accept_seeders(self, accept_seeds):
if accept_seeds: call = 'd.accepting_seeders.enable' else: call = 'd.accepting_seeders.disable' m = rtorrent.rpc.Multicall(self) self.multicall_add(m, call) return m.call()[(-1)]