Skip to content

Commit 36952a6

Browse files
committed
Converted some of the README lines from the last PR to use docstring-like conventions
1 parent a97dc6e commit 36952a6

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,31 @@ If you're system doesn't allow installing `cryptography` like on Google App Engi
2727
## Usage
2828

2929
```python
30-
import jwt
31-
encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
32-
# 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'
30+
>>> import jwt
31+
>>> encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
32+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'
3333
```
3434

3535
Additional headers may also be specified.
3636

3737
```python
38-
jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256', headers={'kid': '230498151c214b788dd97f22b85410a5'})
39-
# 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjIzMDQ5ODE1MWMyMTRiNzg4ZGQ5N2YyMmI4NTQxMGE1In0.eyJzb21lIjoicGF5bG9hZCJ9.DogbDGmMHgA_bU05TAB-R6geQ2nMU2BRM-LnYEtefwg'
38+
>>> jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256', headers={'kid': '230498151c214b788dd97f22b85410a5'})
39+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjIzMDQ5ODE1MWMyMTRiNzg4ZGQ5N2YyMmI4NTQxMGE1In0.eyJzb21lIjoicGF5bG9hZCJ9.DogbDGmMHgA_bU05TAB-R6geQ2nMU2BRM-LnYEtefwg'
4040
```
4141

4242
Note the resulting JWT will not be encrypted, but verifiable with a secret key.
4343

4444
```python
45-
jwt.decode(encoded, 'secret', algorithms=['HS256'])
46-
# {u'some': u'payload'}
45+
>>> jwt.decode(encoded, 'secret', algorithms=['HS256'])
46+
{u'some': u'payload'}
4747
```
4848

4949
If the secret is wrong, it will raise a `jwt.DecodeError` telling you as such.
5050
You can still get the payload by setting the `verify` argument to `False`.
5151

5252
```python
53-
jwt.decode(encoded, verify=False)
54-
# {u'some': u'payload'}
53+
>>> jwt.decode(encoded, verify=False)
54+
{u'some': u'payload'}
5555
```
5656

5757
The `decode()` function can raise other exceptions, e.g. for invalid issuer or
@@ -61,9 +61,9 @@ use this approach to catch any issues relating to invalid tokens:
6161

6262
```python
6363
try:
64-
payload = jwt.decode(encoded)
64+
payload = jwt.decode(encoded)
6565
except jwt.InvalidTokenError:
66-
pass # do something sensible here, e.g. return HTTP 403 status code
66+
pass # do something sensible here, e.g. return HTTP 403 status code
6767
```
6868

6969
You may also override exception checking via an `options` dictionary. The default
@@ -83,12 +83,12 @@ You can skip individual checks by passing an `options` dictionary with certain k
8383
For example, if you want to verify the signature of a JWT that has already expired.
8484

8585
```python
86-
options = {
87-
'verify_exp': True,
88-
}
86+
>>> options = {
87+
>>> 'verify_exp': True,
88+
>>> }
8989

90-
jwt.decode(encoded, 'secret', options=options)
91-
# {u'some': u'payload'}
90+
>>> jwt.decode(encoded, 'secret', options=options)
91+
{u'some': u'payload'}
9292
```
9393

9494
**NOTE**: *Changing the default behavior is done at your own risk, and almost certainly will make your
@@ -126,8 +126,8 @@ You can specify which algorithm you would like to use to sign the JWT
126126
by using the `algorithm` parameter:
127127

128128
```python
129-
encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS512')
130-
# 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.WTzLzFO079PduJiFIyzrOah54YaM8qoxH9fLMQoQhKtw3_fMGjImIOokijDkXVbyfBqhMo2GCNu4w9v7UXvnpA'
129+
>>> encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS512')
130+
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.WTzLzFO079PduJiFIyzrOah54YaM8qoxH9fLMQoQhKtw3_fMGjImIOokijDkXVbyfBqhMo2GCNu4w9v7UXvnpA'
131131
```
132132

133133
### Decoding
@@ -136,8 +136,8 @@ when validating the JWT by using the `algorithms` parameter which takes a list
136136
of allowed algorithms:
137137

138138
```python
139-
jwt.decode(encoded, 'secret', algorithms=['HS512', 'HS256'])
140-
# {u'some': u'payload'}
139+
>>> jwt.decode(encoded, 'secret', algorithms=['HS512', 'HS256'])
140+
{u'some': u'payload'}
141141
```
142142

143143
In the above case, if the JWT has any value for its alg header other than

0 commit comments

Comments
 (0)