python类ascii_uppercase()的实例源码

fileutil.py 文件源码 项目:Peppy 作者: project-owner 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_windows_disks(self):
        """ Return disks available on Windows machine

        :return: list of characters representing available disks
        """        
        disks = list()
        import ctypes
        kernel32 = ctypes.WinDLL('kernel32')
        SEM_FAILCRITICALERRORS = 1
        SEM_NOOPENFILEERRORBOX = 0x8000
        SEM_FAIL = SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS
        oldmode = ctypes.c_uint()
        kernel32.SetThreadErrorMode(SEM_FAIL, ctypes.byref(oldmode))

        for s in string.ascii_uppercase:
            n = s + WINDOWS_DISK_SUFFIX
            if os.path.exists(n):
                disks.append(n)

        kernel32.SetThreadErrorMode(oldmode, ctypes.byref(oldmode))

        return disks
encryption.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def ran(N):
    return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(N))

#given a string s, returns a list containing an encrypted string and a key
Utils.py 文件源码 项目:newsreap 作者: caronc 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def random_str(count=16, seed=ascii_uppercase + digits + ascii_lowercase):
    """
    Generates a random string. This code is based on a great stackoverflow
    post here: http://stackoverflow.com/questions/2257441/\
                    random-string-generation-with-upper-case-\
                    letters-and-digits-in-python
    """
    return ''.join(choice(seed) for _ in range(count))
vrmilter.py 文件源码 项目:sipxecs-voicemail-transcription 作者: andrewsauder 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def random_string(size=6, chars=string.ascii_uppercase + string.digits):
    """Get a random string of numbers and uppercase letters"""
    return ''.join(random.choice(chars) for _ in range(size))
prop_helpers.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _cleanId(prop):
    translation = 48*"_"+_string.digits+7*"_"+_string.ascii_uppercase+6*"_"+_string.ascii_lowercase+133*"_"
    prop_id = prop.get_name()
    if prop_id is None:
        prop_id = prop.get_id()
    return str(prop_id).translate(translation)
cyphermain.py 文件源码 项目:Cypher 作者: NullArray 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def gen_client_ID(size=12, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

# Set `SMTP` to False in order to force the program to use HTTP and it's own C&C Web App.
core.py 文件源码 项目:zipline-chinese 作者: zhanghan1990 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def make_simple_equity_info(sids, start_date, end_date, symbols=None):
    """
    Create a DataFrame representing assets that exist for the full duration
    between `start_date` and `end_date`.

    Parameters
    ----------
    sids : array-like of int
    start_date : pd.Timestamp
    end_date : pd.Timestamp
    symbols : list, optional
        Symbols to use for the assets.
        If not provided, symbols are generated from the sequence 'A', 'B', ...

    Returns
    -------
    info : pd.DataFrame
        DataFrame representing newly-created assets.
    """
    num_assets = len(sids)
    if symbols is None:
        symbols = list(ascii_uppercase[:num_assets])
    return pd.DataFrame(
        {
            'symbol': symbols,
            'start_date': [start_date] * num_assets,
            'end_date': [end_date] * num_assets,
            'exchange': 'TEST',
        },
        index=sids,
    )
test_numerical_expression.py 文件源码 项目:zipline-chinese 作者: zhanghan1990 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_many_inputs(self):
        """
        Test adding NumericalExpressions with >10 inputs.
        """
        # Create an initial NumericalExpression by adding two factors together.
        f = self.f
        expr = f + f

        self.fake_raw_data = {f: full((5, 5), 0, float)}
        expected = 0

        # Alternate between adding and subtracting factors. Because subtraction
        # is not commutative, this ensures that we are combining factors in the
        # correct order.
        ops = (add, sub)

        for i, name in enumerate(ascii_uppercase):
            op = ops[i % 2]
            NewFactor = type(
                name,
                (Factor,),
                dict(dtype=float64_dtype, inputs=(), window_length=0),
            )
            new_factor = NewFactor()

            # Again we need a NumericalExpression, so add two factors together.
            new_expr = new_factor + new_factor
            self.fake_raw_data[new_factor] = full((5, 5), i + 1, float)
            expr = op(expr, new_expr)

            # Double the expected output since each factor is counted twice.
            expected = op(expected, (i + 1) * 2)

        self.check_output(expr, full((5, 5), expected, float))
tasks.py 文件源码 项目:sensu_drive 作者: ilavender 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def passwd_generator(size=25):
    chars=string.ascii_uppercase + string.ascii_lowercase + string.digits
    return ''.join(random.choice(chars) for x in range(size,size+size))
forgot_password.py 文件源码 项目:PimuxBot 作者: Finn10111 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def request_password():
    jid = request.form.get('jid')
    re = s.query(RecoveryEmail).filter(RecoveryEmail.jid==jid, RecoveryEmail.confirmed==True).one_or_none()
    if re:
        password_code = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(64))
        re.password_code = password_code
        s.merge(re)
        s.commit()
        password_code_link = 'https://www.pimux.de/password/?code=%s' % password_code
        sendMail(re.email, 'password reset request', 'click here: %s' % password_code_link)
        content = render_template('success.html', message='link was sent')
    else:
        content = render_template('error.html', message='user not found')
    return content
api.py 文件源码 项目:HBCTF 作者: osteth 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def RandomToken(length):
   return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(length))
ecs.py 文件源码 项目:deployfish 作者: caltechads 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def push_remote_text_file(self, input_data=None, run=False, file_output=False):
        """
        Push a text file to the current remote ECS cluster instance and optionally run it.

        :param input_data: Input data to send. Either string or file.
        :param run: Boolean that indicates if the text file should be run.
        :param file_output: Boolean that indicates if the output should be saved.
        :return: tuple - success, output
        """
        if self.__is_or_has_file(input_data):
            path, name = os.path.split(input_data.name)
        else:
            name = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))

        if run:
            cmd = '"cat \> {}\;bash {}\;rm {}"'.format(name, name, name)
        else:
            cmd = '"cat \> {}"'.format(name)

        with_output = True
        if file_output:
            with_output = NamedTemporaryFile(delete=False)
            output_filename = with_output.name

        success, output = self.ssh(command=cmd, with_output=with_output, input_data=input_data)
        if file_output:
            output = output_filename
        return success, output
donot.py 文件源码 项目:sarafu 作者: pesaply 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, host_port, id = None):
        if id == None:
            id = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))

        self._host, self._port = host_port
        self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self._id = id
        self._mid = 1


        # Init session
        print("[+] Using session ID: " + self._id)
        self.send(self.make_SA())

        # Check if we got something
        res = self.recv()
        cookie = res[8:16]
        print("[+] Cookie: " + cookie)

        self._cookie = cookie

        # Enforce value of 0x21
        if ord(res[16]) != 0x21:
            raise Exception("Invalid router response")

        print("[+] New SA successfuly created.")


    # UPD socket helpers
iyzipay_resource.py 文件源码 项目:iyzipay-python 作者: iyzico 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_http_header(self, options=None, pki_string=None):
        header = {"Accept": "application/json", "Content-type": "application/json"}
        if pki_string is not None:
            random_header_value = "".join(
                random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in
                range(self.RANDOM_STRING_SIZE))
            header.update(
                {'Authorization': self.prepare_auth_string(options, random_header_value, pki_string)})
            header.update({'x-iyzi-rnd': random_header_value})
            header.update({'x-iyzi-client-version': 'iyzipay-python-1.0.29'})
        return header
krand.py 文件源码 项目:Good-Old-Kott 作者: mostafa 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def kRandStr(size):
    """docstring."""
    return ''.join(
        random.choice(
            string.ascii_uppercase + string.digits)
        for _ in range(size))
recipe-577988.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def __init__(self,txt,seq_len=5):
        """txt = original text 
        seq_len = sequence length ; 3 to 6 give the best results"""
        # dictionary mapping sequences of seq_len chararcters to the list 
        # of characters following them in the original text
        self.followers = {}
        for i in range(len(txt)-2*seq_len):
            sequence = txt[i:i+seq_len] # sequence of seq_len characters
            next_char = txt[i+seq_len] # the character following this sequence
            if sequence in self.followers:
                self.followers[sequence].append(next_char)
            else:
                self.followers[sequence]=[next_char]

        # sequences that start with an uppercase letter
        starts = [ key for key in self.followers 
            if key[0] in string.ascii_uppercase ]
        if not starts: # just in case...
            starts = list(self.followers.keys())

        # build a distribution of these sequences with the same frequency
        # as in the original text
        self.starts = []
        for key in starts:
            for i in range(len(self.followers[key])):
                self.starts.append(key)


问题


面经


文章

微信
公众号

扫码关注公众号