예제 #1
0
    def process_data(self):
        self.data['api_paste_format'] = self.data['syntax'] or 'text'
        self.data['api_paste_code'] = self.data['content']
        self.data['api_paste_name'] = self.data['title']
        if self.data['poster']:
            self.data['api_paste_name'] += ' ' if self.data['title'] else ''
            self.data['api_paste_name'] += 'by %s' % (self.data['poster'])
        self.data['api_option'] = 'paste'
        self.data['api_paste_private'] = 1 if self.data['private'] else 0
        # Expiry date according to `hold` flag and `api_paste_expire_date`
        # config
        if self.data['hold']:
            self.data['api_paste_expire_date'] = 'N'
        else:
            self.data['api_paste_expire_date'] = get_config(
                'pastebin', 'api_paste_expire_date', False, '1M')

        # api_dev_key supplied as an option?
        if "api_dev_key" not in self.data or self.data['api_dev_key'] is None:
            logging.debug("Reading api_dev_key from config")
            self.data['api_dev_key'] = get_config('pastebin',
                                                  'api_dev_key',
                                                  allow_empty_option=False)

        assert self.data['api_dev_key'] is not None and len(
            self.data['api_dev_key']) > 0
        logging.debug("Using %s as api_dev_key" % self.data['api_dev_key'])
        #Get the pastebin user key
        self.data['api_user_key'] = self.get_api_user_key(
            self.data['api_dev_key'])
        return self.data
예제 #2
0
파일: services.py 프로젝트: crodjer/paster
    def process_data(self):
        self.data['api_paste_format'] = self.data['syntax'] or 'text'
        self.data['api_paste_code'] = self.data['content']
        self.data['api_paste_name'] = self.data['title']
        if self.data['poster']:
            self.data['api_paste_name'] += ' ' if self.data['title'] else ''
            self.data['api_paste_name'] += 'by %s' %(self.data['poster'])
        self.data['api_option'] = 'paste'
        self.data['api_paste_private'] = 1 if self.data['private'] else 0
        # Expiry date according to `hold` flag and `api_paste_expire_date`
        # config
        if self.data['hold']:
            self.data['api_paste_expire_date'] = 'N'
        else:
            self.data['api_paste_expire_date'] = get_config('pastebin',
                                                            'api_paste_expire_date',
                                                            False,
                                                            '1M')

        # api_dev_key supplied as an option?
        if "api_dev_key" not in self.data or self.data['api_dev_key'] is None:
            logging.debug("Reading api_dev_key from config")
            self.data['api_dev_key'] = get_config('pastebin', 'api_dev_key', allow_empty_option=False)

        assert self.data['api_dev_key'] is not None and len(self.data['api_dev_key']) > 0
        logging.debug("Using %s as api_dev_key" % self.data['api_dev_key'])
        #Get the pastebin user key
        self.data['api_user_key'] = self.get_api_user_key(self.data['api_dev_key'])
        return self.data
예제 #3
0
 def get_api_user_key(self, api_dev_key, username=None, password=None):
     '''
     Get api user key to enable posts from user accounts if username
     and password available.
     Not getting an api_user_key means that the posts will be "guest" posts
     '''
     username = username or get_config('pastebin', 'api_user_name')
     password = password or get_config('pastebin', 'api_user_password')
     if username and password:
         data = {
             'api_user_name': username,
             'api_user_password': password,
             'api_dev_key': api_dev_key,
         }
         urlencoded_data = urllib.urlencode(data)
         req = urllib2.Request('http://pastebin.com/api/api_login.php',
                               urlencoded_data)
         response = urllib2.urlopen(req)
         user_key = response.read()
         logging.debug("User key: %s" % user_key)
         return user_key
     else:
         logging.info("Pastebin: not using any user key")
         return ""
예제 #4
0
파일: services.py 프로젝트: crodjer/paster
 def get_api_user_key(self, api_dev_key, username=None, password=None):
     '''
     Get api user key to enable posts from user accounts if username
     and password available.
     Not getting an api_user_key means that the posts will be "guest" posts
     '''
     username = username or get_config('pastebin', 'api_user_name')
     password = password or get_config('pastebin', 'api_user_password')
     if username and password:
         data = {
             'api_user_name': username,
             'api_user_password': password,
             'api_dev_key': api_dev_key,
         }
         urlencoded_data = urllib.urlencode(data)
         req = urllib2.Request('http://pastebin.com/api/api_login.php',
                               urlencoded_data)
         response = urllib2.urlopen(req)
         user_key = response.read()
         logging.debug("User key: %s" % user_key)
         return user_key
     else:
         logging.info("Pastebin: not using any user key")
         return ""