python类Credentials()的实例源码

appengine.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def locked_get(self):
        """Retrieve Credential from datastore.

        Returns:
            oauth2client.Credentials
        """
        credentials = None
        if self._cache:
            json = self._cache.get(self._key_name)
            if json:
                credentials = client.Credentials.new_from_json(json)
        if credentials is None:
            entity = self._get_entity()
            if entity is not None:
                credentials = getattr(entity, self._property_name)
                if self._cache:
                    self._cache.set(self._key_name, credentials.to_json())

        if credentials and hasattr(credentials, 'set_store'):
            credentials.set_store(self)
        return credentials
_appengine_ndb.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
test_client.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test__to_json_with_strip(self):
        credentials = client.Credentials()
        credentials.foo = 'bar'
        credentials.baz = 'quux'
        to_strip = ['foo']
        json_payload = credentials._to_json(to_strip)
        # str(bytes) in Python2 and str(unicode) in Python3
        self.assertIsInstance(json_payload, str)
        payload = json.loads(json_payload)
        expected_payload = {
            '_class': client.Credentials.__name__,
            '_module': client.Credentials.__module__,
            'token_expiry': None,
            'baz': credentials.baz,
        }
        self.assertEqual(payload, expected_payload)
test_client.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test__to_json_to_serialize(self):
        credentials = client.Credentials()
        to_serialize = {
            'foo': b'bar',
            'baz': u'quux',
            'st': set(['a', 'b']),
        }
        orig_vals = to_serialize.copy()
        json_payload = credentials._to_json([], to_serialize=to_serialize)
        # str(bytes) in Python2 and str(unicode) in Python3
        self.assertIsInstance(json_payload, str)
        payload = json.loads(json_payload)
        expected_payload = {
            '_class': client.Credentials.__name__,
            '_module': client.Credentials.__module__,
            'token_expiry': None,
        }
        expected_payload.update(to_serialize)
        # Special-case the set.
        expected_payload['st'] = list(expected_payload['st'])
        # Special-case the bytes.
        expected_payload['foo'] = u'bar'
        self.assertEqual(payload, expected_payload)
        # Make sure the method call didn't modify our dictionary.
        self.assertEqual(to_serialize, orig_vals)
appengine.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def locked_get(self):
        """Retrieve Credential from datastore.

        Returns:
            oauth2client.Credentials
        """
        credentials = None
        if self._cache:
            json = self._cache.get(self._key_name)
            if json:
                credentials = client.Credentials.new_from_json(json)
        if credentials is None:
            entity = self._get_entity()
            if entity is not None:
                credentials = getattr(entity, self._property_name)
                if self._cache:
                    self._cache.set(self._key_name, credentials.to_json())

        if credentials and hasattr(credentials, 'set_store'):
            credentials.set_store(self)
        return credentials
_appengine_ndb.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
test_client.py 文件源码 项目:REMAP 作者: REMAPApp 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test__to_json_with_strip(self):
        credentials = client.Credentials()
        credentials.foo = 'bar'
        credentials.baz = 'quux'
        to_strip = ['foo']
        json_payload = credentials._to_json(to_strip)
        # str(bytes) in Python2 and str(unicode) in Python3
        self.assertIsInstance(json_payload, str)
        payload = json.loads(json_payload)
        expected_payload = {
            '_class': client.Credentials.__name__,
            '_module': client.Credentials.__module__,
            'token_expiry': None,
            'baz': credentials.baz,
        }
        self.assertEqual(payload, expected_payload)
test_client.py 文件源码 项目:REMAP 作者: REMAPApp 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test__to_json_to_serialize(self):
        credentials = client.Credentials()
        to_serialize = {
            'foo': b'bar',
            'baz': u'quux',
            'st': set(['a', 'b']),
        }
        orig_vals = to_serialize.copy()
        json_payload = credentials._to_json([], to_serialize=to_serialize)
        # str(bytes) in Python2 and str(unicode) in Python3
        self.assertIsInstance(json_payload, str)
        payload = json.loads(json_payload)
        expected_payload = {
            '_class': client.Credentials.__name__,
            '_module': client.Credentials.__module__,
            'token_expiry': None,
        }
        expected_payload.update(to_serialize)
        # Special-case the set.
        expected_payload['st'] = list(expected_payload['st'])
        # Special-case the bytes.
        expected_payload['foo'] = u'bar'
        self.assertEqual(payload, expected_payload)
        # Make sure the method call didn't modify our dictionary.
        self.assertEqual(to_serialize, orig_vals)
appengine.py 文件源码 项目:REMAP 作者: REMAPApp 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def locked_get(self):
        """Retrieve Credential from datastore.

        Returns:
            oauth2client.Credentials
        """
        credentials = None
        if self._cache:
            json = self._cache.get(self._key_name)
            if json:
                credentials = client.Credentials.new_from_json(json)
        if credentials is None:
            entity = self._get_entity()
            if entity is not None:
                credentials = getattr(entity, self._property_name)
                if self._cache:
                    self._cache.set(self._key_name, credentials.to_json())

        if credentials and hasattr(credentials, 'set_store'):
            credentials.set_store(self)
        return credentials
_appengine_ndb.py 文件源码 项目:REMAP 作者: REMAPApp 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
_appengine_ndb.py 文件源码 项目:ecodash 作者: Servir-Mekong 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
_appengine_ndb.py 文件源码 项目:SurfaceWaterTool 作者: Servir-Mekong 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
_appengine_ndb.py 文件源码 项目:metrics 作者: Jeremy-Friedman 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
_appengine_ndb.py 文件源码 项目:metrics 作者: Jeremy-Friedman 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
_appengine_ndb.py 文件源码 项目:alfredToday 作者: jeeftor 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
appengine.py 文件源码 项目:Webradio_v2 作者: Acer54 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def locked_get(self):
        """Retrieve Credential from datastore.

        Returns:
            oauth2client.Credentials
        """
        credentials = None
        if self._cache:
            json = self._cache.get(self._key_name)
            if json:
                credentials = client.Credentials.new_from_json(json)
        if credentials is None:
            entity = self._get_entity()
            if entity is not None:
                credentials = getattr(entity, self._property_name)
                if self._cache:
                    self._cache.set(self._key_name, credentials.to_json())

        if credentials and hasattr(credentials, 'set_store'):
            credentials.set_store(self)
        return credentials
_appengine_ndb.py 文件源码 项目:Webradio_v2 作者: Acer54 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
appengine.py 文件源码 项目:GAMADV-X 作者: taers232c 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def locked_get(self):
        """Retrieve Credential from datastore.

        Returns:
            oauth2client.Credentials
        """
        credentials = None
        if self._cache:
            json = self._cache.get(self._key_name)
            if json:
                credentials = client.Credentials.new_from_json(json)
        if credentials is None:
            entity = self._get_entity()
            if entity is not None:
                credentials = getattr(entity, self._property_name)
                if self._cache:
                    self._cache.set(self._key_name, credentials.to_json())

        if credentials and hasattr(credentials, 'set_store'):
            credentials.set_store(self)
        return credentials
_appengine_ndb.py 文件源码 项目:GAMADV-X 作者: taers232c 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _from_base_type(self, value):
        """Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        """
        if not value:
            return None
        try:
            # Uses the from_json method of the implied class of value
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
appengine.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def make_value_from_datastore(self, value):
        logger.info("make: Got type " + str(type(value)))
        if value is None:
            return None
        if len(value) == 0:
            return None
        try:
            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials
appengine.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def validate(self, value):
        value = super(CredentialsProperty, self).validate(value)
        logger.info("validate: Got type " + str(type(value)))
        if value is not None and not isinstance(value, client.Credentials):
            raise db.BadValueError(
                'Property {0} must be convertible '
                'to a Credentials instance ({1})'.format(self.name, value))
        return value
appengine.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def locked_put(self, credentials):
        """Write a Credentials to the datastore.

        Args:
            credentials: Credentials, the credentials to store.
        """
        entity = self._model.get_or_insert(self._key_name)
        setattr(entity, self._property_name, credentials)
        entity.put()
        if self._cache:
            self._cache.set(self._key_name, credentials.to_json())
appengine.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_credentials(self):
        """A thread local Credentials object.

        Returns:
            A client.Credentials object, or None if credentials hasn't been set
            in this thread yet, which may happen when calling has_credentials
            inside oauth_aware.
        """
        return getattr(self._tls, 'credentials', None)
_appengine_ndb.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _validate(self, value):
        """Validates a value as a proper credentials object.

        Args:
            value: A value to be set on the property.

        Raises:
            TypeError if the value is not an instance of Credentials.
        """
        _LOGGER.info('validate: Got type %s', type(value))
        if value is not None and not isinstance(value, client.Credentials):
            raise TypeError(
                'Property {0} must be convertible to a credentials '
                'instance; received: {1}.'.format(self._name, value))
test_django_models.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setUp(self):
        self.fake_model = tests_models.CredentialsModel()
        self.fake_model_field = self.fake_model._meta.get_field('credentials')
        self.field = models.CredentialsField(null=True)
        self.credentials = client.Credentials()
        self.pickle_str = _helpers._from_bytes(
            base64.b64encode(pickle.dumps(self.credentials)))
        self.jsonpickle_str = _helpers._from_bytes(
            base64.b64encode(jsonpickle.encode(self.credentials).encode()))
test_django_models.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_field_unpickled(self):
        self.assertIsInstance(
            self.field.to_python(self.pickle_str), client.Credentials)
test_django_models.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_field_jsonunpickled(self):
        self.assertIsInstance(
            self.field.to_python(self.jsonpickle_str), client.Credentials)
test_django_models.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_field_already_unpickled(self):
        self.assertIsInstance(
            self.field.to_python(self.credentials), client.Credentials)
test_django_models.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_from_db_value(self):
        value = self.field.from_db_value(
            self.pickle_str, None, None, None)
        self.assertIsInstance(value, client.Credentials)
test__appengine_ndb.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_validate_success(self, mock_logger):
        creds_prop = TestNDBModel.creds
        creds_val = client.Credentials()
        creds_prop._validate(creds_val)
        mock_logger.info.assert_called_once_with('validate: Got type %s',
                                                 type(creds_val))


问题


面经


文章

微信
公众号

扫码关注公众号