当前位置: 首页>>代码示例>>Python>>正文


Python Requester.Requester类代码示例

本文整理汇总了Python中Requester.Requester的典型用法代码示例。如果您正苦于以下问题:Python Requester类的具体用法?Python Requester怎么用?Python Requester使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Requester类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

class Github:
    def __init__( self, login=None, password=None ):
        self.__requester = Requester( login=login, password=password )

    def _dataRequest( self, verb, url, parameters, data ):
        return self.__requester.dataRequest( verb, url, parameters, data )

    def _statusRequest( self, verb, url, parameters, data ):
        return self.__requester.statusRequest( verb, url, parameters, data )

    def get_user( self, login = None ):
        if login is None:
            return AuthenticatedUser( self, {}, lazy = True )
        else:
            return NamedUser( self, { "login": login }, lazy = False )

    def get_organization( self, login ):
        return Organization( self, { "login": login }, lazy = False )

    def get_gist( self, id ):
        return Gist( self, { "id": id }, lazy = False )

    def get_gists( self ):
        return [
            Gist( self, attributes, lazy = True )
            for attributes
            in self._dataRequest( "GET", "/gists/public", None, None )
        ]
开发者ID:abersager,项目名称:PyGithub,代码行数:28,代码来源:Github.py

示例2: __init__

 def __init__(self, authId, authPass):
     Requester.__init__(self, "https://mtgox.com/api/1")
     self._authKey = authId
     self._authSecret = base64.b64decode(authPass.encode())
     # for now, we will manage only EUR.
     #self._availableCurrencies = {"USD", "EUR", "JPY", "CAD", "GBP", "CHF", "RUB", "AUD", "SEK", "DKK", "HKD", "PLN", "CNY", "SGD", "THB", "NZD", "NOK"}
     self._availableCurrencies = {"EUR"}
开发者ID:PoncinMatthieu,项目名称:BTCTrader,代码行数:7,代码来源:MtGoxRequester.py

示例3: __init__

    def __init__(   self, 
                    api_key=None, 
                    api_secret=None, 
                    oauth_token=None, 
                    oauth_token_secret=None):

        self.__requester = Requester( api_key, api_secret, oauth_token, oauth_token_secret)
开发者ID:alvarovmz,项目名称:PyLinkedIn,代码行数:7,代码来源:LinkedIn.py

示例4: __init__

    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,
    ):
        """
        :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
        """

        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 None or isinstance(client_id, (str, unicode)), client_id
        assert client_secret is None or isinstance(client_secret, (str, unicode)), client_secret
        assert user_agent is None or isinstance(user_agent, (str, unicode)), user_agent
        self.__requester = Requester(
            login_or_token, password, base_url, timeout, client_id, client_secret, user_agent, per_page
        )
开发者ID:PropaHard82,项目名称:PyGithub,代码行数:32,代码来源:MainClass.py

示例5: __init__

    def __init__(self, login_or_token=None, password=None, jwt=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, verify=True, retry=None):
        """
        :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
        :param verify: boolean or string
        :param retry: int or urllib3.util.retry.Retry object
        """

        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 jwt is None or isinstance(jwt, (str, unicode)), jwt
        assert isinstance(base_url, (str, unicode)), base_url
        assert isinstance(timeout, (int, long)), timeout
        assert client_id is None or isinstance(client_id, (str, unicode)), client_id
        assert client_secret is None or isinstance(client_secret, (str, unicode)), client_secret
        assert user_agent is None or isinstance(user_agent, (str, unicode)), user_agent
        assert isinstance(api_preview, (bool))
        assert retry is None or isinstance(retry, (int)) or isinstance(retry, (urllib3.util.Retry))
        self.__requester = Requester(login_or_token, password, jwt, base_url, timeout, client_id, client_secret, user_agent, per_page, api_preview, verify, retry)
开发者ID:PyGithub,项目名称:PyGithub,代码行数:25,代码来源:MainClass.py

示例6: Github

class Github( object ):
    def __init__( self, login_or_token = None, password = None ):
        self.__requester = Requester( login_or_token, password )

    @property
    def rate_limiting( self ):
        return self.__requester.rate_limiting

    def get_user( self, login = None ):
        if login is None:
            return AuthenticatedUser.AuthenticatedUser( self.__requester, { "url": "https://api.github.com/user" }, completed = False )
        else:
            headers, data = self.__requester.requestAndCheck(
                "GET",
                "https://api.github.com/users/" + login,
                None,
                None
            )
            return NamedUser.NamedUser( self.__requester, data, completed = True )

    def get_organization( self, login ):
        headers, data = self.__requester.requestAndCheck(
            "GET",
            "https://api.github.com/orgs/" + login,
            None,
            None
        )
        return Organization.Organization( self.__requester, data, completed = True )

    def get_gist( self, id ):
        headers, data = self.__requester.requestAndCheck(
            "GET",
            "https://api.github.com/gists/" + str( id ),
            None,
            None
        )
        return Gist.Gist( self.__requester, data, completed = True )

    def get_gists( self ):
        headers, data = self.__requester.requestAndCheck( "GET", "https://api.github.com/gists/public", None, None )
        return PaginatedList.PaginatedList(
            Gist.Gist,
            self.__requester,
            headers,
            data
        )
开发者ID:herlo,项目名称:PyGithub,代码行数:46,代码来源:Github.py

示例7: __init__

 def __init__(self, config, eventSched, httpRequester, ownAddrFunc, peerId, persister, pInMeasure, pOutMeasure,
              peerPool, connBuilder, connListener, connHandler, choker, torrent, torrentIdent, torrentDataPath, version):
     ##global stuff
     self.config = config
     self.version = version
     self.peerPool = peerPool
     self.connBuilder = connBuilder
     self.connListener = connListener
     self.connHandler = connHandler
     self.choker = choker
     
     ##own stuff
     self.log = Logger('Bt', '%-6s - ', torrentIdent)
     self.torrent = torrent
     self.torrentIdent = torrentIdent
     
     self.log.debug("Creating object persister")
     self.btPersister = BtObjectPersister(persister, torrentIdent)
     
     self.log.debug("Creating measure classes")
     self.inRate = Measure(eventSched, 60, [pInMeasure])
     self.outRate = Measure(eventSched, 60, [pOutMeasure])
     self.inRate.stop()
     self.outRate.stop()
     
     self.log.debug("Creating storage class")
     self.storage = Storage(self.config, self.btPersister, torrentIdent, self.torrent, torrentDataPath)
     
     self.log.debug("Creating global status class")
     self.pieceStatus = PieceStatus(self.torrent.getTotalAmountOfPieces())
     
     self.log.debug("Creating file priority class")
     self.filePrio = FilePriority(self.btPersister, self.version, self.pieceStatus, self.storage.getStatus(),
                                  self.torrent, torrentIdent)
     
     self.log.debug("Creating requester class")
     self.requester = Requester(self.config, self.torrentIdent, self.pieceStatus, self.storage, self.torrent)
     
     self.log.debug("Creating tracker requester class")
     self.trackerRequester = TrackerRequester(self.config, self.btPersister, eventSched, peerId, self.peerPool, ownAddrFunc, httpRequester,
                                              self.inRate, self.outRate, self.storage, self.torrent, self.torrentIdent, self.version)
     
     self.log.debug("Creating superseeding handler class")
     self.superSeedingHandler = SuperSeedingHandler(self.torrentIdent, self.btPersister, self.storage.getStatus(), self.pieceStatus)
     
     ##callbacks
     self.log.debug("Adding callbacks")
     self._addCallbacks()
     
     ##status
     self.state = 'stopped'
     self.started = False
     self.paused = True
     
     ##lock
     self.lock = threading.Lock()
开发者ID:kytvi2p,项目名称:i2p.pybit,代码行数:56,代码来源:Bt.py

示例8: setUp

    def setUp( self ):
        unittest.TestCase.setUp( self )

        self.r = Requester( "login", "password" )
        self.b64_userpass = base64.b64encode( "login:password" )
        self.b64_userpass = self.b64_userpass.replace( '\n', '' )

        self.connectionFactory = MockMockMock.Mock( "httplib.HTTPSConnection" )
        self.connection = MockMockMock.Mock( "connection", self.connectionFactory )
        self.response = MockMockMock.Mock( "response", self.connectionFactory )

        httplib.HTTPSConnection = self.connectionFactory.object
开发者ID:abersager,项目名称:PyGithub,代码行数:12,代码来源:Requester.UnitTest.py

示例9: TestCase

class TestCase( unittest.TestCase ):
    def setUp( self ):
        unittest.TestCase.setUp( self )

        self.r = Requester( "login", "password" )
        self.b64_userpass = base64.b64encode( "login:password" )
        self.b64_userpass = self.b64_userpass.replace( '\n', '' )

        self.connectionFactory = MockMockMock.Mock( "httplib.HTTPSConnection" )
        self.connection = MockMockMock.Mock( "connection", self.connectionFactory )
        self.response = MockMockMock.Mock( "response", self.connectionFactory )

        httplib.HTTPSConnection = self.connectionFactory.object

    def tearDown( self ):
        self.connectionFactory.tearDown()
        unittest.TestCase.tearDown( self )

    def expect( self, verb, url, input, status, responseHeaders, output ):
        self.connectionFactory.expect( "api.github.com", strict = True ).andReturn( self.connection.object )
        self.connection.expect.request( verb, url, input, { "Authorization" : "Basic " + self.b64_userpass } )
        self.connection.expect.getresponse().andReturn( self.response.object )
        self.response.expect.status.andReturn( status )
        self.response.expect.getheaders().andReturn( responseHeaders )
        self.response.expect.read().andReturn( output )
        self.connection.expect.close()

    def testSimpleStatus( self ):
        self.expect( "GET", "/test", "null", 200, [], "" )
        self.assertEqual( self.r.statusRequest( "GET", "/test", None, None ), 200 )

    def testSimpleData( self ):
        self.expect( "GET", "/test", "null", 200, [], '{ "foo": "bar" }' )
        self.assertEqual( self.r.dataRequest( "GET", "/test", None, None ), { "foo" : "bar" } )

    def testDataOnBadStatus( self ):
        self.expect( "GET", "/test", "null", 404, [], '{ "foo": "bar" }' )
        with self.assertRaises( UnknownGithubObject ):
            self.r.dataRequest( "GET", "/test", None, None )

    def testDataWithParametersAndData( self ):
        self.expect( "GET", "/test?tata=tutu&toto=titi", '{"xxx": 42}', 200, [], '{ "foo": "bar" }' )
        self.assertEqual( self.r.dataRequest( "GET", "/test", { "toto" : "titi", "tata" : "tutu" }, { "xxx" : 42 } ), { "foo" : "bar" } )

    def testPagination( self ):
        self.expect( "GET", "/test", 'null', 200, [ ( "link", "<xxx?page=2>; next, xxx; last" ) ], '[ 1, 2 ]' )
        self.expect( "GET", "/test?page=2", 'null', 200, [ ( "link", "xxx; prev, xxx; first, <xxx?page=3>; next, xxx; last" ) ], '[ 3, 4 ]' )
        self.expect( "GET", "/test?page=3", 'null', 200, [ ( "link", "xxx; prev, xxx; first" ) ], '[ 5, 6 ]' )
        self.assertEqual( self.r.dataRequest( "GET", "/test", None, None ), [ 1, 2, 3, 4, 5, 6 ] )

    def testPaginationObviouslyFinished( self ):
        self.expect( "GET", "/test", 'null', 200, [ ( "link", "<xxx?page=2>; next, xxx; last" ) ], '[ 1, 2 ]' )
        self.expect( "GET", "/test?page=2", 'null', 200, [ ( "link", "xxx; prev, xxx; first, <xxx?page=3>; next, xxx; last" ) ], '[ 3, 4 ]' )
        self.expect( "GET", "/test?page=3", 'null', 200, [ ( "link", "xxx; prev, xxx; first" ) ], '[]' )
        self.assertEqual( self.r.dataRequest( "GET", "/test", None, None ), [ 1, 2, 3, 4 ] )
开发者ID:abersager,项目名称:PyGithub,代码行数:55,代码来源:Requester.UnitTest.py

示例10: LinkedIn

class LinkedIn( object ):
    def __init__(   self, 
                    api_key=None, 
                    api_secret=None, 
                    oauth_token=None, 
                    oauth_token_secret=None):

        self.__requester = Requester( api_key, api_secret, oauth_token, oauth_token_secret)


    def get_user( self, login = None ):

        headers, data = self.__requester.requestAndCheck(
            "GET",
            'https://api.linkedin.com/v1/people/~',
            ['id','first-name'],
            None
        )

        return LinkedInUser.LinkedInUser( self.__requester, data, completed = True )
开发者ID:alvarovmz,项目名称:PyLinkedIn,代码行数:20,代码来源:LinkedIn.py

示例11: __init__

 def __init__( self, login_or_token = None, password = None ):
     self.__requester = Requester( login_or_token, password )
开发者ID:herlo,项目名称:PyGithub,代码行数:2,代码来源:Github.py

示例12: Github

class Github( object ):
    def __init__( self, login_or_token = None, password = None, base_url = DEFAULT_BASE_URL, timeout = DEFAULT_TIMEOUT):
        self.__requester = Requester( login_or_token, password, base_url, timeout )

    @property
    def rate_limiting( self ):
        return self.__requester.rate_limiting

    def get_user( self, login = GithubObject.NotSet ):
        assert login is GithubObject.NotSet or isinstance( login, ( str, unicode ) ), login
        if login is GithubObject.NotSet:
            return AuthenticatedUser.AuthenticatedUser( self.__requester, { "url": "/user" }, completed = False )
        else:
            headers, data = self.__requester.requestAndCheck(
                "GET",
                "/users/" + login,
                None,
                None
            )
            return NamedUser.NamedUser( self.__requester, data, completed = True )

    def get_organization( self, login ):
        assert isinstance( login, ( str, unicode ) ), login
        headers, data = self.__requester.requestAndCheck(
            "GET",
            "/orgs/" + login,
            None,
            None
        )
        return Organization.Organization( self.__requester, data, completed = True )

    def get_gist( self, id ):
        assert isinstance( id, ( str, unicode ) ), id
        headers, data = self.__requester.requestAndCheck(
            "GET",
            "/gists/" + id,
            None,
            None
        )
        return Gist.Gist( self.__requester, data, completed = True )

    def get_gists( self ):
        headers, data = self.__requester.requestAndCheck( "GET", "/gists/public", None, None )
        return PaginatedList.PaginatedList(
            Gist.Gist,
            self.__requester,
            headers,
            data
        )

    def legacy_search_repos( self, keyword, language = GithubObject.NotSet ):
        assert isinstance( keyword, ( str, unicode ) ), keyword
        assert language is GithubObject.NotSet or isinstance( language, ( str, unicode ) ), language
        args = {} if language is GithubObject.NotSet else { "language": language }
        return Legacy.PaginatedList(
            "/legacy/repos/search/" + urllib.quote( keyword ),
            args,
            self.__requester,
            "repositories",
            Legacy.convertRepo,
            Repository.Repository,
        )

    def legacy_search_users( self, keyword ):
        assert isinstance( keyword, ( str, unicode ) ), keyword
        return Legacy.PaginatedList(
            "/legacy/user/search/" + urllib.quote( keyword ),
            {},
            self.__requester,
            "users",
            Legacy.convertUser,
            NamedUser.NamedUser,
        )

    def legacy_search_user_by_email( self, email ):
        assert isinstance( email, ( str, unicode ) ), email
        headers, data = self.__requester.requestAndCheck(
            "GET",
            "/legacy/user/email/" + email,
            None,
            None
        )
        return NamedUser.NamedUser( self.__requester, Legacy.convertUser( data[ "user" ] ), completed = False )

    def render_markdown( self, text, context = GithubObject.NotSet ):
        assert isinstance( text, ( str, unicode ) ), text
        assert context is GithubObject.NotSet or isinstance( context, Repository.Repository ), context
        post_parameters = {
            "text": text
        }
        if context is not GithubObject.NotSet:
            post_parameters[ "mode" ] = "gfm"
            post_parameters[ "context" ] = context._identity
        status, headers, data = self.__requester.requestRaw(
            "POST",
            "/markdown",
            None,
            post_parameters
        )
        return data
#.........这里部分代码省略.........
开发者ID:mnsanghvi,项目名称:PyGithub,代码行数:101,代码来源:Github.py

示例13: __init__

 def __init__( self, login_or_token = None, password = None, base_url = DEFAULT_BASE_URL, timeout = DEFAULT_TIMEOUT):
     self.__requester = Requester( login_or_token, password, base_url, timeout )
开发者ID:mnsanghvi,项目名称:PyGithub,代码行数:2,代码来源:Github.py

示例14: __init__

 def __init__(self, _printing=False, _use_cache=False):
     Requester.__init__(self, _printing, _use_cache)
     
     # Table mapping response codes to messages; entries have the
     # form {code: (shortmessage, longmessage)}.
     self.responses = {
         100: ('Continue', 'Request received, please continue'),
         101: ('Switching Protocols',
               'Switching to new protocol; obey Upgrade header'),
     
         200: ('OK', 'Request fulfilled, document follows'),
         201: ('Created', 'Document created, URL follows'),
         202: ('Accepted',
               'Request accepted, processing continues off-line'),
         203: ('Non-Authoritative Information', 'Request fulfilled from cache'),
         204: ('No Content', 'Request fulfilled, nothing follows'),
         205: ('Reset Content', 'Clear input form for further input.'),
         206: ('Partial Content', 'Partial content follows.'),
     
         300: ('Multiple Choices',
               'Object has several resources -- see URI list'),
         301: ('Moved Permanently', 'Object moved permanently -- see URI list'),
         302: ('Found', 'Object moved temporarily -- see URI list'),
         303: ('See Other', 'Object moved -- see Method and URL list'),
         304: ('Not Modified',
               'Document has not changed since given time'),
         305: ('Use Proxy',
               'You must use proxy specified in Location to access this '
               'resource.'),
         307: ('Temporary Redirect',
               'Object moved temporarily -- see URI list'),
     
         400: ('Bad Request',
               'Bad request syntax or unsupported method'),
         401: ('Unauthorized',
               'No permission -- see authorization schemes'),
         402: ('Payment Required',
               'No payment -- see charging schemes'),
         403: ('Forbidden',
               'Request forbidden -- authorization will not help'),
         404: ('Not Found', 'Nothing matches the given URI'),
         405: ('Method Not Allowed',
               'Specified method is invalid for this server.'),
         406: ('Not Acceptable', 'URI not available in preferred format.'),
         407: ('Proxy Authentication Required', 'You must authenticate with '
               'this proxy before proceeding.'),
         408: ('Request Timeout', 'Request timed out; try again later.'),
         409: ('Conflict', 'Request conflict.'),
         410: ('Gone',
               'URI no longer exists and has been permanently removed.'),
         411: ('Length Required', 'Client must specify Content-Length.'),
         412: ('Precondition Failed', 'Precondition in headers is false.'),
         413: ('Request Entity Too Large', 'Entity is too large.'),
         414: ('Request-URI Too Long', 'URI is too long.'),
         415: ('Unsupported Media Type', 'Entity body in unsupported format.'),
         416: ('Requested Range Not Satisfiable',
               'Cannot satisfy request range.'),
         417: ('Expectation Failed',
               'Expect condition could not be satisfied.'),
     
         500: ('Internal Server Error', 'Server got itself in trouble'),
         501: ('Not Implemented',
               'Server does not support this operation'),
         502: ('Bad Gateway', 'Invalid responses from another server/proxy.'),
         503: ('Service Unavailable',
               'The server cannot process the request due to a high load'),
         504: ('Gateway Timeout',
               'The gateway server did not receive a timely response'),
         505: ('HTTP Version Not Supported', 'Cannot fulfill request.'),
     }
开发者ID:darkman66,项目名称:PageGet,代码行数:70,代码来源:RequesterUrllib.py

示例15: __init__

 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=None):
     self.__requester = Requester(login_or_token, password, base_url, timeout, client_id, client_secret, user_agent)
开发者ID:bhaveshnigam,项目名称:PyGithub,代码行数:2,代码来源:Github.py


注:本文中的Requester.Requester类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。