python类VERSION的实例源码

ircthread.py 文件源码 项目:electrum-martexcoin-server 作者: martexcoin 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def getname(self):
        s = 'v' + VERSION + ' '
        if self.pruning:
            s += 'p' + self.pruning_limit + ' '

        def add_port(letter, number):
            DEFAULT_PORTS = {'t':'50001', 's':'50002', 'h':'8081', 'g':'8082'}
            if not number: return ''
            if DEFAULT_PORTS[letter] == number:
                return letter + ' '
            else:
                return letter + number + ' '

        s += add_port('t',self.stratum_tcp_port)
        s += add_port('h',self.stratum_http_port)
        s += add_port('s',self.stratum_tcp_ssl_port)
        s += add_port('g',self.stratum_http_ssl_port)
        return s
I8BPServer.py 文件源码 项目:Infinite8BitPlatformer 作者: chr15m 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def Network_playerid(self, data):
        # either player has supplied their unique player ID, in which case we remember it
        # TODO: check against server's clientData to make sure they supplied a valid ID
        if data.has_key("id"):
            self.playerID = data['id']
        # or client has asked for a new unique, persistent, secret UUID
        # creates the player's unique id and sends it back to them
        # this id is secret and persistent, and not known by any other client
        else:
            self.playerID = self._server.GetNewPlayerID(self)
        # check that the client protocol version is new enough to play with us
        clientversion = data.get('version', -1)
        if clientversion < VERSION:
            self.Send({"action": "badversion", "message": "You are running version %d of the client protocol, but the server is %d." % (clientversion, VERSION), "version": VERSION})
            #self.close_when_done()
            self._server.Log("VERSION MISMATCH: %d / server %d" % (clientversion, VERSION))
        else:
            self._server.Log("VERSION: Player %d has ID %s" % (self.ID, self.playerID))
            self.Send({"action": "playerid", "id": self.playerID, "version": VERSION})
move_workbook_projects.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def get_workbook_id(server, auth_token, user_id, site_id, workbook_name):
    """
    Gets the id of the desired workbook to relocate.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'user_id'       ID of user with access to workbook
    'site_id'       ID of the site that the user is signed into
    'workbook_name' name of workbook to get ID of
    Returns the workbook id and the project id that contains the workbook.
    """
    url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    workbooks = xml_response.findall('.//t:workbook', namespaces=xmlns)
    for workbook in workbooks:
        if workbook.get('name') == workbook_name:
            source_project_id = workbook.find('.//t:project', namespaces=xmlns).get('id')
            return source_project_id, workbook.get('id')
    error = "Workbook named '{0}' not found.".format(workbook_name)
    raise LookupError(error)
move_workbook_projects.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def move_workbook(server, auth_token, site_id, workbook_id, project_id):
    """
    Moves the specified workbook to another project.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    'workbook_id'   ID of the workbook to move
    'project_id'    ID of the project to move workbook into
    """
    url = server + "/api/{0}/sites/{1}/workbooks/{2}".format(VERSION, site_id, workbook_id)
    # Build the request to move workbook
    xml_request = ET.Element('tsRequest')
    workbook_element = ET.SubElement(xml_request, 'workbook')
    ET.SubElement(workbook_element, 'project', id=project_id)
    xml_request = ET.tostring(xml_request)

    server_response = requests.put(url, data=xml_request, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
move_workbook_server.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def get_workbook_id(server, auth_token, user_id, site_id, workbook_name):
    """
    Gets the id of the desired workbook to relocate.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'user_id'       ID of user with access to workbook
    'site_id'       ID of the site that the user is signed into
    'workbook_name' name of workbook to get ID of
    Returns the workbook id and the project id that contains the workbook.
    """
    url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    workbooks = xml_response.findall('.//t:workbook', namespaces=xmlns)
    for workbook in workbooks:
        if workbook.get('name') == workbook_name:
            return workbook.get('id')
    error = "Workbook named '{0}' not found.".format(workbook_name)
    raise LookupError(error)
move_workbook_server.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def download(server, auth_token, site_id, workbook_id):
    """
    Downloads the desired workbook from the server (temp-file).

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    'workbook_id'   ID of the workbook to download
    Returns the filename of the workbook downloaded.
    """
    print("\tDownloading workbook to a temp file")
    url = server + "/api/{0}/sites/{1}/workbooks/{2}/content".format(VERSION, site_id, workbook_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)

    # Header format: Content-Disposition: name="tableau_workbook"; filename="workbook-filename"
    filename = re.findall(r'filename="(.*)"', server_response.headers['Content-Disposition'])[0]
    with open(filename, 'wb') as f:
        f.write(server_response.content)
    return filename
move_workbook_sites.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 13 收藏 0 点赞 0 评论 0
def get_workbook_id(server, auth_token, user_id, site_id, workbook_name):
    """
    Gets the id of the desired workbook to relocate.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'user_id'       ID of the user with access to workbooks
    'site_id'       ID of the site that the user is signed into
    'workbook_name' name of workbook to get ID of
    Returns the workbook id and the project id that contains the workbook.
    """
    url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    workbooks = xml_response.findall('.//t:workbook', namespaces=xmlns)
    for workbook in workbooks:
        if workbook.get('name') == workbook_name:
            return workbook.get('id')
    error = "Workbook named '{0}' not found.".format(workbook_name)
    raise LookupError(error)
user_permission_audit.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def get_workbook_id(server, auth_token, user_id, site_id, workbook_name):
    """
    Gets the id of the desired workbook to relocate.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'user_id'       ID of user with access to workbooks
    'site_id'       ID of the site that the user is signed into
    'workbook_name' name of workbook to get ID of
    Returns the workbook id and the project id that contains the workbook.
    """
    url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    # Find all workbooks in the site and look for the desired one
    workbooks = xml_response.findall('.//t:workbook', namespaces=xmlns)
    for workbook in workbooks:
        if workbook.get('name') == workbook_name:
            return workbook.get('id')
    error = "Workbook named '{0}' not found.".format(workbook_name)
    raise LookupError(error)
user_permission_audit.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def get_user_id(server, auth_token, site_id, username_to_audit):
    """
    Returns the user id of the user to audit permissions for, if found.

    'server'                specified server address
    'auth_token'            authentication token that grants user access to API calls
    'site_id'               ID of the site that the user is signed into
    'username_to_audit'     username to audit permission for on server
    """
    url = server + "/api/{0}/sites/{1}/users".format(VERSION, site_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    server_response = ET.fromstring(_encode_for_display(server_response.text))

    # Find all user tags in the response and look for matching id
    users = server_response.findall('.//t:user', namespaces=xmlns)
    for user in users:
        if user.get('name') == username_to_audit:
            return user.get('id')
    error = "User id for {0} not found".format(username_to_audit)
    raise LookupError(error)
user_permission_audit.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def delete_permission(server, auth_token, site_id, workbook_id, user_id, permission_name, existing_mode):
    """
    Deletes a specific permission from the workbook.

    'server'            specified server address
    'auth_token'        authentication token that grants user access to API calls
    'site_id'           ID of the site that the user is signed into
    'workbook_id'       ID of workbook to audit permission in
    'user_id'           ID of the user to audit
    'permission_name'   name of permission to add or update
    'existing_mode'     is the mode of the permission already set for the workbook
    """
    url = server + "/api/{0}/sites/{1}/workbooks/{2}/permissions/users/{3}/{4}/{5}".format(VERSION,
                                                                                           site_id,
                                                                                           workbook_id,
                                                                                           user_id,
                                                                                           permission_name,
                                                                                           existing_mode)
    server_response = requests.delete(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return
update_permission.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 13 收藏 0 点赞 0 评论 0
def get_user_id(server, auth_token, site_id, username_to_update):
    """
    Returns the user id of the user to update permissions for, if found.

    'server'                specified server address
    'auth_token'            authentication token that grants user access to API calls
    'site_id'               ID of the site that the user is signed into
    'username_to_update'    username to update permission for on server
    """
    url = server + "/api/{0}/sites/{1}/users".format(VERSION, site_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    server_response = ET.fromstring(_encode_for_display(server_response.text))

    # Find all user tags in the response and look for matching id
    users = server_response.findall('.//t:user', namespaces=xmlns)
    for user in users:
        if user.get('name') == username_to_update:
            return user.get('id')
    error = "User id for {0} not found".format(username_to_update)
    raise LookupError(error)
update_permission.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def query_permission(server, auth_token, site_id, workbook_id, user_id):
    """
    Returns a list of all permissions for the specified user.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    'workbook_id'   ID of workbook to update permission in
    'user_id'       ID of the user to update
    """
    url = server + "/api/{0}/sites/{1}/workbooks/{2}/permissions".format(VERSION, site_id, workbook_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    server_response = _encode_for_display(server_response.text)

    # Reads and parses the response
    parsed_response = ET.fromstring(server_response)

    # Find all the capabilities for a specific user
    capabilities = parsed_response.findall('.//t:granteeCapabilities', namespaces=xmlns)
    for capability in capabilities:
        user = capability.find('.//t:user', namespaces=xmlns)
        if user is not None and user.get('id') == user_id:
            return capability.findall('.//t:capability', namespaces=xmlns)
    return None
update_permission.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def delete_permission(server, auth_token, site_id, workbook_id, user_id, permission_name, existing_mode):
    """
    Deletes a specific permission from the workbook.

    'server'            specified server address
    'auth_token'        authentication token that grants user access to API calls
    'site_id'           ID of the site that the user is signed into
    'workbook_id'       ID of workbook to update permission in
    'user_id'           ID of the user to update
    'permission_name'   name of permission to update
    'existing_mode'     is the existing mode for the permission
    """
    url = server + "/api/{0}/sites/{1}/workbooks/{2}/permissions/users/{3}/{4}/{5}".format(VERSION,
                                                                                           site_id,
                                                                                           workbook_id,
                                                                                           user_id,
                                                                                           permission_name,
                                                                                           existing_mode)
    print("\tDeleting existing permission")
    server_response = requests.delete(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return
users_by_group.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def query_groups(server, auth_token, site_id, page_size, page_number):
    """
    Queries for all groups in the site
    URI GET /api/api-version/sites/site-id/groups
    GET /api/api-version/sites/site-id/groups?pageSize=page-size&pageNumber=page-number
    """
    if page_size == 0:
        url = server + "/api/{0}/sites/{1}/groups".format(VERSION, site_id)
    else:
        url = server + "/api/{0}/sites/{1}/groups?pageSize={2}&pageNumber={3}".format(VERSION, site_id, page_size, page_number)

    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))
    groups = xml_response.findall('.//t:group', namespaces=XMLNS)
    return groups
users_by_group.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def get_users_in_group(server, auth_token, site_id, group_id, page_size, page_number):
    """
    Get all the users in the group using group id
    GET /api/api-version/sites/site-id/groups/group-id/users
    GET /api/api-version/sites/site-id/groups/group-id/users?pageSize=page-size&pageNumber=page-number
    """
    if page_size == 0:
        url = server + "/api/{0}/sites/{1}/groups/{2}/users".format(VERSION, site_id, group_id)
    else:
        url = server + "/api/{0}/sites/{1}/groups/{2}/users?pageSize={3}&pageNumber={4}".format(VERSION, site_id, group_id, page_size, page_number)

    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    #_check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))
    users = xml_response.findall('.//t:user', namespaces=XMLNS)
    return users
views.py 文件源码 项目:starbound-ui-reposition 作者: Matoking 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def index(request):
    form = DownloadModForm(request.POST or None)

    if form.is_valid():
        cleaned_data = form.cleaned_data
        zip_data = create_mod({
            "top": cleaned_data["top"],
            "right": cleaned_data["right"],
            "bottom": cleaned_data["bottom"],
            "left": cleaned_data["left"]
        })

        response = HttpResponse(zip_data, content_type="application/zip")
        response["Content-Disposition"] = "attachment; filename=ui_reposition.zip"
        response["Content-Length"] = len(zip_data)
        return response

    return render(request, "index.html", {
        "version": VERSION,
        "presets": SCREEN_PRESETS
    })
prophyle.py 文件源码 项目:prophyle 作者: prophyle 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def _create_makefile(index_dir, k, library_dir, mask_repeats=False):
    """Create a Makefile for k-mer propagation.

    Args:
        index_dir (str): Index directory.
        k (int): K-mer size.
        library_dir (library_dir): Library directory.
        mask_repeats (bool): Mask repeats using DustMasker.

    TODO:
        * Add checking of params.mk
    """
    pro.message('Creating Makefile for k-mer propagation')
    propagation_dir = os.path.join(index_dir, 'propagation')
    pro.makedirs(propagation_dir)

    makefile = os.path.join(propagation_dir, 'Makefile')
    tree_fn = os.path.join(index_dir, 'tree.preliminary.nw')
    _test_tree(tree_fn)
    # pro.test_files(NEWICK2MAKEFILE, tree_fn)
    command = [NEWICK2MAKEFILE, '-k', k, tree_fn, os.path.abspath(library_dir), './', makefile]

    config = collections.OrderedDict()
    config['prophyle-version'] = version.VERSION
    config['prophyle-revision'] = version.REVCOUNT
    config['prophyle-commit'] = version.SHORTHASH
    config['k'] = k

    pro.save_index_config(index_dir, config)

    with open(os.path.join(propagation_dir, "params.mk"), "w+") as f:
        f.write('PRG_ASM="{}"\n'.format(ASM))
        f.write("K={}\n".format(k))
        if mask_repeats:
            f.write("MASKREP=1\n")
    pro.run_safe(command)
    _log_file_md5(makefile)
prophyle_assignment.py 文件源码 项目:prophyle 作者: prophyle 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def print_sam_header(self):
        """Print SAM headers.
        """
        print("@HD", "VN:1.5", "SO:unsorted", sep="\t", file=self.output_fo)
        print("@PG", "PN:prophyle", "ID:prophyle", "VN:{}".format(version.VERSION), sep="\t", file=self.output_fo)
        for node in self.tree_index.tree.traverse("postorder"):

            try:
                ur = "\tUR:{}".format(node.fastapath)
            except:
                ur = ""

            try:
                sp = "\tSP:{}".format(node.sci_name)
            except:
                sp = ""

            try:
                as_ = "\tAS:{}".format(node.gi)
            except:
                as_ = ""

            if node.name != '':
                print(
                    "@SQ\tSN:{rname}\tLN:{rlen}{as_}{ur}{sp}".format(
                        rname=node.name,
                        rlen=CONFIG['FAKE_CONTIG_LENGTH'],
                        as_=as_,
                        ur=ur,
                        sp=sp,
                    ), file=self.output_fo
                )
ovirtclient.py 文件源码 项目:ovirt-desktop-client 作者: nkovacne 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def initUI(self):
        """
            Description: Sets the size of the widget, the window title, centers
                         the window, connects signals to methods and opens the
                         Credentials dialog if needed.
            Arguments: None
            Returns: Nothing.
        """

        global conf, MAXWIDTH, MAXHEIGHT, IMGDIR, VERSION

        self.setFixedSize(MAXWIDTH, MAXHEIGHT)
        self.center()

        self.setWindowTitle(_('apptitle') + ' ' + VERSION)
        self.setWindowIcon(QIcon(IMGDIR + 'appicon.png'))
        self.show()

        self.updatesignal.connect(self.update_status_icon)
        self.logoutsignal.connect(self.logout)
        self.warnlogoutsignal.connect(self.logout_warn)
        self.reloadsignal.connect(self.load_vms)

        if not conf.USERNAME:
            creds = Credentials(self)
            creds.finished.connect(self.start_vmpane)
            creds.exec_()
epycyzm.py 文件源码 项目:epycyzm 作者: slush0 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def subscribe(self):
        ret = yield from self.call('mining.subscribe', VERSION, None, self.server.host, self.server.port)
        nonce1 = binascii.unhexlify(ret['result'][1])
        print("Successfully subscribed for jobs")
        self.solvers.set_nonce(nonce1)
        return nonce1
move_workbook_projects.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def sign_in(server, username, password, site=""):
    """
    Signs in to the server specified with the given credentials

    'server'   specified server address
    'name'     is the name (not ID) of the user to sign in as.
               Note that most of the functions in this example require that the user
               have server administrator permissions.
    'password' is the password for the user.
    'site'     is the ID (as a string) of the site on the server to sign in to. The
               default is "", which signs in to the default site.
    Returns the authentication token and the site ID.
    """
    url = server + "/api/{0}/auth/signin".format(VERSION)

    # Builds the request
    xml_request = ET.Element('tsRequest')
    credentials_element = ET.SubElement(xml_request, 'credentials', name=username, password=password)
    ET.SubElement(credentials_element, 'site', contentUrl=site)
    xml_request = ET.tostring(xml_request)

    # Make the request to server
    server_response = requests.post(url, data=xml_request)
    _check_status(server_response, 200)

    # ASCII encode server response to enable displaying to console
    server_response = _encode_for_display(server_response.text)

    # Reads and parses the response
    parsed_response = ET.fromstring(server_response)

    # Gets the auth token and site ID
    token = parsed_response.find('t:credentials', namespaces=xmlns).get('token')
    site_id = parsed_response.find('.//t:site', namespaces=xmlns).get('id')
    user_id = parsed_response.find('.//t:user', namespaces=xmlns).get('id')
    return token, site_id, user_id
move_workbook_projects.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def sign_out(server, auth_token):
    """
    Destroys the active session and invalidates authentication token.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    """
    url = server + "/api/{0}/auth/signout".format(VERSION)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return
move_workbook_projects.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def get_project_id(server, auth_token, site_id, dest_project):
    """
    Returns the project ID of the desired project

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    'dest_project'  name of destination project to get ID of
    """
    page_num, page_size = 1, 100   # Default paginating values

    # Builds the request
    url = server + "/api/{0}/sites/{1}/projects".format(VERSION, site_id)
    paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page_num)
    server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    # Used to determine if more requests are required to find all projects on server
    total_projects = int(xml_response.find('t:pagination', namespaces=xmlns).get('totalAvailable'))
    max_page = int(math.ceil(total_projects / page_size))

    projects = xml_response.findall('.//t:project', namespaces=xmlns)

    # Continue querying if more projects exist on the server
    for page in range(2, max_page + 1):
        paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page)
        server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
        _check_status(server_response, 200)
        xml_response = ET.fromstring(_encode_for_display(server_response.text))
        projects.extend(xml_response.findall('.//t:project', namespaces=xmlns))

    # Look through all projects to find the 'default' one
    for project in projects:
        if project.get('name') == dest_project:
            return project.get('id')
    error = "Project named '{0}' was not found on server".format(dest_project)
    raise LookupError(error)
move_workbook_server.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def sign_out(server, auth_token):
    """
    Destroys the active session and invalidates authentication token.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    """
    url = server + "/api/{0}/auth/signout".format(VERSION)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return
move_workbook_server.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def start_upload_session(server, auth_token, site_id):
    """
    Creates a POST request that initiates a file upload session.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    Returns a session ID that is used by subsequent functions to identify the upload session.
    """
    url = server + "/api/{0}/sites/{1}/fileUploads".format(VERSION, site_id)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 201)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))
    return xml_response.find('t:fileUpload', namespaces=xmlns).get('uploadSessionId')
move_workbook_server.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def get_default_project_id(server, auth_token, site_id):
    """
    Returns the project ID for the 'default' project on the Tableau server.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    """
    page_num, page_size = 1, 100  # Default paginating values

    # Builds the request
    url = server + "/api/{0}/sites/{1}/projects".format(VERSION, site_id)
    paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page_num)
    server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    # Used to determine if more requests are required to find all projects on server
    total_projects = int(xml_response.find('t:pagination', namespaces=xmlns).get('totalAvailable'))
    max_page = int(math.ceil(total_projects / page_size))

    projects = xml_response.findall('.//t:project', namespaces=xmlns)

    # Continue querying if more projects exist on the server
    for page in range(2, max_page + 1):
        paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page)
        server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
        _check_status(server_response, 200)
        xml_response = ET.fromstring(_encode_for_display(server_response.text))
        projects.extend(xml_response.findall('.//t:project', namespaces=xmlns))

    # Look through all projects to find the 'default' one
    for project in projects:
        if project.get('name') == 'default' or project.get('name') == 'Default':
            return project.get('id')
    print("\tProject named 'default' was not found in {0}".format(server))
move_workbook_sites.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def sign_in(server, username, password, site=""):
    """
    Signs in to the server specified with the given credentials

    'server'   specified server address
    'username' is the name (not ID) of the user to sign in as.
               Note that most of the functions in this example require that the user
               have server administrator permissions.
    'password' is the password for the user.
    'site'     is the ID (as a string) of the site on the server to sign in to. The
               default is "", which signs in to the default site.
    Returns the authentication token and the site ID.
    """
    url = server + "/api/{0}/auth/signin".format(VERSION)

    # Builds the request
    xml_request = ET.Element('tsRequest')
    credentials_element = ET.SubElement(xml_request, 'credentials', name=username, password=password)
    ET.SubElement(credentials_element, 'site', contentUrl=site)
    xml_request = ET.tostring(xml_request)

    # Make the request to server
    server_response = requests.post(url, data=xml_request)
    _check_status(server_response, 200)

    # ASCII encode server response to enable displaying to console
    server_response = _encode_for_display(server_response.text)

    # Reads and parses the response
    parsed_response = ET.fromstring(server_response)

    # Gets the auth token and site ID
    token = parsed_response.find('t:credentials', namespaces=xmlns).get('token')
    site_id = parsed_response.find('.//t:site', namespaces=xmlns).get('id')
    user_id = parsed_response.find('.//t:user', namespaces=xmlns).get('id')
    return token, site_id, user_id
move_workbook_sites.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def sign_out(server, auth_token):
    """
    Destroys the active session and invalidates authentication token.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    """
    url = server + "/api/{0}/auth/signout".format(VERSION)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return
move_workbook_sites.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def start_upload_session(server, auth_token, site_id):
    """
    Creates a POST request that initiates a file upload session.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    Returns a session ID that is used by subsequent functions to identify the upload session.
    """
    url = server + "/api/{0}/sites/{1}/fileUploads".format(VERSION, site_id)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 201)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))
    return xml_response.find('t:fileUpload', namespaces=xmlns).get('uploadSessionId')
move_workbook_sites.py 文件源码 项目:rest-api-samples 作者: tableau 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_default_project_id(server, auth_token, site_id):
    """
    Returns the project ID for the 'default' project on the Tableau server.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    """
    page_num, page_size = 1, 100   # Default paginating values

    # Builds the request
    url = server + "/api/{0}/sites/{1}/projects".format(VERSION, site_id)
    paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page_num)
    server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    # Used to determine if more requests are required to find all projects on server
    total_projects = int(xml_response.find('t:pagination', namespaces=xmlns).get('totalAvailable'))
    max_page = int(math.ceil(total_projects / page_size))

    projects = xml_response.findall('.//t:project', namespaces=xmlns)

    # Continue querying if more projects exist on the server
    for page in range(2, max_page + 1):
        paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page)
        server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
        _check_status(server_response, 200)
        xml_response = ET.fromstring(_encode_for_display(server_response.text))
        projects.extend(xml_response.findall('.//t:project', namespaces=xmlns))

    # Look through all projects to find the 'default' one
    for project in projects:
        if project.get('name') == 'default' or project.get('name') == 'Default':
            return project.get('id')
    error = "Project named 'default' was not found in destination site"
    raise LookupError(error)


问题


面经


文章

微信
公众号

扫码关注公众号