Exemple #1
0
    def __init__(self,
                 app_id,
                 component_appid=None,
                 component_access_token=None,
                 redirect_uri=None,
                 scope='snsapi_base',
                 state='',
                 component=None):
        """

        :param app_id: 微信公众号 app_id
        :param component: WeChatComponent
        """
        self._http = requests.Session()
        self.app_id = app_id
        self.component = component
        if self.component is None:
            warnings.warn(
                'cannot found `component` param of `ComponentOAuth` `__init__` method,'
                'Use `WeChatComponent.get_component_oauth` instead',
                DeprecationWarning,
                stacklevel=2)

            self.component = ObjectDict({
                'component_appid': component_appid,
                'access_token': component_access_token
            })
        if redirect_uri is not None:
            warnings.warn(
                'found `redirect_uri` param of `ComponentOAuth` `__init__` method,'
                'Use `ComponentOAuth.get_authorize_url` instead',
                DeprecationWarning,
                stacklevel=2)
            self.authorize_url = self.get_authorize_url(
                redirect_uri, scope, state)
Exemple #2
0
 def __get__(self, instance, instance_type=None):
     if instance is not None:
         value = instance._data.get(self.attr_name)
         if value is None:
             value = copy.deepcopy(self.field.default)
             instance._data[self.attr_name] = value
         if isinstance(value, dict):
             value = ObjectDict(value)
         if value and not isinstance(value, (dict, list, tuple)) and callable(self.field.converter):
             value = self.field.converter(value)
         return value
     return self.field
Exemple #3
0
 def test_object_dict(self):
     obj = ObjectDict()
     self.assertTrue(obj.xxx is None)
     obj.xxx = 1
     self.assertEqual(1, obj.xxx)