Пример #1
0
    def subf(pattern, format, string, count=0, flags=0, pos=None, endpos=None, concurrent=None, **kwargs):
        """Wrapper for subf."""

        return regex.subf(
            _apply_search_backrefs(pattern, flags), format, string,
            count, flags, pos, endpos, concurrent, **kwargs
        )
Пример #2
0
def nba_scraper(url, headers, n_years, verbose):

    # Initiate variables for the for loop
    df = pd.DataFrame()
    season_list = past_seasons(n_years)
    i = 1

    for season in season_list:

        # Creating the new url for the this season, scraping data, and saving it
        url = re.subf(r'Season=[-\d]+', 'Season={}'.format(season), url)
        result = requests.get(url, headers=headers)
        columns = result.json()['resultSets'][0]['headers']
        df = pd.concat([
            df,
            pd.DataFrame(result.json()['resultSets'][0]['rowSet'],
                         columns=columns)
        ],
                       axis=0)

        # Updating the user and getting ready to scrape again
        if verbose > 0:
            print('Completed Scrape {} of {}'.format(i, len(season_list)))
        i += 1
        time.sleep(5)

    return df
Пример #3
0
    def subf(pattern, format, string, count=0, flags=0, pos=None, endpos=None, concurrent=None, **kwargs):
        """Wrapper for subf."""

        return regex.subf(
            _apply_search_backrefs(pattern, flags), format, string,
            count, flags, pos, endpos, concurrent, **kwargs
        )
Пример #4
0
 def cut(self, text, flags=DEFAULT_FLAGS):
     """Perform tokenization and filter results according to given flags.
     """
     if not self.compiled:
         self.compile()
     self._log(0, 'Original text: \033[7m{}\033[0m'.format(repr(text)))
     if self.init:
         text = regex.sub(self.initx, '{}'.format(FIRST_WORD), text)
     self._log(
         0, 'Sentence-intial words marked: \033[7m{}\033[0m'.format(
             repr(text)))
     if self.abbr:
         text = regex.subf(self.abbrx,
                           '{}{{}}{}'.format(COVER_BEGIN, COVER_END), text)
     self._log(0,
               'Abbreviations marked: \033[7m{}\033[0m'.format(repr(text)))
     pos = 0
     for token, tag, level in self._cut_rec(text):
         token = regex.sub('[' + FIRST_WORD + COVER_BEGIN + COVER_END + ']',
                           '', token)
         oldpos = pos
         pos += len(token)
         if not flags & WHITESPACE_TOKENS and tag == WHITESPACE_TAG:
             continue
         if token == '' and (not flags & EMPTY_TOKENS
                             or tag == WHITESPACE_TAG):
             continue
         yield (token, tag, level, oldpos, pos)
Пример #5
0
    def get_ad_tree(self):
        """Запрашивает из AD distinguishedName для всех UO,
        возвращает список из списков элементов DN"""
        try:
            query = pyad.adquery.ADQuery()
            query.execute_query(
                attributes=["distinguishedName", "description"],
                where_clause="objectClass = 'organizationalUnit'")
        except Exception as e:
            raise Exception(str(e))
        else:
            domain = False
            ous = []
            for row in query.get_results():

                while domain is False:
                    self.domainList = row["distinguishedName"].split(
                        ",DC=", maxsplit=1)[1].split(",DC=")
                    domain = ".".join(self.domainList)
                    self.logBrowser.append(
                        "Подключено к домену: {}".format(domain))
                pathList = regex.subf(
                    "^OU=", "",
                    row["distinguishedName"].split(",DC=")[0]).split(",OU=")
                reversedPathList = list(reversed(pathList))
                ous += [reversedPathList]
            return sorted(ous)
Пример #6
0
    def __clean_data(self, strText):
        sentences = []
        strText = strText.lower()
        strText = regex.subf(self.__bracket, "", strText)
        strText = re.sub(self.__reSub0, " ", strText)
        strText = re.sub(self.__reSub1, " ", strText)

        for sentence in re.split("\.[^a-z0-9]|[,:?!;\n\r]", strText):
            word_sen = word_token(sentence)
            if (len(word_sen) > 2):
                sentences.append(u" ".join(word_sen) + "\n")
        return sentences
Пример #7
0
    def login_templating(self, f, i, o):
        """Генерирует и возвращает логин из ФИО по шаблону"""
        fLat = utilities.translit(f)
        iLat = utilities.translit(i)
        oLat = utilities.translit(o)
        template = self.loginTemplate.text()

        template = regex.subf(r'([fio])(\d*)', '{{{1}:.{2}}}', template)
        template = template.replace(":.}", "}")

        login = self.loginPrefix.text() + template.format(
            f=fLat, i=iLat, o=oLat)

        return login
Пример #8
0
    def __clean_data(self, strText):
        sentences = []
        strText = strText.lower()
        if self.usage_scenario == "phrase":
            strText = regex.subf(self.__bracket, "", strText)
        strText = re.sub(self.__reSub0, " ", strText)
        strText = re.sub(self.__reSub1, " ", strText)

        for sub in set(re.findall(self.__rePlus, strText)):
            strText = strText.replace(sub, sub[0] + " " + sub[2])
        for sentence in re.split(self.__resplit, strText):
            word_sen = word_token(sentence)
            if (len(word_sen) > self.__minNum):
                sentences.append(u" ".join(word_sen) + "\n")
        return sentences
Пример #9
0
def bball_reference_scraper(url, n_years, stat, verbose):

    # Initiate variables for the for loop
    season_list = [str(year) for year in range(2018, 2018 - n_years, -1)]
    i = 1

    # Creating the blank data frame
    df = pd.DataFrame()

    # Looping over all seasons
    for season in season_list:

        # Determining the url for the season
        url = re.subf(r'NBA_[\d]+', 'NBA_{}'.format(season), url)

        # Calling the scraper according to the stat input
        if stat == 'assists_value':
            df = pd.concat([df, assists_value_scraper(url, season)],
                           axis=0,
                           sort=False)

        elif stat == 'standings':
            df = pd.concat([df, standings_scraper(url, season)],
                           axis=0,
                           sort=False)

        else:
            print("We don't have that scraper, yet!")

        # Updating the user and getting ready to scrape again
        if verbose > 0:
            print('Completed Scrape {} of {}'.format(i, len(season_list)))
        i += 1
        if i < len(season_list):
            time.sleep(5)

    return df
def wfs(i = [0]):
    return regex.subf(r"wfs", "wfs" + indices(i), "(?P<wfs>" +  Quantifiers([i[0],1]) + "(?:<((?&wfs))[&V-]((?&wfs))>" + "|" + Term([i[0],1]) + "=" + Term([i[0],2]) + "))")
def Term(i = [0]):
    return regex.subf(r"Term", "Term" + indices(i), "(?P<Term>S*(?:\(((?&Term))[.+]((?&Term))\)" + "|" + Numeral + "|" + Variable + "))")  
def Quantifiers(i = [0]):
    return regex.subf(r"Quantifiers", "Quantifiers" + indices(i), "(?P<Quantifiers>"+ "(?:~|E"+ Variable + ":" + "|A" + Variable + ":" + ")*"  + ")")
Пример #13
0
def dynamic_pattern(pattern):
    regex.subf(pattern, replacement, input)  # OK
    subf(pattern, replacement, input)  # OK
Пример #14
0
def main():
    os.chdir(os.path.dirname(__file__))
    gcc_command = list(["gcc", "-C", "-E"])

    for include in INCLUDES:
        gcc_command.append('-I')
        gcc_command.append(include)

    gcc_command.append(
        "extern/tes3mp/apps/openmw-mp/Script/ScriptFunctions.hpp")

    parser = PrimitiveHeaderParser()

    with subprocess.Popen(gcc_command, stdout=subprocess.PIPE) as p:
        out, err = p.communicate()
        for line in out.splitlines():
            parser.parse_line(line.decode())

    raw = f"#[no_mangle]\npub static mut prefix: [u8; {len(PREFIX)}] = *b\"{PREFIX}\";\n"

    fancy = ""

    for func_name in parser.functions:
        ref = parser.functions[func_name]
        func = parser.classes[ref[0]].functions[ref[1]]

        args = ', '.join([TYPE_TRANSLATION[arg[1]] for arg in func.args])
        ret = ""

        if func.return_type in ['const char*', 'const char *']:
            ret = " -> *const c_char"
        elif func.return_type != "void":
            ret = f" -> {TYPE_TRANSLATION[func.return_type]}"

        place_holder = "|" + ', '.join(['_'] * len(func.args)) + f'| {{ unreachable!("{func_name} was called before ' \
                                                                 f'set by TES3MP"); }};'

        func_def = f"#[no_mangle]\npub static mut {PREFIX}{func_name}: fn({args}){ret} = {place_holder}"

        if '<REMOVE>' in func_def:
            continue

        raw += func_def + "\n"

        fancy_name = normalize_var(func_name)
        fancy_args = []

        for arg in func.args:
            fancy_arg = normalize_var(arg[0])

            fancy_arg = fancy_arg.replace('__', '_')

            if arg[1] in ['const char*', 'const char *']:
                fancy_args.append((
                    fancy_arg, '&str',
                    f'CString::new({fancy_arg}).unwrap_or_default().as_ptr()'))
            else:
                fancy_args.append(
                    (fancy_arg, TYPE_TRANSLATION[arg[1]], fancy_arg))

        ret = ""
        if func.return_type in ['const char*', 'const char *']:
            ret = " -> String"
        elif func.return_type != "void":
            ret = f" -> {TYPE_TRANSLATION[func.return_type]}"

        func_args = ', '.join([f"{x[0]}: {x[1]}" for x in fancy_args])
        call_args = ', '.join([x[2] for x in fancy_args])

        if func.comment is not None:
            comment = ""
            for line in func.comment.strip().splitlines():
                line = line.strip()
                m = regex.match(RE_COMMENT_PREFIX, line)
                comment += ("///" + (' ' * len(m[1])) + m[2]).rstrip() + "\n"

            comment = regex.sub(RE_BRIEF, '', comment)

            def replace_param(m):
                return f"`{normalize_var(m[1])}`"

            def replace_return(m):
                return f"\n///  Returns {m[1].lower()}"

            comment = regex.sub(RE_PARAM_PREFIX, replace_param, comment)
            comment = regex.sub(RE_RETURN, replace_return, comment)
            comment = regex.subf(RE_COMMENT_NEWLINE, '{1}  \n///{2}', comment)
            comment = comment.replace('"[Script]:"', '`[Script]:`')

            fancy += comment

        fancy += f"pub fn {fancy_name}({func_args}){ret} {{\n"
        fancy += "    unsafe {\n"

        if func.return_type in ['const char*', 'const char *']:
            fancy += f"        CStr::from_ptr(raw::{PREFIX}{func_name}({call_args}))\n"
            fancy += f"            .to_str()\n"
            fancy += f"            .unwrap_or_default()\n"
            fancy += f"            .to_string()\n"
        else:
            fancy += f"        raw::{PREFIX}{func_name}({call_args})\n"

        fancy += "    }\n"
        fancy += "}\n\n"

    whole = "use std::ffi::{CStr, CString};\nuse std::os::raw::*;\n\n"
    whole += "#[allow(non_upper_case_globals)]\npub mod raw {\n    use std::os::raw::*;\n"
    for line in raw.splitlines():
        whole += "    " + line + "\n"
    whole += "}\n\n"
    whole += fancy

    with open("tes3mp-plugin/src/plugin/generated.rs", "w") as f:
        f.write(whole)
Пример #15
0
def dynamic_pattern(pattern):
    regex.subf(pattern, replacement, input)  # Noncompliant
    subf(pattern, replacement, input)  # Noncompliant
Пример #16
0
def dynamic_pattern(pattern):
    regex.subf(pattern, replacement, input)  # Noncompliant
    subf(pattern, replacement, input)  # Noncompliant