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


Python HydroShare.getUserInfo方法代码示例

本文整理汇总了Python中hs_restclient.HydroShare.getUserInfo方法的典型用法代码示例。如果您正苦于以下问题:Python HydroShare.getUserInfo方法的具体用法?Python HydroShare.getUserInfo怎么用?Python HydroShare.getUserInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hs_restclient.HydroShare的用法示例。


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

示例1: test_get_user_info

# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getUserInfo [as 别名]
    def test_get_user_info(self):
        hs = HydroShare()
        user_info = hs.getUserInfo()

        self.assertEquals(user_info['username'], 'username')
        self.assertEquals(user_info['first_name'], 'First')
        self.assertEquals(user_info['last_name'], 'Last')
        self.assertEquals(user_info['email'], '[email protected]')
开发者ID:mtpain,项目名称:hs_restclient,代码行数:10,代码来源:test_hs_restclient.py

示例2: hydroshare

# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getUserInfo [as 别名]
class hydroshare():
    def __init__(self, username=None, password=None, cache=True):
        self.hs = None
        self.content = {}

        # connect to hydroshare using OAUTH2
        authfile = os.path.expanduser("~/.hs_auth")
        if os.path.exists(authfile):
            with open(authfile, 'rb') as f:
                token, cid = pickle.load(f)
            auth = HydroShareAuthOAuth2(cid, '', token=token)
        else:
            # connect to hydroshare using Basic Authentication
            self.cache = cache
            if cache:
                utilities.load_environment(os.path.join(
                                           os.environ['NOTEBOOK_HOME'],
                                           '.env'))

            self.auth_path = os.environ.get('NOTEBOOK_HOME',
                                            '/home/jovyan/.auth')

            uname = username
            if uname is None:
                if 'HS_USR_NAME' in os.environ.keys():
                    uname = os.environ['HS_USR_NAME']

            if password is None:
                # get a secure connection to hydroshare
                auth = self.getSecureConnection(uname)
            else:
                print('WARNING: THIS IS NOT A SECURE METHOD OF CONNECTING TO '
                      'HYDROSHARE...AVOID TYPING CREDENTIALS AS PLAIN TEXT')
                auth = HydroShareAuthBasic(username=uname, password=password)

        try:
            self.hs = HydroShare(auth=auth)
            self.hs.getUserInfo()
            print('Successfully established a connection with HydroShare')

        except HydroShareHTTPException as e:
            print('Failed to establish a connection with HydroShare.\n  '
                  'Please check that you provided the correct credentials.\n'
                  '%s' % e)
            # remove the cached authentication
            if os.path.exists(self.auth_path):
                os.remove(self.auth_path)
            return None

        # set the HS resource download directory
        download_dir = os.environ.get('JUPYTER_DOWNLOADS', 'Downloads')
        if not os.path.isdir(download_dir):
            os.makedirs(download_dir)
        self.download_dir = download_dir

    def _addContentToExistingResource(self, resid, content_files):

        for f in content_files:
            self.hs.addResourceFile(resid, f)

    def getSecureConnection(self, username=None):
        """Establishes a secure connection with hydroshare.

        args:
        -- email: email address associated with hydroshare

        returns:
        -- hydroshare api connection
        """

        if not os.path.exists(self.auth_path):
            print('\nThe hs_utils library requires a secure connection to '
                  'your HydroShare account.')
            if username is None:
                username = input('Please enter your HydroShare username: ') \
                        .strip()
            p = getpass.getpass('Enter the HydroShare password for user '
                                '\'%s\': ' % username)
            auth = HydroShareAuthBasic(username=username, password=p)

            if self.cache:
                with open(self.auth_path, 'wb') as f:
                    pickle.dump(auth, f, protocol=2)

        else:

            with open(self.auth_path, 'rb') as f:
                auth = pickle.load(f)

        return auth

    def getResourceMetadata(self, resid):
        """Gets metadata for a specified resource.

        args:
        -- resid: hydroshare resource id

        returns:
        -- resource metadata object
        """
#.........这里部分代码省略.........
开发者ID:hydroshare,项目名称:hydroshare-jupyterhub,代码行数:103,代码来源:hydroshare.py


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