django-esi 8.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. django_esi-8.1.0.dist-info/METADATA +93 -0
  2. django_esi-8.1.0.dist-info/RECORD +100 -0
  3. django_esi-8.1.0.dist-info/WHEEL +4 -0
  4. django_esi-8.1.0.dist-info/licenses/LICENSE +674 -0
  5. esi/__init__.py +7 -0
  6. esi/admin.py +42 -0
  7. esi/aiopenapi3/client.py +79 -0
  8. esi/aiopenapi3/plugins.py +224 -0
  9. esi/app_settings.py +112 -0
  10. esi/apps.py +11 -0
  11. esi/checks.py +56 -0
  12. esi/clients.py +657 -0
  13. esi/decorators.py +271 -0
  14. esi/errors.py +22 -0
  15. esi/exceptions.py +51 -0
  16. esi/helpers.py +63 -0
  17. esi/locale/cs_CZ/LC_MESSAGES/django.mo +0 -0
  18. esi/locale/cs_CZ/LC_MESSAGES/django.po +53 -0
  19. esi/locale/de/LC_MESSAGES/django.mo +0 -0
  20. esi/locale/de/LC_MESSAGES/django.po +58 -0
  21. esi/locale/en/LC_MESSAGES/django.mo +0 -0
  22. esi/locale/en/LC_MESSAGES/django.po +54 -0
  23. esi/locale/es/LC_MESSAGES/django.mo +0 -0
  24. esi/locale/es/LC_MESSAGES/django.po +59 -0
  25. esi/locale/fr_FR/LC_MESSAGES/django.mo +0 -0
  26. esi/locale/fr_FR/LC_MESSAGES/django.po +59 -0
  27. esi/locale/it_IT/LC_MESSAGES/django.mo +0 -0
  28. esi/locale/it_IT/LC_MESSAGES/django.po +59 -0
  29. esi/locale/ja/LC_MESSAGES/django.mo +0 -0
  30. esi/locale/ja/LC_MESSAGES/django.po +58 -0
  31. esi/locale/ko_KR/LC_MESSAGES/django.mo +0 -0
  32. esi/locale/ko_KR/LC_MESSAGES/django.po +58 -0
  33. esi/locale/nl_NL/LC_MESSAGES/django.mo +0 -0
  34. esi/locale/nl_NL/LC_MESSAGES/django.po +53 -0
  35. esi/locale/pl_PL/LC_MESSAGES/django.mo +0 -0
  36. esi/locale/pl_PL/LC_MESSAGES/django.po +53 -0
  37. esi/locale/ru/LC_MESSAGES/django.mo +0 -0
  38. esi/locale/ru/LC_MESSAGES/django.po +61 -0
  39. esi/locale/sk/LC_MESSAGES/django.mo +0 -0
  40. esi/locale/sk/LC_MESSAGES/django.po +55 -0
  41. esi/locale/uk/LC_MESSAGES/django.mo +0 -0
  42. esi/locale/uk/LC_MESSAGES/django.po +57 -0
  43. esi/locale/zh_Hans/LC_MESSAGES/django.mo +0 -0
  44. esi/locale/zh_Hans/LC_MESSAGES/django.po +58 -0
  45. esi/management/commands/__init__.py +0 -0
  46. esi/management/commands/esi_clear_spec_cache.py +21 -0
  47. esi/management/commands/generate_esi_stubs.py +661 -0
  48. esi/management/commands/migrate_to_ssov2.py +188 -0
  49. esi/managers.py +303 -0
  50. esi/managers.pyi +85 -0
  51. esi/migrations/0001_initial.py +55 -0
  52. esi/migrations/0002_scopes_20161208.py +56 -0
  53. esi/migrations/0003_hide_tokens_from_admin_site.py +23 -0
  54. esi/migrations/0004_remove_unique_access_token.py +18 -0
  55. esi/migrations/0005_remove_token_length_limit.py +23 -0
  56. esi/migrations/0006_remove_url_length_limit.py +18 -0
  57. esi/migrations/0007_fix_mysql_8_migration.py +18 -0
  58. esi/migrations/0008_nullable_refresh_token.py +18 -0
  59. esi/migrations/0009_set_old_tokens_to_sso_v1.py +18 -0
  60. esi/migrations/0010_set_new_tokens_to_sso_v2.py +18 -0
  61. esi/migrations/0011_add_token_indices.py +28 -0
  62. esi/migrations/0012_fix_token_type_choices.py +18 -0
  63. esi/migrations/0013_squashed_0012_fix_token_type_choices.py +57 -0
  64. esi/migrations/__init__.py +0 -0
  65. esi/models.py +349 -0
  66. esi/openapi_clients.py +1225 -0
  67. esi/rate_limiting.py +107 -0
  68. esi/signals.py +21 -0
  69. esi/static/esi/img/EVE_SSO_Login_Buttons_Large_Black.png +0 -0
  70. esi/static/esi/img/EVE_SSO_Login_Buttons_Large_White.png +0 -0
  71. esi/static/esi/img/EVE_SSO_Login_Buttons_Small_Black.png +0 -0
  72. esi/static/esi/img/EVE_SSO_Login_Buttons_Small_White.png +0 -0
  73. esi/stubs.py +2 -0
  74. esi/stubs.pyi +6807 -0
  75. esi/tasks.py +78 -0
  76. esi/templates/esi/select_token.html +116 -0
  77. esi/templatetags/__init__.py +0 -0
  78. esi/templatetags/scope_tags.py +8 -0
  79. esi/tests/__init__.py +134 -0
  80. esi/tests/client_authed_pilot.py +63 -0
  81. esi/tests/client_public_pilot.py +53 -0
  82. esi/tests/factories.py +47 -0
  83. esi/tests/factories_2.py +60 -0
  84. esi/tests/jwt_factory.py +135 -0
  85. esi/tests/test_checks.py +48 -0
  86. esi/tests/test_clients.py +1019 -0
  87. esi/tests/test_decorators.py +578 -0
  88. esi/tests/test_management_command.py +307 -0
  89. esi/tests/test_managers.py +673 -0
  90. esi/tests/test_models.py +403 -0
  91. esi/tests/test_openapi.json +854 -0
  92. esi/tests/test_openapi.py +1017 -0
  93. esi/tests/test_swagger.json +489 -0
  94. esi/tests/test_swagger_full.json +51112 -0
  95. esi/tests/test_tasks.py +116 -0
  96. esi/tests/test_templatetags.py +22 -0
  97. esi/tests/test_views.py +331 -0
  98. esi/tests/threading_pilot.py +69 -0
  99. esi/urls.py +9 -0
  100. esi/views.py +129 -0
esi/rate_limiting.py ADDED
@@ -0,0 +1,107 @@
1
+ import logging
2
+ import time
3
+ from django.core.cache import cache
4
+ from esi.exceptions import ESIBucketLimitException
5
+
6
+ logger = logging.getLogger(__name__)
7
+
8
+ seconds_per_unit = {"s": 1, "m": 60, "h": 3600, "d": 86400}
9
+
10
+
11
+ def interval_to_seconds(s):
12
+ return int(s[:-1]) * seconds_per_unit[s[-1]]
13
+
14
+
15
+ class ESIRateLimitBucket:
16
+ MARKET_DATA_HISTORY = ("market_data_history", 300, 60)
17
+ CHARACTER_CORPORATION_HISTORY = ("character_corporation_history", 300, 60)
18
+
19
+ def __init__(self, slug, limit, window):
20
+ self.slug = slug
21
+ self.limit = limit
22
+ self.window = window
23
+
24
+ @classmethod
25
+ def choices(cls):
26
+ return [(bucket.slug, bucket.slug.replace("_", " ").title()) for bucket in cls]
27
+
28
+ def __str__(self):
29
+ return f"Rate Limit: {self.slug} - {self.limit} in {self.window}Seconds"
30
+
31
+
32
+ class ESIRateLimiter:
33
+ def __init__(self) -> None:
34
+ pass
35
+
36
+ def _slug_to_key(self, slug) -> str:
37
+ return f"esi:bucket:{slug}"
38
+
39
+ def init_bucket(self, bucket: ESIRateLimitBucket) -> None:
40
+ # Set our bucket up if it doesn't already exist
41
+ cache.set(
42
+ self._slug_to_key(bucket.slug),
43
+ bucket.limit,
44
+ timeout=bucket.window,
45
+ nx=True # Don't re-create if it does exist
46
+ )
47
+
48
+ def get_bucket(self, bucket: ESIRateLimitBucket) -> int:
49
+ # get the value from the bucket
50
+ return int(
51
+ cache.get(
52
+ self._slug_to_key(bucket.slug),
53
+ 1 # When not found return 1
54
+ )
55
+ )
56
+
57
+ def get_timeout(self, bucket: ESIRateLimitBucket) -> int:
58
+ current_bucket = self.get_bucket(bucket)
59
+ if current_bucket <= 0:
60
+ timeout = cache.ttl(self._slug_to_key(bucket.slug)) + 1
61
+ msg = (
62
+ f"Rate limit for bucket '{bucket.slug}' exceeded: "
63
+ f"{current_bucket}/{bucket.limit} in last {bucket.window}s. "
64
+ f"Wait {timeout}s."
65
+ )
66
+ logger.warning(msg)
67
+ return timeout # return the time left till reset
68
+ else:
69
+ return 0 # we are good.
70
+
71
+ def decr_bucket(self, bucket: ESIRateLimitBucket, delta: int = 1) -> int:
72
+ # decrease the bucket value by <delta> from the bucket
73
+ return cache.decr(
74
+ self._slug_to_key(bucket.slug),
75
+ delta
76
+ )
77
+
78
+ def set_bucket(self, bucket: ESIRateLimitBucket, new_limit: int = 1) -> int:
79
+ # decrease the bucket value by <delta> from the bucket
80
+ return cache.set(
81
+ self._slug_to_key(bucket.slug),
82
+ int(new_limit),
83
+ timeout=bucket.window
84
+ )
85
+
86
+ def check_bucket(self, bucket: ESIRateLimitBucket):
87
+ self.init_bucket(bucket)
88
+ # get the value
89
+ bucket_val = self.get_bucket(bucket)
90
+ if bucket_val <= 0:
91
+ timeout = self.get_timeout(bucket)
92
+ if timeout > 0:
93
+ raise ESIBucketLimitException(bucket, timeout)
94
+ return
95
+
96
+ def check_decr_bucket(self, bucket: ESIRateLimitBucket, raise_on_limit: bool = True):
97
+ try:
98
+ self.check_bucket(bucket)
99
+ self.decr_bucket(bucket)
100
+ except ESIBucketLimitException as ex:
101
+ if raise_on_limit:
102
+ raise ex
103
+ else:
104
+ time.sleep(ex.reset)
105
+
106
+
107
+ ESIRateLimits = ESIRateLimiter()
esi/signals.py ADDED
@@ -0,0 +1,21 @@
1
+ from django.dispatch import Signal
2
+
3
+ """
4
+ Basic signal sent after an ESI requests
5
+ from django.dispatch import receiver
6
+ from esi.signals import esi_request_statistics
7
+
8
+ @receiver(esi_request_statistics)
9
+ def esi_callback(sender, operation, status_code, headers, latency, bucket, **kwargs):
10
+ # do stuff
11
+ pass
12
+ """
13
+ esi_request_statistics = Signal(
14
+ # providing_args=[
15
+ # "operation",
16
+ # "status_code",
17
+ # "headers",
18
+ # "latency",
19
+ # "bucket"
20
+ # ]
21
+ )
esi/stubs.py ADDED
@@ -0,0 +1,2 @@
1
+ class ESIClientStub:
2
+ pass