We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
uuid4 should return UUID instead of str
__Context__: I'm using faker in combination with [FactoryBoy](https://github.com/FactoryBoy/factory_boy) to test [Django](https://www.djangoproject.com/) models. I have this test to make sure some data dict generated from model data is JSON-serializable. The test passed, but not the code in production. (`Object of type UUID is not JSON serializable`).

Now, of course the fix to the offending code is simple:

``` diff
- data['uuid'] = model.uuid
+ data['uuid'] = str(model.uuid)
```

but the problem is two-fold:

1. __The fact that `uuid4` returns `str` is confusing__. I didn't pay attention and couldn't test properly.
2. __There is no provider for actual `UUID` objects__. I can understand if some people want strings that are in fact uuid representations, after all that's [how AutoFixture generates strings](https://github.com/AutoFixture/AutoFixture/wiki/Cheat-Sheet#completely-autogenerated-string) (Autofixture does approximately the same job as faker, but for C#). But there should be a provider for true `UUID`s as well.

### Steps to reproduce

1. Call `fake.uuid4()`

### Expected behavior

`fake.uuid4()` should return an `UUID` object

### Actual behavior

`fake.uuid4()` returns a `str`


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `faker/providers/misc/__init__.py`
Content:
```
1 # coding=utf-8
2 
3 from __future__ import unicode_literals
4 import hashlib
5 import string
6 import uuid
7 import sys
8 
9 from .. import BaseProvider
10 
11 
12 class Provider(BaseProvider):
13     # Locales supported by Linux Mint from `/usr/share/i18n/SUPPORTED`
14     language_locale_codes = {
15         'aa': ('DJ', 'ER', 'ET'), 'af': ('ZA',), 'ak': ('GH',), 'am': ('ET',),
16         'an': ('ES',), 'apn': ('IN',),
17         'ar': ('AE', 'BH', 'DJ', 'DZ', 'EG', 'EH', 'ER', 'IL', 'IN',
18                'IQ', 'JO', 'KM', 'KW', 'LB', 'LY', 'MA', 'MR', 'OM',
19                'PS', 'QA', 'SA', 'SD', 'SO', 'SS', 'SY', 'TD', 'TN',
20                'YE'),
21         'as': ('IN',), 'ast': ('ES',), 'ayc': ('PE',), 'az': ('AZ', 'IN'),
22         'be': ('BY',), 'bem': ('ZM',), 'ber': ('DZ', 'MA'), 'bg': ('BG',),
23         'bhb': ('IN',), 'bho': ('IN',), 'bn': ('BD', 'IN'), 'bo': ('CN', 'IN'),
24         'br': ('FR',), 'brx': ('IN',), 'bs': ('BA',), 'byn': ('ER',),
25         'ca': ('AD', 'ES', 'FR', 'IT'), 'ce': ('RU',), 'ckb': ('IQ',),
26         'cmn': ('TW',), 'crh': ('UA',), 'cs': ('CZ',), 'csb': ('PL',),
27         'cv': ('RU',), 'cy': ('GB',), 'da': ('DK',),
28         'de': ('AT', 'BE', 'CH', 'DE', 'LI', 'LU'), 'doi': ('IN',),
29         'dv': ('MV',), 'dz': ('BT',), 'el': ('GR', 'CY'),
30         'en': ('AG', 'AU', 'BW', 'CA', 'DK', 'GB', 'HK', 'IE', 'IN', 'NG',
31                'NZ', 'PH', 'SG', 'US', 'ZA', 'ZM', 'ZW'),
32         'eo': ('US',),
33         'es': ('AR', 'BO', 'CL', 'CO', 'CR', 'CU', 'DO', 'EC', 'ES', 'GT',
34                'HN', 'MX', 'NI', 'PA', 'PE', 'PR', 'PY', 'SV', 'US', 'UY', 'VE',
35                ), 'et': ('EE',), 'eu': ('ES', 'FR'), 'fa': ('IR',),
36         'ff': ('SN',), 'fi': ('FI',), 'fil': ('PH',), 'fo': ('FO',),
37         'fr': ('CA', 'CH', 'FR', 'LU'), 'fur': ('IT',), 'fy': ('NL', 'DE'),
38         'ga': ('IE',), 'gd': ('GB',), 'gez': ('ER', 'ET'), 'gl': ('ES',),
39         'gu': ('IN',), 'gv': ('GB',), 'ha': ('NG',), 'hak': ('TW',),
40         'he': ('IL',), 'hi': ('IN',), 'hne': ('IN',), 'hr': ('HR',),
41         'hsb': ('DE',), 'ht': ('HT',), 'hu': ('HU',), 'hy': ('AM',),
42         'ia': ('FR',), 'id': ('ID',), 'ig': ('NG',), 'ik': ('CA',),
43         'is': ('IS',), 'it': ('CH', 'IT'), 'iu': ('CA',), 'iw': ('IL',),
44         'ja': ('JP',), 'ka': ('GE',), 'kk': ('KZ',), 'kl': ('GL',),
45         'km': ('KH',), 'kn': ('IN',), 'ko': ('KR',), 'kok': ('IN',),
46         'ks': ('IN',), 'ku': ('TR',), 'kw': ('GB',), 'ky': ('KG',),
47         'lb': ('LU',), 'lg': ('UG',), 'li': ('BE', 'NL'), 'lij': ('IT',),
48         'ln': ('CD',), 'lo': ('LA',), 'lt': ('LT',), 'lv': ('LV',),
49         'lzh': ('TW',), 'mag': ('IN',), 'mai': ('IN',), 'mg': ('MG',),
50         'mhr': ('RU',), 'mi': ('NZ',), 'mk': ('MK',), 'ml': ('IN',),
51         'mn': ('MN',), 'mni': ('IN',), 'mr': ('IN',), 'ms': ('MY',),
52         'mt': ('MT',), 'my': ('MM',), 'nan': ('TW',), 'nb': ('NO',),
53         'nds': ('DE', 'NL'), 'ne': ('NP',), 'nhn': ('MX',),
54         'niu': ('NU', 'NZ'), 'nl': ('AW', 'BE', 'NL'), 'nn': ('NO',),
55         'nr': ('ZA',), 'nso': ('ZA',), 'oc': ('FR',), 'om': ('ET', 'KE'),
56         'or': ('IN',), 'os': ('RU',), 'pa': ('IN', 'PK'),
57         'pap': ('AN', 'AW', 'CW'), 'pl': ('PL',), 'ps': ('AF',),
58         'pt': ('BR', 'PT'), 'quz': ('PE',), 'raj': ('IN',), 'ro': ('RO',),
59         'ru': ('RU', 'UA'), 'rw': ('RW',), 'sa': ('IN',), 'sat': ('IN',),
60         'sc': ('IT',), 'sd': ('IN', 'PK'), 'se': ('NO',), 'shs': ('CA',),
61         'si': ('LK',), 'sid': ('ET',), 'sk': ('SK',), 'sl': ('SI',),
62         'so': ('DJ', 'ET', 'KE', 'SO'), 'sq': ('AL', 'ML'), 'sr': ('ME', 'RS'),
63         'ss': ('ZA',), 'st': ('ZA',), 'sv': ('FI', 'SE'), 'sw': ('KE', 'TZ'),
64         'szl': ('PL',), 'ta': ('IN', 'LK'), 'tcy': ('IN',), 'te': ('IN',),
65         'tg': ('TJ',), 'th': ('TH',), 'the': ('NP',), 'ti': ('ER', 'ET'),
66         'tig': ('ER',), 'tk': ('TM',), 'tl': ('PH',), 'tn': ('ZA',),
67         'tr': ('CY', 'TR'), 'ts': ('ZA',), 'tt': ('RU',), 'ug': ('CN',),
68         'uk': ('UA',), 'unm': ('US',), 'ur': ('IN', 'PK'), 'uz': ('UZ',),
69         've': ('ZA',), 'vi': ('VN',), 'wa': ('BE',), 'wae': ('CH',),
70         'wal': ('ET',), 'wo': ('SN',), 'xh': ('ZA',), 'yi': ('US',),
71         'yo': ('NG',), 'yue': ('HK',), 'zh': ('CN', 'HK', 'SG', 'TW'),
72         'zu': ('ZA',),
73     }
74 
75     def boolean(self, chance_of_getting_true=50):
76         return self.generator.random.randint(1, 100) <= chance_of_getting_true
77 
78     def null_boolean(self):
79         return {
80             0: None,
81             1: True,
82             -1: False,
83         }[self.generator.random.randint(-1, 1)]
84 
85     def binary(self, length=(1 * 1024 * 1024)):
86         """ Returns random binary blob.
87 
88         Default blob size is 1 Mb.
89         """
90         blob = [self.generator.random.randrange(256) for _ in range(length)]
91         return bytes(blob) if sys.version_info[0] >= 3 else bytearray(blob)
92 
93     def md5(self, raw_output=False):
94         """
95         Calculates the md5 hash of a given string
96         :example 'cfcd208495d565ef66e7dff9f98764da'
97         """
98         res = hashlib.md5(str(self.generator.random.random()).encode('utf-8'))
99         if raw_output:
100             return res.digest()
101         return res.hexdigest()
102 
103     def sha1(self, raw_output=False):
104         """
105         Calculates the sha1 hash of a given string
106         :example 'b5d86317c2a144cd04d0d7c03b2b02666fafadf2'
107         """
108         res = hashlib.sha1(str(self.generator.random.random()).encode('utf-8'))
109         if raw_output:
110             return res.digest()
111         return res.hexdigest()
112 
113     def sha256(self, raw_output=False):
114         """
115         Calculates the sha256 hash of a given string
116         :example '85086017559ccc40638fcde2fecaf295e0de7ca51b7517b6aebeaaf75b4d4654'
117         """
118         res = hashlib.sha256(
119             str(self.generator.random.random()).encode('utf-8'))
120         if raw_output:
121             return res.digest()
122         return res.hexdigest()
123 
124     def locale(self):
125         language_code = self.language_code()
126         return language_code + '_' + self.random_element(
127             Provider.language_locale_codes[language_code],
128         )
129 
130     def language_code(self):
131         return self.random_element(Provider.language_locale_codes.keys())
132 
133     def uuid4(self):
134         """
135         Generates a random UUID4 string.
136         """
137         # Based on http://stackoverflow.com/q/41186818
138         return str(uuid.UUID(int=self.generator.random.getrandbits(128)))
139 
140     def password(
141             self,
142             length=10,
143             special_chars=True,
144             digits=True,
145             upper_case=True,
146             lower_case=True):
147         """
148         Generates a random password.
149         @param length: Integer. Length of a password
150         @param special_chars: Boolean. Whether to use special characters !@#$%^&*()_+
151         @param digits: Boolean. Whether to use digits
152         @param upper_case: Boolean. Whether to use upper letters
153         @param lower_case: Boolean. Whether to use lower letters
154         @return: String. Random password
155         """
156         choices = ""
157         required_tokens = []
158         if special_chars:
159             required_tokens.append(
160                 self.generator.random.choice("!@#$%^&*()_+"))
161             choices += "!@#$%^&*()_+"
162         if digits:
163             required_tokens.append(self.generator.random.choice(string.digits))
164             choices += string.digits
165         if upper_case:
166             required_tokens.append(
167                 self.generator.random.choice(string.ascii_uppercase))
168             choices += string.ascii_uppercase
169         if lower_case:
170             required_tokens.append(
171                 self.generator.random.choice(string.ascii_lowercase))
172             choices += string.ascii_lowercase
173 
174         assert len(
175             required_tokens) <= length, "Required length is shorter than required characters"
176 
177         # Generate a first version of the password
178         chars = self.random_choices(choices, length=length)
179 
180         # Pick some unique locations
181         random_indexes = set()
182         while len(random_indexes) < len(required_tokens):
183             random_indexes.add(
184                 self.generator.random.randint(0, len(chars) - 1))
185 
186         # Replace them with the required characters
187         for i, index in enumerate(random_indexes):
188             chars[index] = required_tokens[i]
189 
190         return ''.join(chars)
191
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/faker/providers/misc/__init__.py b/faker/providers/misc/__init__.py
--- a/faker/providers/misc/__init__.py
+++ b/faker/providers/misc/__init__.py
@@ -130,12 +130,14 @@
     def language_code(self):
         return self.random_element(Provider.language_locale_codes.keys())
 
-    def uuid4(self):
+    def uuid4(self, cast_to=str):
         """
         Generates a random UUID4 string.
+        :param cast_to: Specify what type the UUID should be cast to. Default is `str`
+        :type cast_to: callable
         """
         # Based on http://stackoverflow.com/q/41186818
-        return str(uuid.UUID(int=self.generator.random.getrandbits(128)))
+        return cast_to(uuid.UUID(int=self.generator.random.getrandbits(128), version=4))
 
     def password(
             self,

{"golden_diff": "diff --git a/faker/providers/misc/__init__.py b/faker/providers/misc/__init__.py\n--- a/faker/providers/misc/__init__.py\n+++ b/faker/providers/misc/__init__.py\n@@ -130,12 +130,14 @@\n     def language_code(self):\n         return self.random_element(Provider.language_locale_codes.keys())\n \n-    def uuid4(self):\n+    def uuid4(self, cast_to=str):\n         \"\"\"\n         Generates a random UUID4 string.\n+        :param cast_to: Specify what type the UUID should be cast to. Default is `str`\n+        :type cast_to: callable\n         \"\"\"\n         # Based on http://stackoverflow.com/q/41186818\n-        return str(uuid.UUID(int=self.generator.random.getrandbits(128)))\n+        return cast_to(uuid.UUID(int=self.generator.random.getrandbits(128), version=4))\n \n     def password(\n             self,\n", "issue": "uuid4 should return UUID instead of str\n__Context__: I'm using faker in combination with [FactoryBoy](https://github.com/FactoryBoy/factory_boy) to test [Django](https://www.djangoproject.com/) models. I have this test to make sure some data dict generated from model data is JSON-serializable. The test passed, but not the code in production. (`Object of type UUID is not JSON serializable`).\r\n\r\nNow, of course the fix to the offending code is simple:\r\n\r\n``` diff\r\n- data['uuid'] = model.uuid\r\n+ data['uuid'] = str(model.uuid)\r\n```\r\n\r\nbut the problem is two-fold:\r\n\r\n1. __The fact that `uuid4` returns `str` is confusing__. I didn't pay attention and couldn't test properly.\r\n2. __There is no provider for actual `UUID` objects__. I can understand if some people want strings that are in fact uuid representations, after all that's [how AutoFixture generates strings](https://github.com/AutoFixture/AutoFixture/wiki/Cheat-Sheet#completely-autogenerated-string) (Autofixture does approximately the same job as faker, but for C#). But there should be a provider for true `UUID`s as well.\r\n\r\n### Steps to reproduce\r\n\r\n1. Call `fake.uuid4()`\r\n\r\n### Expected behavior\r\n\r\n`fake.uuid4()` should return an `UUID` object\r\n\r\n### Actual behavior\r\n\r\n`fake.uuid4()` returns a `str`\r\n\n", "before_files": [{"content": "# coding=utf-8\n\nfrom __future__ import unicode_literals\nimport hashlib\nimport string\nimport uuid\nimport sys\n\nfrom .. import BaseProvider\n\n\nclass Provider(BaseProvider):\n    # Locales supported by Linux Mint from `/usr/share/i18n/SUPPORTED`\n    language_locale_codes = {\n        'aa': ('DJ', 'ER', 'ET'), 'af': ('ZA',), 'ak': ('GH',), 'am': ('ET',),\n        'an': ('ES',), 'apn': ('IN',),\n        'ar': ('AE', 'BH', 'DJ', 'DZ', 'EG', 'EH', 'ER', 'IL', 'IN',\n               'IQ', 'JO', 'KM', 'KW', 'LB', 'LY', 'MA', 'MR', 'OM',\n               'PS', 'QA', 'SA', 'SD', 'SO', 'SS', 'SY', 'TD', 'TN',\n               'YE'),\n        'as': ('IN',), 'ast': ('ES',), 'ayc': ('PE',), 'az': ('AZ', 'IN'),\n        'be': ('BY',), 'bem': ('ZM',), 'ber': ('DZ', 'MA'), 'bg': ('BG',),\n        'bhb': ('IN',), 'bho': ('IN',), 'bn': ('BD', 'IN'), 'bo': ('CN', 'IN'),\n        'br': ('FR',), 'brx': ('IN',), 'bs': ('BA',), 'byn': ('ER',),\n        'ca': ('AD', 'ES', 'FR', 'IT'), 'ce': ('RU',), 'ckb': ('IQ',),\n        'cmn': ('TW',), 'crh': ('UA',), 'cs': ('CZ',), 'csb': ('PL',),\n        'cv': ('RU',), 'cy': ('GB',), 'da': ('DK',),\n        'de': ('AT', 'BE', 'CH', 'DE', 'LI', 'LU'), 'doi': ('IN',),\n        'dv': ('MV',), 'dz': ('BT',), 'el': ('GR', 'CY'),\n        'en': ('AG', 'AU', 'BW', 'CA', 'DK', 'GB', 'HK', 'IE', 'IN', 'NG',\n               'NZ', 'PH', 'SG', 'US', 'ZA', 'ZM', 'ZW'),\n        'eo': ('US',),\n        'es': ('AR', 'BO', 'CL', 'CO', 'CR', 'CU', 'DO', 'EC', 'ES', 'GT',\n               'HN', 'MX', 'NI', 'PA', 'PE', 'PR', 'PY', 'SV', 'US', 'UY', 'VE',\n               ), 'et': ('EE',), 'eu': ('ES', 'FR'), 'fa': ('IR',),\n        'ff': ('SN',), 'fi': ('FI',), 'fil': ('PH',), 'fo': ('FO',),\n        'fr': ('CA', 'CH', 'FR', 'LU'), 'fur': ('IT',), 'fy': ('NL', 'DE'),\n        'ga': ('IE',), 'gd': ('GB',), 'gez': ('ER', 'ET'), 'gl': ('ES',),\n        'gu': ('IN',), 'gv': ('GB',), 'ha': ('NG',), 'hak': ('TW',),\n        'he': ('IL',), 'hi': ('IN',), 'hne': ('IN',), 'hr': ('HR',),\n        'hsb': ('DE',), 'ht': ('HT',), 'hu': ('HU',), 'hy': ('AM',),\n        'ia': ('FR',), 'id': ('ID',), 'ig': ('NG',), 'ik': ('CA',),\n        'is': ('IS',), 'it': ('CH', 'IT'), 'iu': ('CA',), 'iw': ('IL',),\n        'ja': ('JP',), 'ka': ('GE',), 'kk': ('KZ',), 'kl': ('GL',),\n        'km': ('KH',), 'kn': ('IN',), 'ko': ('KR',), 'kok': ('IN',),\n        'ks': ('IN',), 'ku': ('TR',), 'kw': ('GB',), 'ky': ('KG',),\n        'lb': ('LU',), 'lg': ('UG',), 'li': ('BE', 'NL'), 'lij': ('IT',),\n        'ln': ('CD',), 'lo': ('LA',), 'lt': ('LT',), 'lv': ('LV',),\n        'lzh': ('TW',), 'mag': ('IN',), 'mai': ('IN',), 'mg': ('MG',),\n        'mhr': ('RU',), 'mi': ('NZ',), 'mk': ('MK',), 'ml': ('IN',),\n        'mn': ('MN',), 'mni': ('IN',), 'mr': ('IN',), 'ms': ('MY',),\n        'mt': ('MT',), 'my': ('MM',), 'nan': ('TW',), 'nb': ('NO',),\n        'nds': ('DE', 'NL'), 'ne': ('NP',), 'nhn': ('MX',),\n        'niu': ('NU', 'NZ'), 'nl': ('AW', 'BE', 'NL'), 'nn': ('NO',),\n        'nr': ('ZA',), 'nso': ('ZA',), 'oc': ('FR',), 'om': ('ET', 'KE'),\n        'or': ('IN',), 'os': ('RU',), 'pa': ('IN', 'PK'),\n        'pap': ('AN', 'AW', 'CW'), 'pl': ('PL',), 'ps': ('AF',),\n        'pt': ('BR', 'PT'), 'quz': ('PE',), 'raj': ('IN',), 'ro': ('RO',),\n        'ru': ('RU', 'UA'), 'rw': ('RW',), 'sa': ('IN',), 'sat': ('IN',),\n        'sc': ('IT',), 'sd': ('IN', 'PK'), 'se': ('NO',), 'shs': ('CA',),\n        'si': ('LK',), 'sid': ('ET',), 'sk': ('SK',), 'sl': ('SI',),\n        'so': ('DJ', 'ET', 'KE', 'SO'), 'sq': ('AL', 'ML'), 'sr': ('ME', 'RS'),\n        'ss': ('ZA',), 'st': ('ZA',), 'sv': ('FI', 'SE'), 'sw': ('KE', 'TZ'),\n        'szl': ('PL',), 'ta': ('IN', 'LK'), 'tcy': ('IN',), 'te': ('IN',),\n        'tg': ('TJ',), 'th': ('TH',), 'the': ('NP',), 'ti': ('ER', 'ET'),\n        'tig': ('ER',), 'tk': ('TM',), 'tl': ('PH',), 'tn': ('ZA',),\n        'tr': ('CY', 'TR'), 'ts': ('ZA',), 'tt': ('RU',), 'ug': ('CN',),\n        'uk': ('UA',), 'unm': ('US',), 'ur': ('IN', 'PK'), 'uz': ('UZ',),\n        've': ('ZA',), 'vi': ('VN',), 'wa': ('BE',), 'wae': ('CH',),\n        'wal': ('ET',), 'wo': ('SN',), 'xh': ('ZA',), 'yi': ('US',),\n        'yo': ('NG',), 'yue': ('HK',), 'zh': ('CN', 'HK', 'SG', 'TW'),\n        'zu': ('ZA',),\n    }\n\n    def boolean(self, chance_of_getting_true=50):\n        return self.generator.random.randint(1, 100) <= chance_of_getting_true\n\n    def null_boolean(self):\n        return {\n            0: None,\n            1: True,\n            -1: False,\n        }[self.generator.random.randint(-1, 1)]\n\n    def binary(self, length=(1 * 1024 * 1024)):\n        \"\"\" Returns random binary blob.\n\n        Default blob size is 1 Mb.\n        \"\"\"\n        blob = [self.generator.random.randrange(256) for _ in range(length)]\n        return bytes(blob) if sys.version_info[0] >= 3 else bytearray(blob)\n\n    def md5(self, raw_output=False):\n        \"\"\"\n        Calculates the md5 hash of a given string\n        :example 'cfcd208495d565ef66e7dff9f98764da'\n        \"\"\"\n        res = hashlib.md5(str(self.generator.random.random()).encode('utf-8'))\n        if raw_output:\n            return res.digest()\n        return res.hexdigest()\n\n    def sha1(self, raw_output=False):\n        \"\"\"\n        Calculates the sha1 hash of a given string\n        :example 'b5d86317c2a144cd04d0d7c03b2b02666fafadf2'\n        \"\"\"\n        res = hashlib.sha1(str(self.generator.random.random()).encode('utf-8'))\n        if raw_output:\n            return res.digest()\n        return res.hexdigest()\n\n    def sha256(self, raw_output=False):\n        \"\"\"\n        Calculates the sha256 hash of a given string\n        :example '85086017559ccc40638fcde2fecaf295e0de7ca51b7517b6aebeaaf75b4d4654'\n        \"\"\"\n        res = hashlib.sha256(\n            str(self.generator.random.random()).encode('utf-8'))\n        if raw_output:\n            return res.digest()\n        return res.hexdigest()\n\n    def locale(self):\n        language_code = self.language_code()\n        return language_code + '_' + self.random_element(\n            Provider.language_locale_codes[language_code],\n        )\n\n    def language_code(self):\n        return self.random_element(Provider.language_locale_codes.keys())\n\n    def uuid4(self):\n        \"\"\"\n        Generates a random UUID4 string.\n        \"\"\"\n        # Based on http://stackoverflow.com/q/41186818\n        return str(uuid.UUID(int=self.generator.random.getrandbits(128)))\n\n    def password(\n            self,\n            length=10,\n            special_chars=True,\n            digits=True,\n            upper_case=True,\n            lower_case=True):\n        \"\"\"\n        Generates a random password.\n        @param length: Integer. Length of a password\n        @param special_chars: Boolean. Whether to use special characters !@#$%^&*()_+\n        @param digits: Boolean. Whether to use digits\n        @param upper_case: Boolean. Whether to use upper letters\n        @param lower_case: Boolean. Whether to use lower letters\n        @return: String. Random password\n        \"\"\"\n        choices = \"\"\n        required_tokens = []\n        if special_chars:\n            required_tokens.append(\n                self.generator.random.choice(\"!@#$%^&*()_+\"))\n            choices += \"!@#$%^&*()_+\"\n        if digits:\n            required_tokens.append(self.generator.random.choice(string.digits))\n            choices += string.digits\n        if upper_case:\n            required_tokens.append(\n                self.generator.random.choice(string.ascii_uppercase))\n            choices += string.ascii_uppercase\n        if lower_case:\n            required_tokens.append(\n                self.generator.random.choice(string.ascii_lowercase))\n            choices += string.ascii_lowercase\n\n        assert len(\n            required_tokens) <= length, \"Required length is shorter than required characters\"\n\n        # Generate a first version of the password\n        chars = self.random_choices(choices, length=length)\n\n        # Pick some unique locations\n        random_indexes = set()\n        while len(random_indexes) < len(required_tokens):\n            random_indexes.add(\n                self.generator.random.randint(0, len(chars) - 1))\n\n        # Replace them with the required characters\n        for i, index in enumerate(random_indexes):\n            chars[index] = required_tokens[i]\n\n        return ''.join(chars)\n", "path": "faker/providers/misc/__init__.py"}], "after_files": [{"content": "# coding=utf-8\n\nfrom __future__ import unicode_literals\nimport hashlib\nimport string\nimport uuid\nimport sys\n\nfrom .. import BaseProvider\n\n\nclass Provider(BaseProvider):\n    # Locales supported by Linux Mint from `/usr/share/i18n/SUPPORTED`\n    language_locale_codes = {\n        'aa': ('DJ', 'ER', 'ET'), 'af': ('ZA',), 'ak': ('GH',), 'am': ('ET',),\n        'an': ('ES',), 'apn': ('IN',),\n        'ar': ('AE', 'BH', 'DJ', 'DZ', 'EG', 'EH', 'ER', 'IL', 'IN',\n               'IQ', 'JO', 'KM', 'KW', 'LB', 'LY', 'MA', 'MR', 'OM',\n               'PS', 'QA', 'SA', 'SD', 'SO', 'SS', 'SY', 'TD', 'TN',\n               'YE'),\n        'as': ('IN',), 'ast': ('ES',), 'ayc': ('PE',), 'az': ('AZ', 'IN'),\n        'be': ('BY',), 'bem': ('ZM',), 'ber': ('DZ', 'MA'), 'bg': ('BG',),\n        'bhb': ('IN',), 'bho': ('IN',), 'bn': ('BD', 'IN'), 'bo': ('CN', 'IN'),\n        'br': ('FR',), 'brx': ('IN',), 'bs': ('BA',), 'byn': ('ER',),\n        'ca': ('AD', 'ES', 'FR', 'IT'), 'ce': ('RU',), 'ckb': ('IQ',),\n        'cmn': ('TW',), 'crh': ('UA',), 'cs': ('CZ',), 'csb': ('PL',),\n        'cv': ('RU',), 'cy': ('GB',), 'da': ('DK',),\n        'de': ('AT', 'BE', 'CH', 'DE', 'LI', 'LU'), 'doi': ('IN',),\n        'dv': ('MV',), 'dz': ('BT',), 'el': ('GR', 'CY'),\n        'en': ('AG', 'AU', 'BW', 'CA', 'DK', 'GB', 'HK', 'IE', 'IN', 'NG',\n               'NZ', 'PH', 'SG', 'US', 'ZA', 'ZM', 'ZW'),\n        'eo': ('US',),\n        'es': ('AR', 'BO', 'CL', 'CO', 'CR', 'CU', 'DO', 'EC', 'ES', 'GT',\n               'HN', 'MX', 'NI', 'PA', 'PE', 'PR', 'PY', 'SV', 'US', 'UY', 'VE',\n               ), 'et': ('EE',), 'eu': ('ES', 'FR'), 'fa': ('IR',),\n        'ff': ('SN',), 'fi': ('FI',), 'fil': ('PH',), 'fo': ('FO',),\n        'fr': ('CA', 'CH', 'FR', 'LU'), 'fur': ('IT',), 'fy': ('NL', 'DE'),\n        'ga': ('IE',), 'gd': ('GB',), 'gez': ('ER', 'ET'), 'gl': ('ES',),\n        'gu': ('IN',), 'gv': ('GB',), 'ha': ('NG',), 'hak': ('TW',),\n        'he': ('IL',), 'hi': ('IN',), 'hne': ('IN',), 'hr': ('HR',),\n        'hsb': ('DE',), 'ht': ('HT',), 'hu': ('HU',), 'hy': ('AM',),\n        'ia': ('FR',), 'id': ('ID',), 'ig': ('NG',), 'ik': ('CA',),\n        'is': ('IS',), 'it': ('CH', 'IT'), 'iu': ('CA',), 'iw': ('IL',),\n        'ja': ('JP',), 'ka': ('GE',), 'kk': ('KZ',), 'kl': ('GL',),\n        'km': ('KH',), 'kn': ('IN',), 'ko': ('KR',), 'kok': ('IN',),\n        'ks': ('IN',), 'ku': ('TR',), 'kw': ('GB',), 'ky': ('KG',),\n        'lb': ('LU',), 'lg': ('UG',), 'li': ('BE', 'NL'), 'lij': ('IT',),\n        'ln': ('CD',), 'lo': ('LA',), 'lt': ('LT',), 'lv': ('LV',),\n        'lzh': ('TW',), 'mag': ('IN',), 'mai': ('IN',), 'mg': ('MG',),\n        'mhr': ('RU',), 'mi': ('NZ',), 'mk': ('MK',), 'ml': ('IN',),\n        'mn': ('MN',), 'mni': ('IN',), 'mr': ('IN',), 'ms': ('MY',),\n        'mt': ('MT',), 'my': ('MM',), 'nan': ('TW',), 'nb': ('NO',),\n        'nds': ('DE', 'NL'), 'ne': ('NP',), 'nhn': ('MX',),\n        'niu': ('NU', 'NZ'), 'nl': ('AW', 'BE', 'NL'), 'nn': ('NO',),\n        'nr': ('ZA',), 'nso': ('ZA',), 'oc': ('FR',), 'om': ('ET', 'KE'),\n        'or': ('IN',), 'os': ('RU',), 'pa': ('IN', 'PK'),\n        'pap': ('AN', 'AW', 'CW'), 'pl': ('PL',), 'ps': ('AF',),\n        'pt': ('BR', 'PT'), 'quz': ('PE',), 'raj': ('IN',), 'ro': ('RO',),\n        'ru': ('RU', 'UA'), 'rw': ('RW',), 'sa': ('IN',), 'sat': ('IN',),\n        'sc': ('IT',), 'sd': ('IN', 'PK'), 'se': ('NO',), 'shs': ('CA',),\n        'si': ('LK',), 'sid': ('ET',), 'sk': ('SK',), 'sl': ('SI',),\n        'so': ('DJ', 'ET', 'KE', 'SO'), 'sq': ('AL', 'ML'), 'sr': ('ME', 'RS'),\n        'ss': ('ZA',), 'st': ('ZA',), 'sv': ('FI', 'SE'), 'sw': ('KE', 'TZ'),\n        'szl': ('PL',), 'ta': ('IN', 'LK'), 'tcy': ('IN',), 'te': ('IN',),\n        'tg': ('TJ',), 'th': ('TH',), 'the': ('NP',), 'ti': ('ER', 'ET'),\n        'tig': ('ER',), 'tk': ('TM',), 'tl': ('PH',), 'tn': ('ZA',),\n        'tr': ('CY', 'TR'), 'ts': ('ZA',), 'tt': ('RU',), 'ug': ('CN',),\n        'uk': ('UA',), 'unm': ('US',), 'ur': ('IN', 'PK'), 'uz': ('UZ',),\n        've': ('ZA',), 'vi': ('VN',), 'wa': ('BE',), 'wae': ('CH',),\n        'wal': ('ET',), 'wo': ('SN',), 'xh': ('ZA',), 'yi': ('US',),\n        'yo': ('NG',), 'yue': ('HK',), 'zh': ('CN', 'HK', 'SG', 'TW'),\n        'zu': ('ZA',),\n    }\n\n    def boolean(self, chance_of_getting_true=50):\n        return self.generator.random.randint(1, 100) <= chance_of_getting_true\n\n    def null_boolean(self):\n        return {\n            0: None,\n            1: True,\n            -1: False,\n        }[self.generator.random.randint(-1, 1)]\n\n    def binary(self, length=(1 * 1024 * 1024)):\n        \"\"\" Returns random binary blob.\n\n        Default blob size is 1 Mb.\n        \"\"\"\n        blob = [self.generator.random.randrange(256) for _ in range(length)]\n        return bytes(blob) if sys.version_info[0] >= 3 else bytearray(blob)\n\n    def md5(self, raw_output=False):\n        \"\"\"\n        Calculates the md5 hash of a given string\n        :example 'cfcd208495d565ef66e7dff9f98764da'\n        \"\"\"\n        res = hashlib.md5(str(self.generator.random.random()).encode('utf-8'))\n        if raw_output:\n            return res.digest()\n        return res.hexdigest()\n\n    def sha1(self, raw_output=False):\n        \"\"\"\n        Calculates the sha1 hash of a given string\n        :example 'b5d86317c2a144cd04d0d7c03b2b02666fafadf2'\n        \"\"\"\n        res = hashlib.sha1(str(self.generator.random.random()).encode('utf-8'))\n        if raw_output:\n            return res.digest()\n        return res.hexdigest()\n\n    def sha256(self, raw_output=False):\n        \"\"\"\n        Calculates the sha256 hash of a given string\n        :example '85086017559ccc40638fcde2fecaf295e0de7ca51b7517b6aebeaaf75b4d4654'\n        \"\"\"\n        res = hashlib.sha256(\n            str(self.generator.random.random()).encode('utf-8'))\n        if raw_output:\n            return res.digest()\n        return res.hexdigest()\n\n    def locale(self):\n        language_code = self.language_code()\n        return language_code + '_' + self.random_element(\n            Provider.language_locale_codes[language_code],\n        )\n\n    def language_code(self):\n        return self.random_element(Provider.language_locale_codes.keys())\n\n    def uuid4(self, cast_to=str):\n        \"\"\"\n        Generates a random UUID4 string.\n        :param cast_to: Specify what type the UUID should be cast to. Default is `str`\n        :type cast_to: callable\n        \"\"\"\n        # Based on http://stackoverflow.com/q/41186818\n        return cast_to(uuid.UUID(int=self.generator.random.getrandbits(128), version=4))\n\n    def password(\n            self,\n            length=10,\n            special_chars=True,\n            digits=True,\n            upper_case=True,\n            lower_case=True):\n        \"\"\"\n        Generates a random password.\n        @param length: Integer. Length of a password\n        @param special_chars: Boolean. Whether to use special characters !@#$%^&*()_+\n        @param digits: Boolean. Whether to use digits\n        @param upper_case: Boolean. Whether to use upper letters\n        @param lower_case: Boolean. Whether to use lower letters\n        @return: String. Random password\n        \"\"\"\n        choices = \"\"\n        required_tokens = []\n        if special_chars:\n            required_tokens.append(\n                self.generator.random.choice(\"!@#$%^&*()_+\"))\n            choices += \"!@#$%^&*()_+\"\n        if digits:\n            required_tokens.append(self.generator.random.choice(string.digits))\n            choices += string.digits\n        if upper_case:\n            required_tokens.append(\n                self.generator.random.choice(string.ascii_uppercase))\n            choices += string.ascii_uppercase\n        if lower_case:\n            required_tokens.append(\n                self.generator.random.choice(string.ascii_lowercase))\n            choices += string.ascii_lowercase\n\n        assert len(\n            required_tokens) <= length, \"Required length is shorter than required characters\"\n\n        # Generate a first version of the password\n        chars = self.random_choices(choices, length=length)\n\n        # Pick some unique locations\n        random_indexes = set()\n        while len(random_indexes) < len(required_tokens):\n            random_indexes.add(\n                self.generator.random.randint(0, len(chars) - 1))\n\n        # Replace them with the required characters\n        for i, index in enumerate(random_indexes):\n            chars[index] = required_tokens[i]\n\n        return ''.join(chars)\n", "path": "faker/providers/misc/__init__.py"}]}