python类subn()的实例源码

util.py 文件源码 项目:SalesforceXyTools 作者: exiahuang 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def del_comment(soql):
    result = soql
    if soql:
        # TODO
        # soql = soql.strip().replace('\t', ' ').replace('\r\n', ' ').replace('\n', ' ')
        soql = soql.strip().replace('\t', ' ')

        # delete // comment
        result1, number = re.subn("//.*", "", soql)
        # delete /**/ comment
        result, number = re.subn("/\*([\s|\S]*?)\*/", "", result1, flags=re.M)
        result = result.strip()
    # show_in_panel(result)

    return result


# get sobject name from soql
obtain_date.py 文件源码 项目:Broad_Crawler 作者: rafacheng 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def pre_process(dates):
    # \u5e74\u6708\u65e5
    # dates = [re.subn(r'[\u4e00-\u5e73]|[\u5e75-\u6707]', '', tm)[0] for tm in dates]
    # dates = [re.subn(r'[\u6709-\u65e4]|[\u65e6-\u9fa5]', '', tm)[0] for tm in dates]
    # ???
    dates = dates[:int(len(dates) / 2)]
    # ?????100??
    dates = [d for d in dates if 100 > len(d) > 0]
    # ????????
    dates = [d.replace('\n', ' ').replace('\t', ' ').replace('\b', ' ').replace(' ', ' ') for d in dates]
    # ????????????????
    new_dates = []
    for v in dates:
        v = re.sub('\A\s*', '', v)
        v = re.sub('\s*\Z', '', v)
        v = re.sub('\s+', ' ', v)
        new_dates.append(v)
    # ???????????????????????
    shorter_dates = []
    for v in new_dates:
        ffdi = find_first_digit_index(v)
        if ffdi:
            shorter_dates.append(v[ffdi-1:])
    return shorter_dates
publishers.py 文件源码 项目:python-mysql-binlog-pubsub 作者: tarzanjw 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _rename_schema(self, schema):
        """ Rename a schema name and return new name

        Args:
            schema (str): schema nae

        Returns:
            str
        """
        try:
            return self._schema_new_names[schema]
        except KeyError:
            new_name = schema
            for pattern, repl in self.schema_rename.items():
                new_name, subs_made = re.subn(pattern, repl, schema)
                if subs_made:
                    break

            self._schema_new_names[schema] = new_name
            return new_name
publishers.py 文件源码 项目:python-mysql-binlog-pubsub 作者: tarzanjw 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _rename_table(self, schema, table):
        """ Rename a table and rereturn new name

        Args:
            schema (str): schema name (the new one)
            table (str): table name

        Returns:
            str
        """
        try:
            return self._table_new_names[(schema, table)]
        except KeyError:
            new_name = table
            _rules = self.table_rename.get(schema, {})
            for pattern, repl in _rules.items():
                new_name, subs_made = re.subn(pattern, repl, table)
                if subs_made:
                    break

            self._table_new_names[(schema, table)] = new_name
            return new_name
resolver.py 文件源码 项目:drydock 作者: att-comdev 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def resolve_reference_ucp(cls, design_uri):
        """Retrieve artifacts from a UCP service endpoint.

        Return a byte array of the response content. Assumes Keystone
        authentication required.

        :param design_uri: Tuple as returned by urllib.parse for the design reference
        """
        ks_sess = KeystoneUtils.get_session()
        (new_scheme, foo) = re.subn('^[^+]+\+', '', design_uri.scheme)
        url = urllib.parse.urlunparse((new_scheme, design_uri.netloc, design_uri.path,
                                       design_uri.params, design_uri.query, design_uri.fragment))
        logger = logging.getLogger(__name__)
        logger.debug("Calling Keystone session for url %s" % str(url))
        resp = ks_sess.get(url)
        if resp.status_code >= 400:
            raise errors.InvalidDesignReference(
                "Received error code for reference %s: %s - %s" % (url, str(resp.status_code), resp.text))
        return resp.content
sed.py 文件源码 项目:PythonSed 作者: GillesArcas 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def apply(self, sed):
        _, repl, count, printit, _, write, filename = self.args

        # managing ampersand is done when converting to python format

        # manage empty regexp
        regexp = sed.cache_regexp(self.regexp)

        success, sed.PS = regexp.subn(repl, sed.PS, count=count)

        sed.subst_successful = sed.subst_successful or success

        if success:
            if printit:
                sed.printline(sed.PS)
            if write:
                sed.write_subst_file(filename, sed.PS)

        return self.next
alutiiq.py 文件源码 项目:wiinaq 作者: futurulus 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def normalize(word):
    '''
    Perform fuzzy search normalization (collapse commonly confused sounds
    so search is resilient to misspellings of Alutiiq words).

    >>> normalize('tuumiaqlluku')
    'tumiaklluku'
    >>> normalize("Wiiwaq")
    'uiuak'
    >>> normalize("estui'isuun")
    'stuisun'
    '''
    word = re.subn(r'(?<!n)g', 'r', word)[0]
    word = re.subn(r'[A-QS-Z]', lambda m: m.group().lower(), word)[0]
    word = (word.replace('q', 'k')
                .replace('y', 'i')
                .replace('w', 'u')
                .replace('e', '')
                .replace("'", ''))
    for vowel in 'aiu':
        word = re.sub(vowel + '+', vowel, word)
    return word
engine.py 文件源码 项目:refextract 作者: inspirehep 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def find_substring_ignore_special_chars(s, substr):
    s = s.upper()
    substr = substr.upper()
    clean_s, dummy_subs_in_s = re.subn('[^A-Z0-9]', '', s)
    clean_substr, dummy_subs_in_substr = re.subn('[^A-Z0-9]', '', substr)
    startIndex = clean_s.find(clean_substr)
    if startIndex != -1:
        i = 0
        real_index = 0
        re_alphanum = re.compile('[A-Z0-9]')
        for real_index, char in enumerate(s):
            if re_alphanum.match(char):
                i += 1
            if i > startIndex:
                break

        return real_index
    else:
        return -1
update-date.py 文件源码 项目:squid_dedup 作者: frispete 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def search_and_replace_date(lines, newdate):
    pattern = gpar.date_assign_re % gpar.datevar
    repl = gpar.date_repl_re % newdate
    log.debug('search_and_replace_date: pattern: %s', pattern)
    log.debug('search_and_replace_date: replace: %s', repl)
    for ln, line in enumerate(lines):
        newline, n = re.subn(pattern, repl, line)
        if n:
            if line != newline:
                # pattern matched and line changed
                log.debug('found pattern: %s', line[:-1])
                log.debug('  replacement: %s', newline[:-1])
                lines[ln] = newline
                return True
            else:
                # pattern matched, but not changed
                return False
    return False
setupActiveModules.py 文件源码 项目:Eyra 作者: Eyra-is 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def logReSubn(subnExpr, preComment, postComment, errorMsg='') -> str:
    """
    Takes in the result of a re.subn call, subnExpr, and
    logs preComment to stdout, then logs postComment and specifies the
    number of subs.
    Prints errorMsg in case of 0 subs.

    Returns the string from subnExpr with replacements made.
    """
    out = subnExpr[0]
    subs = subnExpr[1]
    print(preComment)
    print(str(subs) + ' ' + postComment)
    if (subs == 0 and errorMsg != ''):
        print(errorMsg)
    return out
_sourcedstring.py 文件源码 项目:gateplugin-python 作者: GateNLP 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def subn(self, repl, string, count=0):
        if (isinstance(repl, SourcedString) or
            isinstance(string, SourcedString)):
            result = ''
            pos = 0
            n = 0
            for match in self.pattern.finditer(string):
                result += string[pos:match.start()]
                result += repl
                pos = match.end()
                n += 1
                if count and n==count: break
            result += string[pos:]
            return result, n
        else:
            return self.pattern.subn(repl, string, count)
_sourcedstring.py 文件源码 项目:gateplugin-python 作者: GateNLP 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def patch_re_module():
        """
        Modify the standard ``re`` module by installing new versions of
        the functions ``re.compile``, ``re.sub``, and ``re.subn``,
        causing regular expression substitutions to return
        ``SourcedStrings`` when called with ``SourcedStrings``
        arguments.

        Use this function only if necessary: it potentially affects
        all Python modules that use regular expressions!
        """
        def new_re_sub(pattern, repl, string, count=0):
            return re.compile(pattern).sub(repl, string, count)
        def new_re_subn(pattern, repl, string, count=0):
            return re.compile(pattern).subn(repl, string, count)
        re.compile = SourcedStringRegexp
        re.sub = new_re_sub
        re.subn = new_re_subn
sourcedstring.py 文件源码 项目:gateplugin-python 作者: GateNLP 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def subn(self, repl, string, count=0):
        if (isinstance(repl, SourcedString) or
            isinstance(string, SourcedString)):
            result = ''
            pos = 0
            n = 0
            for match in self.pattern.finditer(string):
                result += string[pos:match.start()]
                result += repl
                pos = match.end()
                n += 1
                if count and n==count: break
            result += string[pos:]
            return result, n
        else:
            return self.pattern.subn(repl, string, count)
sourcedstring.py 文件源码 项目:gateplugin-python 作者: GateNLP 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def patch_re_module():
        """
        Modify the standard ``re`` module by installing new versions of
        the functions ``re.compile``, ``re.sub``, and ``re.subn``,
        causing regular expression substitutions to return
        ``SourcedStrings`` when called with ``SourcedStrings``
        arguments.

        Use this function only if necessary: it potentially affects
        all Python modules that use regular expressions!
        """
        def new_re_sub(pattern, repl, string, count=0):
            return re.compile(pattern).sub(repl, string, count)
        def new_re_subn(pattern, repl, string, count=0):
            return re.compile(pattern).subn(repl, string, count)
        re.compile = SourcedStringRegexp
        re.sub = new_re_sub
        re.subn = new_re_subn
secretary.py 文件源码 项目:pytemplate 作者: krotos139 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _unescape_entities(xml_text):
        """
        Strips tags of the form <text:span ...> from inside Jinja elements
        and unescapes HTML codes for >, <, & and "
        """
        unescape_rules = {
            r'(?is)({([{%])[^%}]*?)(</?text:s.*?>)(.*?[%}]})': r'\1 \4',
            r'(?is)({([{%])[^%}]*?)(&gt;)(.*?[%}]})'         : r'\1>\4',
            r'(?is)({([{%])[^%}]*?)(&lt;)(.*?[%}]})'         : r'\1<\4',
            r'(?is)({([{%])[^%}]*?)(&amp;)(.*?[%}]})'        : r'\1&\4',
            r'(?is)({([{%])[^%}]*?)(&quot;)(.*?[%}]})'       : r'\1"\4',
        }

        for regexp, replacement in unescape_rules.items():
            subs_made = True
            while subs_made:
                xml_text, subs_made = re.subn(regexp, replacement, xml_text)

        return xml_text
parsing.py 文件源码 项目:Tutorial-Chatterbot 作者: isipalma 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def datetime_parsing(text, base_date=datetime.now()):
    """
    Extract datetime objects from a string of text.
    """
    matches = []
    found_array = []

    # Find the position in the string
    for expression, function in regex:
        for match in expression.finditer(text):
            matches.append((match.group(), function(match, base_date), match.span()))

    # Wrap the matched text with TAG element to prevent nested selections
    for match, value, spans in matches:
        subn = re.subn(
            '(?!<TAG[^>]*?>)' + match + '(?![^<]*?</TAG>)', '<TAG>' + match + '</TAG>', text
        )
        text = subn[0]
        is_substituted = subn[1]
        if is_substituted != 0:
            found_array.append((match, value, spans))

    # To preserve order of the match, sort based on the start position
    return sorted(found_array, key=lambda match: match and match[2][0])
HDOJ_Submitter.py 文件源码 项目:HDUACM_ACer 作者: HScarb 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def getTextFromSoup(htmlsoup):
    #print(htmlsoup)
    text = str(htmlsoup)
    imgurls = []
    imgs = htmlsoup.find_all('img')
    #print_list(imgs)
    for img in imgs:
        imgurls.append('http://acm.hdu.edu.cn%s' % img['src'])
    #print(htmlsoup)
    if len(imgurls) != 0:
        for url in imgurls:
            text, number = re.subn(r'<img.+?>', r'![image](%s)' % url, text)
    #print(text)
    text, number = re.subn(r'<br>', '\n', text)
    text, number = re.subn(r'<.+?>', '', text)
    return text
    #print(text)
    #print(seh.group())
    #print_list(imgurls)
    # res = htmlsoup.replace('<br/>', '\r\n')
    # result, number = re.subn('<.+?>', '', res)
    # print(result)
    # print(number)
vkstruct_json.py 文件源码 项目:vkstruct 作者: cheery 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def translate_enumeration(types, enum, constructor):
    name = enum["name"]
    name = rename_enumeration(name)

    types[name] = this = {"type":constructor, "ctype":"i32"}
    this["constants"] = constants = {}

    # turns out the "expand" was insufficient nearly everywhere.
    prefix = "^VK_"
    for cell in split_case(name):
        prefix += "(" + cell.upper() + "_)?"
    for tag in enum:
        if tag.name == "enum":
            name_ = re.subn(prefix, "", tag["name"])[0]
            if "bitpos" in tag.attrs:
                value = 1 << int(tag["bitpos"])
            elif tag["value"].startswith("0x"):
                value = int(tag["value"], 16)
            else:
                value = int(tag["value"])
            constants[name_] = value
    return name
vkstruct.py 文件源码 项目:vkstruct 作者: cheery 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def translate_enumeration(enum, constructor):
    name = enum["name"]
    name = rename_enumeration(name)
    print "{0} = {1}({0!r}, {{".format(name, constructor)
    # turns out the "expand" was insufficient nearly everywhere.
    prefix = "^VK_"
    for cell in split_case(name):
        prefix += "(" + cell.upper() + "_)?"
    for tag in enum:
        if tag.name == "enum":
            name_ = re.subn(prefix, "", tag["name"])[0]
            if "bitpos" in tag.attrs:
                value = "1 << " + tag["bitpos"]
            else:
                value = tag["value"]
            print "    {!r:<50}: {!s},".format(name_, value)
    print "})"
    return name
checkwiki.py 文件源码 项目:NapalmBot 作者: Facenapalm 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def fix_unpair_tag(text, tag, count_selfclosing=True):
    """
    Fix self-closing unpair tags and return (new_text, replacements_count) tuple.
    tag parameter must contains only name of the tag, for example, "br" for <br>.
    If self-closing tags are correct, set count_selfclosing param to False.
    self-closing still will be corrected in the name of unification, but those
    replacements will not be counted.
    Used in 2nd error.
    """
    correct_tag = "<{}>".format(tag)
    all_tags = r"<[/\\ ]*{}[/\\ ]*>".format(tag)

    if count_selfclosing:
        correct = count_ignore_case(text, correct_tag)
    else:
        correct = len(re.findall(r"<{}\s*/?>".format(tag), text))
    (text, fixed) = re.subn(all_tags, correct_tag, text, flags=re.I)
    return (text, fixed - correct)
checkwiki.py 文件源码 项目:NapalmBot 作者: Facenapalm 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def fix_pair_tag(text, tag, recursive=False):
    """
    Fix self-closing pair tags and return (new_text, replacements_count) tuple.
    tag parameter must contains only name of the tag, for example, "b" for <b>.
    recursive flag must be True if nested tags are correct. The default value is False.
    Checks tag balance: if something going wrong, function willn't change anything.
    Used in 2nd error.
    """
    old_text = text
    correct_tag = "</{}>".format(tag)

    (text, fixed1) = re.subn(r"<[ ]*{}[ ]*[/\\]>".format(tag), correct_tag, text, flags=re.I)
    (text, fixed2) = re.subn(r"<\\[ ]*{}[ ]*>".format(tag), correct_tag, text, flags=re.I)

    if check_tag_balance(text, tag, recursive):
        return (text, fixed1 + fixed2)
    else:
        return (old_text, 0)
checkwiki.py 文件源码 项目:NapalmBot 作者: Facenapalm 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def error_002_invalid_tags(text):
    """Fix the error and return (new_text, replacements_count) tuple."""
    (text, fixed_br) = fix_unpair_tag(text, "br", count_selfclosing=False)
    (text, fixed_hr) = fix_unpair_tag(text, "hr", count_selfclosing=False)
    fixed_total = fixed_br + fixed_hr

    (text, fixed_clear) = re.subn(r"<br clear=\"?(left|right)\"?\s*/?>", "{{clear|\\1}}", text)
    (text, fixed_clear_all) = re.subn(r"<br clear=\"?(?:all|both)\"?\s*/?>", "{{clear}}", text)
    fixed_total += fixed_clear + fixed_clear_all

    (text, fixed_small) = fix_pair_tag(text, "small")
    (text, fixed_center) = fix_pair_tag(text, "center")
    (text, fixed_div) = fix_pair_tag(text, "div", recursive=True)
    (text, fixed_span) = fix_pair_tag(text, "span", recursive=True)
    fixed_total += fixed_small + fixed_center + fixed_div + fixed_span

    return (text, fixed_total)
checkwiki.py 文件源码 项目:NapalmBot 作者: Facenapalm 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def error_068_interwiki_link(text):
    """
    Fix links to Special:BookSearch and direct links, written like interwiki
    ones. For example, for ruwiki fixes [[:ru:Example|Something]].
    Return (new_text, replacements_count) tuple.
    """
    def _check_link(match_obj):
        """Check if founded link is a link to a file or a category and insert extra ":" if so."""
        link = match_obj.group(2).lstrip().lower()
        if re.search(r"^" + IMAGE, link) is None and re.search(r"^" + CATEGORY, link) is None:
            return match_obj.group(1) + match_obj.group(2)
        else:
            return match_obj.group(1) + ":" + match_obj.group(2)

    # bot will not fix links without a pipe: manual control needed
    (text, direct) = re.subn(r"(\[\[):{}:([^|\[\]\n]+\|[^|\[\]\n]+\]\])".format(LANG_CODE),
                             _check_link, text, flags=re.I)
    (text, books) = re.subn(r"\[\[:..:Special:BookSources/\d+X?\|(ISBN [0-9\-X]+)\]\]",
                            "\\1", text, flags=re.I)
    return (text, direct + books)
checkwiki.py 文件源码 项目:NapalmBot 作者: Facenapalm 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def error_086_ext_link_two_brackets(text):
    """Fix some cases and return (new_text, replacements_count) tuple."""
    # case: [[http://youtube.com/|YouTube]]
    def _process_link(match_obj):
        """Deals with founded wiki-link."""
        link = match_obj.group(1)
        name = match_obj.group(2)
        if "wikipedia.org" in link.lower():
            link = re.sub(" ", "_", link)
        else:
            link = re.sub(" ", "%20", link)
        return "[" + link + " " + name + "]"
    exp1 = r"\[\[(https?://[^|\[\]\n]+)\|([^|\[\]\n]+)\]\]"
    (text, count1) = re.subn(exp1, _process_link, text, flags=re.I)
    # case: [[http://youtube.com YouTube]]
    exp2 = r"\[(\[https?://[^\[\]\n]+\])\]"
    (text, count2) = re.subn(exp2, "\\1", text, flags=re.I)
    return (text, count1 + count2)
checkwiki.py 文件源码 项目:NapalmBot 作者: Facenapalm 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def error_104_quote_marks_in_refs(text):
    """Fix the error and return (new_text, replacements_count) tuple."""
    count3 = 0
    def quote_ref(match):
        """Quote ref name if it's neccessary."""
        #pylint: disable=undefined-variable
        nonlocal count3
        name = match.group(2)
        if re.search(r"group\s*=", name):
            return match.group(0)
        if "\"" in name or re.match(r"^'.*'$", name):
            # ref is already quotetd (all is ok) or has a quote (dangerous to fix)
            return match.group(0)
        if re.search(r"['/\\=?#\s]", name):
            count3 += 1
            return match.group(1) + "\"" + name + "\"" + match.group(3)
        return match.group(0)

    (text, count1) = re.subn(r"(<ref\s+name\s*=\s*\"[^\">]+?)(\s*/?>)", "\\1\"\\2", text)
    (text, count2) = re.subn(r"(<ref\s+name\s*=\s*)([^\">]+?\"\s*/?>)", "\\1\"\\2", text)
    text = re.sub(r"(<ref\s+name\s*=\s*)(.*?)(\s*/?>)", quote_ref, text)
    return (text, count1 + count2 + count3)
test_saml.py 文件源码 项目:social-core 作者: python-social-auth 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def modify_start_url(self, start_url):
        """
        Given a SAML redirect URL, parse it and change the ID to
        a consistent value, so the request is always identical.
        """
        # Parse the SAML Request URL to get the XML being sent to TestShib
        url_parts = urlparse(start_url)
        query = dict((k, v[0]) for (k, v) in
                     parse_qs(url_parts.query).items())
        xml = OneLogin_Saml2_Utils.decode_base64_and_inflate(
            query['SAMLRequest']
        )
        # Modify the XML:
        xml = xml.decode()
        xml, changed = re.subn(r'ID="[^"]+"', 'ID="TEST_ID"', xml)
        self.assertEqual(changed, 1)
        # Update the URL to use the modified query string:
        query['SAMLRequest'] = OneLogin_Saml2_Utils.deflate_and_base64_encode(
            xml
        )
        url_parts = list(url_parts)
        url_parts[4] = urlencode(query)
        return urlunparse(url_parts)
recipe-577349.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def removebackspaces(text):
    backspace_or_eol = r'(.\010)|(\033\[K)'
    n = 1
    while n > 0:
        text, n = re.subn(backspace_or_eol, '', text, 1)
    return text
training.py 文件源码 项目:photinia 作者: XoriieInpottn 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def load(self, name, model, alias_list=None):
        param_dict = self._load(name)
        if alias_list:
            new_dict = {}
            for key, value in param_dict.items():
                for src, dst in alias_list:
                    if not key.startswith(src):
                        continue
                    print(key)
                    if isinstance(dst, widgets.Widget):
                        dst = dst.prefix()
                    key, _ = re.subn('^{}'.format(src), dst, key)
                    new_dict[key] = value
            param_dict = new_dict
        model.parameters = param_dict
tle.py 文件源码 项目:satellite-tracker 作者: lofaldli 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def checksum(line):
    line, n = re.subn('-', '1', line)     # replace dashes with 1's
    line, n = re.subn('[^\d]', '', line)  # remove non-digit chars
    # compare with last digit with sum modulo 10
    digits = [int(x) for x in line[:-1]]
    return int(line[-1]) == sum(digits) % 10
stamp.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def stamp_source(base_dir, version, dry_run=False):
    """update version string in passlib dist"""
    path = os.path.join(base_dir, "passlib", "__init__.py")
    with open(path) as fh:
        input = fh.read()
    output, count = re.subn('(?m)^__version__\s*=.*$',
                    '__version__ = ' + repr(version),
                    input)
    assert count == 1, "failed to replace version string"
    if not dry_run:
        os.unlink(path) # sdist likes to use hardlinks
        with open(path, "w") as fh:
            fh.write(output)


问题


面经


文章

微信
公众号

扫码关注公众号