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


Python User.exists方法代码示例

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


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

示例1: post

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import exists [as 别名]
    def post(self):
        try:
            body = json.loads(self.request.body)
            name = body['name']
            pw = body['pw']
            target_url = body.get('next')
        except (KeyError, ValueError, TypeError) as e:
            self.application.log.info('User creation request malformed, error={}, url={}, body={}'.format(e, self.request.uri, self.request.body))
            self.send_error(httplib.BAD_REQUEST)
            return

        exists = yield User.exists(name)
        if exists:
            self.send_error(httplib.CONFLICT)
            return

        user = User(name, pw)
        yield user.save()
        self.set_current_user(user.guid)
        if target_url:
            self.redirect(target_url)
        else:
            self.set_header('Location', self.reverse_url(UserMaintenanceHandler.__name__, user.guid))
            self.write(self.application.user_representation(user))
            self.set_status(httplib.CREATED)
开发者ID:lchapple,项目名称:minterest,代码行数:27,代码来源:api.py

示例2: post

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import exists [as 别名]
    def post(self):
        """ Handle the sign-up request. """
        email = self.request.get("email")
        pwd = self.request.get("password")
        verify = self.request.get("verify")

        # there is verification on browser by JS, but validating again won't hurt
        if not self._validate(email, pwd, verify):
            logging.error("How could the invalid input pass the JS test? @auth.SignUpHandler.post()")
            self.redirect("/signup")
            return

        if User.exists(email):
            # telling user that the email has been taken
            self._error("Email registered by others")
        else:
            hashed = encrypt.hash_pwd(email, pwd)
            u = User(email=email,
                     pwd_hashed=hashed,
                     parent=utils.get_key_public('User'))
            u.put()
            self._init_user(u)

            self._set_id_cookie(email)
            self.redirect('/me')
开发者ID:AndriyLin,项目名称:Books,代码行数:27,代码来源:__init__.py

示例3: Twitter

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import exists [as 别名]
class Twitter(Network):
  def __init__(self):
    Network.__init__(self, "twitter")
    self.user = User(network=self.name)
    self.auth = self.Oauth()
    self.api = None
    
  def get_api(self, stream_api_callback):
    if self.user.exists():
      logp("User '%s' found for Twitter" % self.user.screen_name)
      logp("Getting Twitter API")
      self.TwitterStreamAPI(self.user.access_key, self.user.access_secret, stream_api_callback)
      self.api = self.TwitterAPI(self.user.access_key, self.user.access_secret)
      return True
    else:
      logm("A problem has occurred while getting access to Twitter API")
      return False
      
  class Oauth():
    def __init__(self):
      self.request_token_url  = 'https://twitter.com/oauth/request_token'
      self.access_token_url   = 'https://twitter.com/oauth/access_token'
      self.authorize_url      = 'https://twitter.com/oauth/authorize'

      consumer_key, consumer_secret = read_consumer_key_and_secret("twitter")
      self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
      self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()

      self.request_token = None
      self.access_token = None
      
    def get_authorization_url(self):
      self.request_token = self.get_unauthorized_request_token()
      oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
                                                                 token = self.request_token,
                                                                 http_url = self.authorize_url)
      oauth_request.sign_request(self.signature_method, self.consumer, self.request_token)
      return oauth_request.to_url()

    def get_unauthorized_request_token(self):
      oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, http_url = self.request_token_url)
      oauth_request.sign_request(self.signature_method, self.consumer, None)
      url = oauth_request.to_url()
      response = get(url)
      token = oauth.OAuthToken.from_string(response)
      return token

    # Exchange request token for access token
    def get_access_token_and_secret(self, pin):
      oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
                                                                 http_url = self.access_token_url,
                                                                 verifier = pin,
                                                                 token = self.request_token)
      oauth_request.sign_request(self.signature_method, self.consumer, self.request_token)
      url = oauth_request.to_url()
      response = get(url)
      self.access_token = oauth.OAuthToken.from_string(response)                      # create both .key and .secret attributes
      return self.access_token.key, self.access_token.secret
      
  class API():
    def __init__(self, access_key, access_secret):
      self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
      consumer_key, consumer_secret = read_consumer_key_and_secret()
      self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
      self.access_token = oauth.OAuthToken(access_key, access_secret)

  class TwitterStreamAPI(API):
    def __init__(self, access_key, access_secret, callback):
      Twitter.API.__init__(self, access_key, access_secret)

      self.user_stream_url = "https://userstream.twitter.com/1.1/user.json"
      self.callback = callback                                                        # called as soon as a new entry on the stream appears
      thread = threading.Thread(target=self.tweet_streaming)                          # keep checking for new entries on the stream
      thread.start()                                                                  # run, forrest run

    def tweet_streaming(self):
      oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
                                                                 token = self.access_token,
                                                                 http_url = self.user_stream_url)
      oauth_request.sign_request(self.signature_method, self.consumer, self.access_token)

      url = oauth_request.to_url()
      try:
        req = urllib_request.urlopen(url)
      except urllib_error.URLError:
        return  # we should give the information back to the applet...
      
      buffer = ''
      while True:
        chunk = req.read(1)                                             # read character per character from the connection ...
        if not chunk:
          break

        buffer += chunk
        tweets = buffer.split("\n",1)                                   # ... until find the end of a tweet marked with a '\n'
        if len(tweets) > 1:
          content = tweets[0]
          if "text" in content:
            try:
              content = simplejson.loads(content)
#.........这里部分代码省略.........
开发者ID:Awkee,项目名称:cairo-dock-plug-ins-extras,代码行数:103,代码来源:twitter.py

示例4: Identica

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import exists [as 别名]
class Identica(Network):
  def __init__(self):
    Network.__init__(self, "identica")
    self.user = User(network=self.name)
    self.auth = self.Oauth()
    self.api = None
    
  def get_api(self):
    if self.user.exists():
      logp("User '%s' found for Identi.ca" % self.user.screen_name)
      logp("Getting Identi.ca API")
      self.api = self.IdenticaAPI(self.user.access_key, self.user.access_secret, self.user.screen_name)
      return True
    else:
      logm("A problem has occurred while getting access to Identi.ca API")
      return False
    
  class Oauth:
    def __init__(self):
      self.request_token_url  = 'https://identi.ca/oauth/request_token'
      self.access_token_url = 'https://identi.ca/oauth/access_token'
      self.authorize_url = 'https://identi.ca/oauth/authorize'

      consumer_key, consumer_secret = read_consumer_key_and_secret("identica")
      self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
      self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
      
    def get_authorization_url(self):
      self.request_token = self.get_unauthorized_request_token()
      oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, token = self.request_token, http_url = self.authorize_url)
      oauth_request.sign_request(self.signature_method, self.consumer, self.request_token)
      return oauth_request.to_url()

    def get_unauthorized_request_token(self):
      oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, http_url = self.request_token_url, callback="oob")
      oauth_request.sign_request(self.signature_method, self.consumer, None)
      url = oauth_request.to_url()
      response = get(url)
      token = oauth.OAuthToken.from_string(response)
      return token
      
    # Exchange request token for access token
    def get_access_token_and_secret(self, verifier):
      oauth_request = oauth.OAuthRequest.from_consumer_and_token(oauth_consumer=self.consumer, 
                                                                 token = self.request_token,
                                                                 callback="oob",
                                                                 verifier = str(verifier),
                                                                 http_url = self.access_token_url)
      oauth_request.sign_request(self.signature_method, self.consumer, self.request_token)
      url = oauth_request.to_url()
      response = get(url)
      access_token = oauth.OAuthToken.from_string(response)
      return access_token.key, access_token.secret
      
  class IdenticaAPI():
    def __init__(self, access_key, access_secret, user_screen_name):
      self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
      consumer_key, consumer_secret = read_consumer_key_and_secret("identica")
      self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
      self.access_token = oauth.OAuthToken(access_key, access_secret)
      
      self.feed_url = "https://identi.ca/api/user/%s/feed" % user_screen_name

    def dispatch(self, url, mode, parameters={}):
      oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
                                                               token = self.access_token,
                                                               http_url = url,
                                                               parameters = parameters,
                                                               http_method = mode)
      oauth_request.sign_request(self.signature_method, self.consumer, self.access_token)
      if mode == "GET":
        url = oauth_request.to_url()
        response = get(url) 
        return loads(response)
      elif mode == "POST":
        headers = {'Content-Type': 'application/json'}
        post_to_identica(oauth_request.to_url(), dumps(parameters), headers)

    def tweet(self, message):                                                           # popularly "send a tweet"
      try:
        note = {"verb": "post", "object": {"content": message, "objectType": "note"}}
        self.dispatch(self.feed_url, "POST", note)
      except HTTPError as err: # urllib2
        if err.code == 401:
          return False
      else:
        return True
      
    def home_timeline(self):
      return "Not implemented"
开发者ID:Awkee,项目名称:cairo-dock-plug-ins-extras,代码行数:92,代码来源:identica.py


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