获取话题下的精华答案.

        :return: 话题下的精华答案，返回生成器.
        :rtype: Answer.Iterable
170134
def top_answers(self):
        
        from .question import Question
        from .answer import Answer
        from .author import Author, ANONYMOUS

        top_answers_url = Topic_Top_Answers_Url.format(self.id)
        params = {'page': 1}
        while True:
            # 超出50页直接返回
            if params['page'] > 50:
                return
            res = self._session.get(top_answers_url, params=params)
            params['page'] += 1
            soup = BeautifulSoup(res.content)
            # 不够50页，来到错误页面 返回
            if soup.find('div', class_='error') is not None:
                return
            questions = soup.find_all('a', class_='question_link')
            answers = soup.find_all('a', class_='answer-date-link')
            authors = soup.find_all('div', class_='zm-item-answer-author-info')
            upvotes = soup.find_all('a', class_='zm-item-vote-count')
            for ans, up, q, au in zip(answers, upvotes, questions, authors):
                answer_url = Zhihu_URL + ans['href']
                question_url = Zhihu_URL + q['href']
                question_title = q.text.strip()
                upvote = up.text
                if upvote.isdigit():
                    upvote = int(upvote)
                else:
                    upvote = None
                question = Question(question_url, question_title,
                                    session=self._session)
                if au.a is None:
                    author = ANONYMOUS
                else:
                    author_url = Zhihu_URL + au.a['href']
                    author_name = au.a.text
                    author_motto = au.strong['title'] if au.strong else ''
                    author = Author(author_url, author_name, author_motto,
                                    session=self._session)
                yield Answer(answer_url, question, author, upvote,
                             session=self._session)
1357986
def top_i_answers(self, i):
        
        for j, a in enumerate(self.answers):
            if j <= i - 1:
                yield a
            else:
                return
105838
def answers(self):
        
        from .question import Question
        from .answer import Answer
        from .author import Author, ANONYMOUS

        newest_url = Topic_Newest_Url.format(self.id)
        params = {'start': 0, '_xsrf': self.xsrf}
        res = self._session.get(newest_url)
        soup = BeautifulSoup(res.content)
        while True:
            divs = soup.find_all('div', class_='folding')
            # 如果话题下无答案，则直接返回
            if len(divs) == 0:
                return
            last_score = divs[-1]['data-score']
            for div in divs:
                q = div.find('a', class_="question_link")
                question_url = Zhihu_URL + q['href']
                question_title = q.text.strip()
                question = Question(question_url, question_title,
                                    session=self._session)

                ans = div.find('a', class_='answer-date-link')
                answer_url = Zhihu_URL + ans['href']

                upvote = div.find('a', class_='zm-item-vote-count').text
                if upvote.isdigit():
                    upvote = int(upvote)
                else:
                    upvote = None

                au = div.find('div', class_='zm-item-answer-author-info')
                if au.a is None:
                    author = ANONYMOUS
                else:
                    author_url = Zhihu_URL + au.a['href']
                    author_name = au.a.text
                    author_motto = au.strong['title'] if au.strong else ''
                    author = Author(author_url, author_name, author_motto,
                                    session=self._session)
                yield Answer(answer_url, question, author, upvote,
                             session=self._session)

            params['offset'] = last_score
            res = self._session.post(newest_url, data=params)
            gotten_feed_num = res.json()['msg'][0]
            # 如果得到内容数量为0则返回
            if gotten_feed_num == 0:
                return
            soup = BeautifulSoup(res.json()['msg'][1])
570582
def answer_num(self):
        
        answer_num_block = self.soup.find('h3', id='zh-question-answer-num')
        # 当0人回答或1回答时，都会找不到 answer_num_block，
        # 通过找答案的赞同数block来判断到底有没有答案。
        # （感谢知乎用户 段晓晨 提出此问题）
        if answer_num_block is None:
            if self.soup.find('span', class_='count') is not None:
                return 1
            else:
                return 0
        return int(answer_num_block['data-num'])
1105345
def get_all(self) -> Iterable[Tuple[str, str]]:
        
        for name, values in self._as_list.items():
            for value in values:
                yield (name, value)
1183929
def get_response(self):
        
        res = IODWriteMultipleRes()
        for field in ["seqNum", "ARUUID", "API", "slotNumber",
                      "subslotNumber", "index"]:
            res.setfieldval(field, self.getfieldval(field))

        # append all block response
        res_blocks = []
        for block in self.getfieldval("blocks"):
            res_blocks.append(block.get_response())
        res.setfieldval("blocks", res_blocks)
        return res
761595
def choices(self):
        
        if isinstance(self.validator, list):
            return self.validator[0].print_choices()
        return self.validator.print_choices()
1014121
def _get_answer(self, part):
        
        answer_fname = getattr(self, "answer_{}_fname".format(part))
        if os.path.isfile(answer_fname):
            with open(answer_fname) as f:
                return f.read().strip()
        # scrape puzzle page for any previously solved answers
        response = requests.get(self.url, cookies=self._cookies, headers=self._headers)
        response.raise_for_status()
        soup = bs4.BeautifulSoup(response.text, "html.parser")
        if not self._title:
            # may as well save this while we're here
            self._save_title(soup=soup)
        hit = "Your puzzle answer was"
        paras = [p for p in soup.find_all("p") if p.text.startswith(hit)]
        if paras:
            parta_correct_answer = paras[0].code.text
            self._save_correct_answer(value=parta_correct_answer, part="a")
            if len(paras) > 1:
                _p1, p2 = paras
                partb_correct_answer = p2.code.text
                self._save_correct_answer(value=partb_correct_answer, part="b")
        if os.path.isfile(answer_fname):
            with open(answer_fname) as f:
                return f.read().strip()
        msg = "Answer {}-{}{} is not available".format(self.year, self.day, part)
        raise PuzzleUnsolvedError(msg)
159684
def query( self ):
        
        if ( self.childCount() ):
            q = Q()
            for i in range(self.childCount()):
                q &= self.child(i).query()
            return q
        else:
            op_name = projex.text.classname(self.text(2))
            q = Q(nativestring(self.text(1)))
            q.setOperatorType(Q.Op[op_name])
            q.setValueString(nativestring(self.text(3)))
            return q
1220984
def ask_questions(self):
        
        out_config = {}

        for key in c.CONFIG_QUESTIONS:
            section = key[1]
            print
            for question in section:
                answer = utils.ask(question[1], question[2])
                out_config["{0}_{1}".format(key[0], question[0])] = answer

        for key in c.CONFIG_MULTIPLE_CHOICE_QUESTIONS:
            section = key[1]
            print
            # keep going until we get what we want
            while True:
                input = utils.ask(section[1], "")
                if (input.isdigit() and
                        int(input) > 0 and
                        int(input) <= section[0]):
                    answer = input

                    break
                print

            # store the answer as 1 less than it is, we're dealing with
            # a list to select the number which is 0 indexed
            answer = int(input) - 1

            if key[0] == "license":
                out_config["license_type"] = c.LICENSE_TYPES[answer][0]
                out_config["license_url"] = c.LICENSE_TYPES[answer][1]

        # merge in defaults without asking questions
        merged_config = dict(c.CONFIG_DEFAULTS.items() + out_config.items())

        return merged_config
1142693
def get_printable(iterable):
    
    if iterable:
        return ''.join(i for i in iterable if i in string.printable)
    return ''
315981
def next(self):
        
        if self.index < self.length:
            index = self.index
            self.index += 1
            return self.data[index]
        else:
            raise StopIteration()
973191
def get_question(self):
        
        question_map = dict(self._my_map['question'])
        question_map['learningObjectiveIds'] = self._my_map['learningObjectiveIds']
        return Question(osid_object_map=question_map,
                        runtime=self._runtime,
                        proxy=self._proxy)
1040991
def _next(self):
        
        c = self._get()
        if c == '/':
            p = self._peek()
            if p == '/':
                c = self._get()
                while c > '\n':
                    c = self._get()
                return c
            if p == '*':
                c = self._get()
                while 1:
                    c = self._get()
                    if c == '*':
                        if self._peek() == '/':
                            self._get()
                            return ' '
                    if c == '\000':
                        raise UnterminatedComment()

        return c
1368254
def level(self) -> str:
        
        levels = self._data['level']
        return self.random.choice(levels)
1273550
def loop(self):
        
        self.eat(TokenTypes.FOR_LOOP)
        init = NoOp()
        if self.cur_token.type != TokenTypes.SEMI_COLON:
            init = self.assign_statement()
        else:
            self.eat(TokenTypes.SEMI_COLON)

        ctrl = NoOp()
        if self.cur_token.type != TokenTypes.SEMI_COLON:
            ctrl = self.expression()
        self.eat(TokenTypes.SEMI_COLON)

        inc = NoOp()
        if self.cur_token.type != TokenTypes.LBRACE:
            inc = self.assign_statement()

        block = self.block()
        return ForLoop(init, ctrl, inc, block)
540797
def values(self):
        
        def iter_values():
            val = self._element.val
            if val is None:
                return
            for idx in range(val.ptCount_val):
                yield val.pt_v(idx)

        return tuple(iter_values())