Ejemplo n.º 1
0
def make_request(url, postdata='', proxy_handlers=None):
    handlers = [
        urllib2.HTTPHandler(debuglevel=100),
        urllib2.HTTPSHandler(debuglevel=100)
    ]
    if proxy_handlers:
        handlers.extend(proxy_handlers)

    opener = urllib2.build_opener(*handlers)

    url_req = urllib2.Request(url, postdata)

    handle = None
    try:
        handle = opener.open(url_req)
        print '****************************** HEADERS ******************************'
        print handle.info()
        print '****************************** CONTENT ******************************'
        print handle.read()

    except urllib2.HTTPError as e:
        print 'Error code:', e.code, 'Exception:', str(e)

    except urllib2.URLError as e:
        code, errstr = e.reason
        print 'Error code:', code, 'Exception:', errstr

    except Exception as e:
        print 'Exception:', str(e)

    finally:
        if handle:
            handle.close()
            handle = None
Ejemplo n.º 2
0
def create_download_handle(url,
                           postdata,
                           proxy_handlers,
                           auth_handlers,
                           cert,
                           last_modified=None,
                           etag=None,
                           headers=None,
                           method=None,
                           timeout_sec=None):
    """
    Wraps handle download creation.
    """
    if postdata is None:
        url_req = urllib2.Request(url, method=method)
    else:
        url_req = urllib2.Request(url, postdata, method=method)

    if headers:
        for item, val in headers:
            url_req.add_header(item, val)

    # These headers are used for checking whether there has been any modifications.
    # It will return a 304 by way of an exception on open()
    if last_modified:
        url_req.add_header(
            'If-Modified-Since',
            time.strftime('%a, %d %b %Y %H:%M:%S GMT',
                          time.localtime(last_modified)))
    if etag:
        url_req.add_header('If-None-Match', etag)

    url_opener = build_opener(cert, proxy_handlers, auth_handlers)

    if timeout_sec:
        return url_opener.open(url_req, timeout=timeout_sec)

    return url_opener.open(url_req)
Ejemplo n.º 3
0
def create_connect_handle(host,
                          proxy_handlers,
                          auth_handlers=None,
                          cert=None,
                          timeout_sec=None):
    """
    Wraps handle connect creation.
    """
    url_req = urllib2.Request(host)

    url_opener = build_connect_opener(cert, proxy_handlers, auth_handlers)

    if timeout_sec:
        return url_opener.open(url_req, timeout=timeout_sec)

    return url_opener.open(url_req)
Ejemplo n.º 4
0
 def revokeDevelopmentCert(self, serialNumber):
     requestId = str(uuid.uuid4()).upper()
     postData = {
         "clientId": self.clientId,
         "myacinfo": self.accountBlob,
         "protocolVersion": "QH65B2",
         "requestId": requestId,
         "teamId": self.teamId,
         "serialNumber": serialNumber,
         "userLocale": ["en_US"]
     }
     plist = plistlib.writePlistToString(postData)
     response = self.browser.open(
         urllib2.Request(
             "https://developerservices2.apple.com/services/QH65B2/ios/revokeDevelopmentCert.action?clientId="
             + self.clientId, plist, {'Content-Type': 'text/x-xml-plist'}))
Ejemplo n.º 5
0
 def retrieveDevelopmentCerts(self):
     requestId = str(uuid.uuid4()).upper()
     postData = {
         "clientId": self.clientId,
         "myacinfo": self.accountBlob,
         "protocolVersion": "QH65B2",
         "requestId": requestId,
         "teamId": self.teamId,
         "userLocale": ["en_US"]
     }
     plist = plistlib.writePlistToString(postData)
     response = self.browser.open(
         urllib2.Request(
             "https://developerservices2.apple.com/services/QH65B2/ios/listAllDevelopmentCerts.action?clientId="
             + self.clientId, plist, {'Content-Type': 'text/x-xml-plist'}))
     responseData = response.read()
     root = plistlib.readPlistFromString(responseData)
     return root["certificates"]
Ejemplo n.º 6
0
 def removeAppId(self, appIdId):
     requestId = str(uuid.uuid4()).upper()
     postData = {
         "clientId": self.clientId,
         "myacinfo": self.accountBlob,
         "protocolVersion": "QH65B2",
         "requestId": requestId,
         "teamId": self.teamId,
         "appIdId": appIdId,
         "userLocale": ["en_US"]
     }
     plist = plistlib.writePlistToString(postData)
     response = self.browser.open(
         urllib2.Request(
             "https://developerservices2.apple.com/services/QH65B2/ios/deleteAppId.action?clientId="
             + self.clientId, plist, {'Content-Type': 'text/x-xml-plist'}))
     responseData = response.read()
     return responseData
Ejemplo n.º 7
0
    def retrieveActiveTeam(self):
        requestId = str(uuid.uuid4()).upper()
        postData = {
            "clientId": self.clientId,
            "myacinfo": self.accountBlob,
            "protocolVersion": "QH65B2",
            "requestId": requestId,
            "userLocale": ["en_US"]
        }
        plist = plistlib.writePlistToString(postData)
        response = self.browser.open(
            urllib2.Request(
                "https://developerservices2.apple.com/services/QH65B2/listTeams.action?clientId="
                + self.clientId, plist, {'Content-Type': 'text/x-xml-plist'}))
        responseData = response.read()
        root = plistlib.readPlistFromString(responseData)
        teams = root["teams"]
        for team in teams:
            if team["status"] == "active":
                return team

        logger.error("No active teams listed on the account")
Ejemplo n.º 8
0
 def addAppId(self, identifier):
     requestId = str(uuid.uuid4()).upper()
     postData = {
         "clientId": self.clientId,
         "myacinfo": self.accountBlob,
         "protocolVersion": "QH65B2",
         "requestId": requestId,
         "teamId": self.teamId,
         "entitlements": [],
         "identifier": identifier,
         "name": "Xcode iOS App ID " + identifier.replace(".", " "),
         "appIdName": "Xcode iOS App ID " + identifier.replace(".", " "),
         "userLocale": ["en_US"]
     }
     plist = plistlib.writePlistToString(postData)
     response = self.browser.open(
         urllib2.Request(
             "https://developerservices2.apple.com/services/QH65B2/ios/addAppId.action?clientId="
             + self.clientId, plist, {'Content-Type': 'text/x-xml-plist'}))
     responseData = response.read()
     root = plistlib.readPlistFromString(responseData)
     return root
Ejemplo n.º 9
0
def main():
    parser = OptionParser(usage='Usage: %prog [options] (-h for help)')
    parser.add_option('-p', '--port', dest='port', default='8088')
    options, args = parser.parse_args()

    proxy_server = 'http://localhost:%s' % options.port
    proxy_handler = urllib2.ProxyHandler({
        'http': proxy_server,
        'https': proxy_server,
    })

    proxy = ProxyServer(int(options.port))
    proxy.start()

    headers = None
    timeout_sec = 5
    for url, postdata in THE_INTERWEBS:
        print '****************'
        url_req = urllib2.Request(url, postdata)
        if headers:
            for item, val in headers:
                url_req.add_header(item, val)

        handlers = [proxy_handler]
        url_opener = urllib2.build_opener(*handlers)

        handle = None
        if timeout_sec:
            handle = url_opener.open(url_req, timeout=timeout_sec)

        print handle.info().items()
        print handle.read()
        print '****************'

    proxy.stop()

    return 0