当前位置: 首页>>代码示例>>Python>>正文


Python Provider.locale方法代码示例

本文整理汇总了Python中faker.providers.misc.Provider.locale方法的典型用法代码示例。如果您正苦于以下问题:Python Provider.locale方法的具体用法?Python Provider.locale怎么用?Python Provider.locale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在faker.providers.misc.Provider的用法示例。


在下文中一共展示了Provider.locale方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_locale

# 需要导入模块: from faker.providers.misc import Provider [as 别名]
# 或者: from faker.providers.misc.Provider import locale [as 别名]
    def test_locale(self):
        from faker.providers.misc import Provider
        provider = Provider(self.generator)

        for _ in range(99):
            locale = provider.locale()
            self.assertTrue(re.match(r'^[a-z]{2,3}_[A-Z]{2}$', locale))
开发者ID:bessl,项目名称:faker-1,代码行数:9,代码来源:test_factory.py

示例2: firefox

# 需要导入模块: from faker.providers.misc import Provider [as 别名]
# 或者: from faker.providers.misc.Provider import locale [as 别名]
    def firefox(cls):
        ver = (
            'Gecko/{0} Firefox/{1}.0'.format(
                DatetimeProvider.date_time_between(
                    datetime(2011, 1, 1)), random.randint(4, 15)),
            'Gecko/{0} Firefox/3.6.{1}'.format(
                DatetimeProvider.date_time_between(
                    datetime(2010, 1, 1)), random.randint(1, 20)),
            'Gecko/{0} Firefox/3.8'.format(
                DatetimeProvider.date_time_between(
                    datetime(2010, 1, 1)), ),
        )
        tmplt_win = '({0}; {1}; rv:1.9.{2}.20) {3}'
        tmplt_lin = '({0}; rv:1.9.{1}.20) {2}'
        tmplt_mac = '({0}; rv:1.9.{1}.20) {2}'
        platforms = (
            tmplt_win.format(cls.windows_platform_token(),
                             MiscProvider.locale().replace('_', '-'),
                             random.randint(0, 2),
                             random.choice(ver)),
            tmplt_lin.format(cls.linux_platform_token(),
                             random.randint(5, 7),
                             random.choice(ver)),
            tmplt_mac.format(cls.mac_platform_token(),
                             random.randint(2, 6),
                             random.choice(ver)),
        )

        return 'Mozilla/5.0 ' + cls.random_element(platforms)
开发者ID:Stasonhub,项目名称:faker-2,代码行数:31,代码来源:__init__.py

示例3: opera

# 需要导入模块: from faker.providers.misc import Provider [as 别名]
# 或者: from faker.providers.misc.Provider import locale [as 别名]
 def opera(cls):
     platform = '({0}; {1}) Presto/2.9.{2} Version/{3}.00'.format(
         (
             cls.linux_platform_token() if random.getrandbits(1)
             else cls.windows_platform_token()
         ),
         MiscProvider.locale().replace('_', '-'),
         random.randint(160, 190),
         random.randint(10, 12),
     )
     return 'Opera/{0}.{1}.{2}'.format(
         random.randint(8, 9),
         random.randint(10, 99),
         platform,
     )
开发者ID:Stasonhub,项目名称:faker-2,代码行数:17,代码来源:__init__.py

示例4: safari

# 需要导入模块: from faker.providers.misc import Provider [as 别名]
# 或者: from faker.providers.misc.Provider import locale [as 别名]
    def safari(cls):
        saf = "{0}.{1}.{2}".format(random.randint(531, 535),
                                   random.randint(1, 50),
                                   random.randint(1, 7))
        if not random.getrandbits(1):
            ver = "{0}.{1}".format(random.randint(4, 5),
                                   random.randint(0, 1))
        else:
            ver = "{0}.0.{1}".format(random.randint(4, 5),
                                     random.randint(1, 5))
        tmplt_win = '(Windows; U; {0}) AppleWebKit/{1} (KHTML, like Gecko)' \
                    ' Version/{2} Safari/{3}'
        tmplt_mac = '({0} rv:{1}.0; {2}) AppleWebKit/{3} (KHTML, like Gecko)' \
                    ' Version/{4} Safari/{5}'
        tmplt_ipod = '(iPod; U; CPU iPhone OS {0}_{1} like Mac OS X; {2})' \
                     ' AppleWebKit/{3} (KHTML, like Gecko) Version/{4}.0.5' \
                     ' Mobile/8B{5} Safari/6{6}'
        locale = MiscProvider.locale().replace('_', '-')
        platforms = (
            tmplt_win.format(cls.windows_platform_token(),
                             saf,
                             ver,
                             saf),
            tmplt_mac.format(cls.mac_platform_token(),
                             random.randint(2, 6),
                             locale,
                             saf,
                             ver,
                             saf),
            tmplt_ipod.format(random.randint(3, 4),
                              random.randint(0, 3),
                              locale,
                              saf,
                              random.randint(3, 4),
                              random.randint(111, 119),
                              saf),
        )

        return 'Mozilla/5.0 ' + cls.random_element(platforms)
开发者ID:Stasonhub,项目名称:faker-2,代码行数:41,代码来源:__init__.py


注:本文中的faker.providers.misc.Provider.locale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。