Exemplo n.º 1
0
    def name(self, gender='female'):
        """Get a random name.

        :param gender: if 'male' then will getting male name else female name.
        :return: Name.
        :Example:
            John.
        """
        # TODO: Add function for checking gender.
        try:
            names = self.data['names'][gender]
        except KeyError:
            raise WrongArgument('gender must be "female" or "male"')
        return self.random.choice(names)
Exemplo n.º 2
0
    def title(self, gender='female', title_type='typical'):
        """Get a random title (prefix/suffix) for name.

        :param gender: The gender.
        :param title_type:  The type of title ('typical' and 'academic').
        :return: The title.
        :Example:
            PhD.
        """
        try:
            titles = self.data['title'][gender][title_type]
        except KeyError:
            raise WrongArgument('Wrong value of argument.')

        title = self.random.choice(titles)
        return title
Exemplo n.º 3
0
    def network_protocol(self, layer='application'):
        """Get a random network protocol form OSI model.

        :param layer: Layer of protocol: application, data_link,
        network, physical, presentation, session and transport.
        :return: Protocol name.
        :Example:
            AMQP
        """
        layer = layer.lower()
        try:
            protocol = self.random.choice(NETWORK_PROTOCOLS[layer])
            return protocol
        except KeyError:
            protocols = list(NETWORK_PROTOCOLS.keys())
            raise WrongArgument('Unsupported layer, use: {}'.format(protocols))
Exemplo n.º 4
0
    def surname(self, gender='female'):
        """Get a random surname.

        :param gender: The gender of person.
        :return: Surname.
        :Example:
            Smith.
        """
        # Separated by gender.
        if self.locale in ('ru', 'is', 'uk'):
            try:
                return self.random.choice(self.data['surnames'][gender])
            except KeyError:
                raise WrongArgument('gender must be "female" or "male"')

        surname = self.random.choice(self.data['surnames'])
        return surname
Exemplo n.º 5
0
    def title(self, gender: Gender = 0, title_type: str = 'typical') -> str:
        """Get a random title (prefix/suffix) for name.

        :param gender: The gender.
        :type gender: int or str
        :param str title_type:  The type of title ('typical' and 'academic').
        :return: The title.
        :raises WrongArgument: if gender in incorrect format.

        :Example:
            PhD.
        """
        try:
            gender = check_gender(gender)
            titles = self.data['title'].get(gender).get(title_type)
        except KeyError:
            raise WrongArgument('Wrong value of argument.')

        title = self.random.choice(titles)
        return title
Exemplo n.º 6
0
    def username(self, gender='female'):
        """Get a random username with digits. Username generated
        from names (en) for all locales.

        :return: Username.
        :rtype: str
        :Example:
            abby1189.
        """
        try:
            names = pull('personal.json', 'en')['names'][gender]
            name = self.random.choice(names)
        except KeyError:
            raise WrongArgument('gender must be "female" or "male"')

        fmt = ['%s_%s', '%s%s', '%s-%s']

        username = self.random.choice(fmt) % (name,
                                              self.random.randint(2, 9999))
        return username.lower()
Exemplo n.º 7
0
    def prefix(self, sign: str = 'positive', symbol: bool = False) -> str:
        """Get a random prefix for the International System of Units (SI)

        :param sign: Sing of number (positive, negative)
        :param bool symbol: Return symbol of prefix.
        :return: Prefix for SI.
        :raises WrongArgument: if sign is not supported.

        :Example:
            mega
        """
        sign = sign.lower()

        prefixes = SI_PREFIXES_SYM if \
            symbol else SI_PREFIXES

        try:
            prefixes = self.random.choice(prefixes[sign])  # type: ignore
            return prefixes  # type: ignore
        except KeyError:
            raise WrongArgument(
                "Unsupported sign. Use: 'positive' or 'negative'")
Exemplo n.º 8
0
    def prefix(self, sign='positive', symbol=False):
        """Get a random prefix for the International System of Units (SI)

        :param sign: Sing of number (positive, negative)
        :param symbol: Return symbol of prefix.
        :return: Prefix for SI.
        :rtype: str
        :Example:
            mega
        """
        sign = sign.lower()

        if symbol:
            prefixes = SI_PREFIXES['_sym_']
        else:
            prefixes = SI_PREFIXES

        try:
            return self.random.choice(prefixes[sign])
        except KeyError:
            raise WrongArgument(
                "Unsupported sign. Use: 'positive' or 'negative'")
Exemplo n.º 9
0
    def username(self, template=None):
        """Generate username by template.

        :param template: Template ('U_d', 'U.d', 'U-d', 'ld', 'l-d', 'Ud',
        'l.d', 'l_d', 'default')
        :return: Username.
        :Example:
            Celloid1873
        """
        name = self.random.choice(USERNAMES)
        date = str(self.random.randint(1800, 2070))

        templates = {
            # UppercaseDate
            'Ud': '{U}{d}'.format(
                U=name.capitalize(),
                d=date,
            ),
            # Uppercase.Date
            'U.d': '{U}.{d}'.format(
                U=name.capitalize(),
                d=date,
            ),
            # lowercaseDate
            'ld': '{l}{d}'.format(
                l=name,
                d=date,
            ),
            # Uppercase-date
            'U-d': '{U}-{d}'.format(
                U=name.title(),
                d=date,
            ),
            # Uppercase_date
            'U_d': '{U}_{d}'.format(
                U=name.title(),
                d=date,
            ),
            # lowercase-date
            'l-d': '{l}-{d}'.format(
                l=name,
                d=date,
            ),
            # lowercase_date
            'l_d': '{l}_{d}'.format(
                l=name,
                d=date,
            ),
            # lowercase.date
            'l.d': '{l}.{d}'.format(
                l=name,
                d=date,
            ),
            # Default is ld
            'default': '{l}{d}'.format(
                l=name,
                d=date,
            ),
        }

        supported = list(templates.keys())

        if template is not None:
            try:
                return templates[template]
            except KeyError:
                raise WrongArgument(
                    'Unsupported template {unsupported}.'
                    'Use one of: {supported}'.format(
                        unsupported=template,
                        supported=', '.join(supported),
                    ), )

        templ = self.random.choice(supported)
        return templates[templ]