python类next()的实例源码

cmd2.py 文件源码 项目:cmd2 作者: python-cmd2 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def parsed(self, raw):
        """ This function is where the actual parsing of each line occurs.

        :param raw: str - the line of text as it was entered
        :return: ParsedString - custom subclass of str with extra attributes
        """
        if isinstance(raw, ParsedString):
            p = raw
        else:
            # preparse is an overridable hook; default makes no changes
            s = self.preparse(raw)
            s = self.input_source_parser.transformString(s.lstrip())
            s = self.commentGrammars.transformString(s)
            for (shortcut, expansion) in self.shortcuts:
                if s.lower().startswith(shortcut):
                    s = s.replace(shortcut, expansion + ' ', 1)
                    break
            try:
                result = self.main_parser.parseString(s)
            except pyparsing.ParseException:
                # If we have a parsing failure, treat it is an empty command and move to next prompt
                result = self.main_parser.parseString('')
            result['raw'] = raw
            result['command'] = result.multilineCommand or result.command
            result = self.postparse(result)
            p = ParsedString(result.args)
            p.parsed = result
            p.parser = self.parsed
        return p
cmd2.py 文件源码 项目:cmd2 作者: python-cmd2 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _transform_transcript_expected(self, s):
        """parse the string with slashed regexes into a valid regex"""
        regex = ''
        start = 0

        while True:
            (regex, first_slash_pos, start) = self._escaped_find(regex, s, start, False)
            if first_slash_pos == -1:
                # no more slashes, add the rest of the string and bail
                regex += re.escape(s[start:])
                break
            else:
                # there is a slash, add everything we have found so far
                # add stuff before the first slash as plain text
                regex += re.escape(s[start:first_slash_pos])
                start = first_slash_pos+1
                # and go find the next one
                (regex, second_slash_pos, start) = self._escaped_find(regex, s, start, True)
                if second_slash_pos > 0:
                    # add everything between the slashes (but not the slashes)
                    # as a regular expression
                    regex += s[start:second_slash_pos]
                    # and change where we start looking for slashed on the
                    # turn through the loop
                    start = second_slash_pos + 1
                else:
                    # No closing slash, we have to add the first slash,
                    # and the rest of the text
                    regex += re.escape(s[start-1:])
                    break
        return regex
fields.py 文件源码 项目:django-spectator 作者: philgyford 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create_slug(self, model_instance, add):
        # get fields to populate from and slug field to set
        if not isinstance(self._populate_from, (list, tuple)):
            self._populate_from = (self._populate_from, )
        slug_field = model_instance._meta.get_field(self.attname)

        if add or self.overwrite:
            # slugify the original field content and set next step to 2
            slug_for_field = lambda lookup_value: self.slugify_func(self.get_slug_fields(model_instance, lookup_value))
            slug = self.separator.join(map(slug_for_field, self._populate_from))
            start = 2
        else:
            # get slug from the current model instance
            slug = getattr(model_instance, self.attname)
            # model_instance is being modified, and overwrite is False,
            # so instead of doing anything, just return the current slug
            return slug

        # strip slug depending on max_length attribute of the slug field
        # and clean-up
        self.slug_len = slug_field.max_length
        if self.slug_len:
            slug = slug[:self.slug_len]
        slug = self._slug_strip(slug)
        original_slug = slug

        if self.allow_duplicates:
            setattr(model_instance, self.attname, slug)
            return slug

        return super(AutoSlugField, self).find_unique(
            model_instance, slug_field, self.slug_generator(original_slug, start))
base_manager.py 文件源码 项目:RealtimePythonChat 作者: quangtqag 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _generate_ack_id(self, sid, namespace, callback):
        """Generate a unique identifier for an ACK packet."""
        namespace = namespace or '/'
        if sid not in self.callbacks:
            self.callbacks[sid] = {}
        if namespace not in self.callbacks[sid]:
            self.callbacks[sid][namespace] = {0: itertools.count(1)}
        id = six.next(self.callbacks[sid][namespace][0])
        self.callbacks[sid][namespace][id] = callback
        return id
pnh.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def monitor(self, id, message, apikey=''):
        """
        This component is optional and therefore the API will only work if it is installed
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'pnh/action/monitor/', {'id': id, 'message': message, 'apikey': apikey})))
pnh.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def oracle(self, id, apikey=''):
        """
        This component is optional and therefore the API will only work if it is installed
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'pnh/action/oracle/', {'id': id, 'apikey': apikey})))
pnh.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def start_monitoring(self, url, apikey=''):
        """
        This component is optional and therefore the API will only work if it is installed
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'pnh/action/startMonitoring/', {'url': url, 'apikey': apikey})))
pnh.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def stop_monitoring(self, id, apikey=''):
        """
        This component is optional and therefore the API will only work if it is installed
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'pnh/action/stopMonitoring/', {'id': id, 'apikey': apikey})))
script.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def list_engines(self):
        """
        Lists the script engines available
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'script/view/listEngines/')))
script.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def enable(self, scriptname, apikey=''):
        """
        Enables the script with the given name
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'script/action/enable/', {'scriptName': scriptname, 'apikey': apikey})))
script.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def disable(self, scriptname, apikey=''):
        """
        Disables the script with the given name
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'script/action/disable/', {'scriptName': scriptname, 'apikey': apikey})))
script.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def load(self, scriptname, scripttype, scriptengine, filename, scriptdescription=None, charset=None, apikey=''):
        """
        Loads a script into ZAP from the given local file, with the given name, type and engine, optionally with a description, and a charset name to read the script (the charset name is required if the script is not in UTF-8, for example, in ISO-8859-1).
        """
        params = {'scriptName': scriptname, 'scriptType': scripttype, 'scriptEngine': scriptengine, 'fileName': filename, 'apikey': apikey}
        if scriptdescription is not None:
            params['scriptDescription'] = scriptdescription
        if charset is not None:
            params['charset'] = charset
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'script/action/load/', params)))
script.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def remove(self, scriptname, apikey=''):
        """
        Removes the script with the given name
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'script/action/remove/', {'scriptName': scriptname, 'apikey': apikey})))
script.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def run_stand_alone_script(self, scriptname, apikey=''):
        """
        Runs the stand alone script with the give name
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'script/action/runStandAloneScript/', {'scriptName': scriptname, 'apikey': apikey})))
openapi.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def import_url(self, url, hostoverride=None, apikey=''):
        """
        Import an Open API definition from a URL, hostOverride allows the host to be replaced
        This component is optional and therefore the API will only work if it is installed
        """
        params = {'url': url, 'apikey': apikey}
        if hostoverride is not None:
            params['hostOverride'] = hostoverride
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'openapi/action/importUrl/', params)))
acsrf.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def option_tokens_names(self):
        """
        Lists the names of all anti-CSRF tokens
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/view/optionTokensNames/')))
acsrf.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def add_option_token(self, string, apikey=''):
        """
        Adds an anti-CSRF token with the given name, enabled by default
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/addOptionToken/', {'String': string, 'apikey': apikey})))
acsrf.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def remove_option_token(self, string, apikey=''):
        """
        Removes the anti-CSRF token with the given name
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'acsrf/action/removeOptionToken/', {'String': string, 'apikey': apikey})))
ascan.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def status(self, scanid=None):
        params = {}
        if scanid is not None:
            params['scanId'] = scanid
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/view/status/', params)))
ascan.py 文件源码 项目:zap-api-python 作者: zaproxy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def messages_ids(self, scanid):
        """
        Gets the IDs of the messages sent during the scan with the given ID. A message can be obtained with 'message' core view.
        """
        return six.next(six.itervalues(self.zap._request(self.zap.base + 'ascan/view/messagesIds/', {'scanId': scanid})))


问题


面经


文章

微信
公众号

扫码关注公众号