telnyx 2.1.1__py2.py3-none-any.whl → 2.1.2__py2.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.

Potentially problematic release.


This version of telnyx might be problematic. Click here for more details.

telnyx/__init__.py CHANGED
@@ -24,7 +24,7 @@ public_key = os.environ.get("TELNYX_PUBLIC_KEY")
24
24
  log = None
25
25
 
26
26
 
27
- __version__ = "2.1.1"
27
+ __version__ = "2.1.2"
28
28
 
29
29
 
30
30
  # Sets some basic information about the running application that's sent along
telnyx/api_requestor.py CHANGED
@@ -125,37 +125,37 @@ class APIRequestor(object):
125
125
  )
126
126
 
127
127
  if rcode == 400:
128
- return error.InvalidRequestError(error_list, rbody, rcode, resp, rheaders)
128
+ return error.InvalidRequestError(error_list, rcode, rbody, resp, rheaders)
129
129
  elif rcode == 401:
130
- return error.AuthenticationError(error_list, rbody, rcode, resp, rheaders)
130
+ return error.AuthenticationError(error_list, rcode, rbody, resp, rheaders)
131
131
  elif rcode == 403:
132
- return error.PermissionError(error_list, rbody, rcode, resp, rheaders)
132
+ return error.PermissionError(error_list, rcode, rbody, resp, rheaders)
133
133
  elif rcode == 404:
134
- return error.ResourceNotFoundError(error_list, rbody, rcode, resp, rheaders)
134
+ return error.ResourceNotFoundError(error_list, rcode, rbody, resp, rheaders)
135
135
  elif rcode == 405:
136
136
  return error.MethodNotSupportedError(
137
- error_list, rbody, rcode, resp, rheaders
137
+ error_list, rcode, rbody, resp, rheaders
138
138
  )
139
139
  elif rcode == 408:
140
- return error.TimeoutError(error_list, rbody, rcode, resp, rheaders)
140
+ return error.TimeoutError(error_list, rcode, rbody, resp, rheaders)
141
141
  elif rcode == 415:
142
142
  return error.UnsupportedMediaTypeError(
143
- error_list, rbody, rcode, resp, rheaders
143
+ error_list, rcode, rbody, resp, rheaders
144
144
  )
145
145
  elif rcode == 422:
146
146
  return error.InvalidParametersError(
147
- error_list, rbody, rcode, resp, rheaders
147
+ error_list, rcode, rbody, resp, rheaders
148
148
  )
149
149
  elif rcode == 429:
150
- return error.RateLimitError(error_list, rbody, rcode, resp, rheaders)
150
+ return error.RateLimitError(error_list, rcode, rbody, resp, rheaders)
151
151
  elif rcode == 500:
152
- return error.APIError(error_list, rbody, rcode, resp, rheaders)
152
+ return error.APIError(error_list, rcode, rbody, resp, rheaders)
153
153
  elif rcode == 503:
154
154
  return error.ServiceUnavailableError(
155
- error_list, rbody, rcode, resp, rheaders
155
+ error_list, rcode, rbody, resp, rheaders
156
156
  )
157
157
  else:
158
- return error.APIError(error_list, rbody, rcode, resp, rheaders)
158
+ return error.APIError(error_list, rcode, rbody, resp, rheaders)
159
159
 
160
160
  def request_headers(self, api_key, method):
161
161
  user_agent = "Telnyx/v2 PythonBindings/%s" % (telnyx.__version__,)
@@ -2,13 +2,16 @@ from __future__ import absolute_import, division, print_function
2
2
 
3
3
  from telnyx.api_resources.abstract import (
4
4
  CreateableAPIResource,
5
- DeletableAPIResource, ListableAPIResource, UpdateableAPIResource
5
+ DeletableAPIResource,
6
+ ListableAPIResource,
7
+ UpdateableAPIResource,
6
8
  )
7
9
 
8
10
 
9
- class AuthenticationProvider(CreateableAPIResource, DeletableAPIResource, ListableAPIResource, UpdateableAPIResource):
11
+ class AuthenticationProvider(
12
+ CreateableAPIResource,
13
+ DeletableAPIResource,
14
+ ListableAPIResource,
15
+ UpdateableAPIResource,
16
+ ):
10
17
  OBJECT_NAME = "authentication_provider"
11
-
12
-
13
-
14
-
@@ -2,13 +2,16 @@ from __future__ import absolute_import, division, print_function
2
2
 
3
3
  from telnyx.api_resources.abstract import (
4
4
  CreateableAPIResource,
5
- DeletableAPIResource, ListableAPIResource, UpdateableAPIResource
5
+ DeletableAPIResource,
6
+ ListableAPIResource,
7
+ UpdateableAPIResource,
6
8
  )
7
9
 
8
10
 
9
- class BillingGroup(CreateableAPIResource, DeletableAPIResource, ListableAPIResource, UpdateableAPIResource):
11
+ class BillingGroup(
12
+ CreateableAPIResource,
13
+ DeletableAPIResource,
14
+ ListableAPIResource,
15
+ UpdateableAPIResource,
16
+ ):
10
17
  OBJECT_NAME = "billing_group"
11
-
12
-
13
-
14
-
@@ -2,13 +2,16 @@ from __future__ import absolute_import, division, print_function
2
2
 
3
3
  from telnyx.api_resources.abstract import (
4
4
  CreateableAPIResource,
5
- DeletableAPIResource, ListableAPIResource, UpdateableAPIResource
5
+ DeletableAPIResource,
6
+ ListableAPIResource,
7
+ UpdateableAPIResource,
6
8
  )
7
9
 
8
10
 
9
- class OutboundVoiceProfile(CreateableAPIResource, DeletableAPIResource, ListableAPIResource, UpdateableAPIResource):
11
+ class OutboundVoiceProfile(
12
+ CreateableAPIResource,
13
+ DeletableAPIResource,
14
+ ListableAPIResource,
15
+ UpdateableAPIResource,
16
+ ):
10
17
  OBJECT_NAME = "outbound_voice_profile"
11
-
12
-
13
-
14
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: telnyx
3
- Version: 2.1.1
3
+ Version: 2.1.2
4
4
  Summary: Python bindings for the Telnyx API
5
5
  Home-page: https://github.com/team-telnyx/telnyx-python
6
6
  Author: Telnyx
@@ -1,10 +1,9 @@
1
- telnyx/__init__.py,sha256=yRg6VPYkO-6KMM1J2Bm8Zbq4oMeTT7EiarH8U_kE33c,1012
2
- telnyx/api_requestor.py,sha256=4J04su6GyGTyK2lSXTEDuZbcoAE4e3OwMIWlohUEQR0,10412
1
+ telnyx/__init__.py,sha256=Nsz_JBCvHlHKhgzTagXMUnlU8WJV_TF5oi_7Hf4ncUA,1012
2
+ telnyx/api_requestor.py,sha256=01zqlPu3Mx58baLLAsRvGihvv5F6h9efBxUtLsAPyLw,10412
3
3
  telnyx/error.py,sha256=7kwUMS7b0ec64A-Ugcwbjs4D2Pl7stEb-JjCE9T6Pic,4366
4
4
  telnyx/http_client.py,sha256=P9htOl44DhSW_m5MkRYtz2U0uLxh7tyuaf1v-ja9MiY,20042
5
5
  telnyx/multipart_data_generator.py,sha256=A6rNpe1WJ859ncFSvAEGHUFuK_fHQiLKqYJAL2Cmc6k,2597
6
6
  telnyx/request_metrics.py,sha256=FHW4rRRYmUe54IWlEgC7BIsM7yvEXMBncPut0E0EWGY,401
7
- telnyx/six.py,sha256=JicFpUC2QNR-QUizUt6EtP3ZNDUyNKUxRDpXllR0jbA,30908
8
7
  telnyx/telnyx_object.py,sha256=ckPaeniC34GOEyCJ9dA6OCVvfRcXYvNJnQ0gqG7mOms,9453
9
8
  telnyx/telnyx_response.py,sha256=4oWm_bDEavy7J3I7DvfD6FpFHCbFj9w1x76OiJFfnoU,422
10
9
  telnyx/util.py,sha256=pUO0qUV4WZsNsjCmjo8SaCRQce668bJoIaFNTabIGIY,16522
@@ -17,12 +16,12 @@ telnyx/api_resources/address.py,sha256=-3N_Hmh727UtEICbznbXWQ6NnblrpRNcg5JPwtKtC
17
16
  telnyx/api_resources/advanced_optinoptout.py,sha256=bRdACJIroXCwtjS9woI4Z-ZWsaG6p9yzjl6anfc-QH4,395
18
17
  telnyx/api_resources/ai.py,sha256=gIgVWt8IcHpS5y4_YQz3jvIGofFBQEVKpSuVgYYEqyI,1225
19
18
  telnyx/api_resources/api_key.py,sha256=SrFq-Vo1ObxBs4lTfUUOVqZ0JaRujykxon3tvyHcQ4k,300
20
- telnyx/api_resources/authentication_provider.py,sha256=lF60-Vczt-dqWUlC7OQ1JHZ-OGrPy2kwHsfGuFRvMGk,385
19
+ telnyx/api_resources/authentication_provider.py,sha256=8hy0qX0nJRt8xagH8W24kstsS8GYvgmjl5OYlQzK7aE,401
21
20
  telnyx/api_resources/autorechargepreference.py,sha256=15rzmAwDoaIFlz_dnjQ_uP7KRJ1405j_mxeWvt2M-jw,270
22
21
  telnyx/api_resources/available_phone_number.py,sha256=QtaoJsudHMun_fdY6KeDmXOghocARm8zlHRLwjUUi8U,222
23
22
  telnyx/api_resources/balance.py,sha256=Z6qwClGpe8NR_RiaU0_lEJV29udmMsdzeJNehHCguX4,196
24
23
  telnyx/api_resources/billing.py,sha256=A8KbJlvjI7BPP12MiM7NziUgP_kYyJ7BB1VLzsrcmQ0,194
25
- telnyx/api_resources/billing_group.py,sha256=NGwMCMaJqS3_3-Muo0CCNsv-spGE_1SoTJ_I2CF4P_Q,365
24
+ telnyx/api_resources/billing_group.py,sha256=vM7ZlhtU1Vs__brcJCszrh953dIrhT-43T8QEMa6iV8,381
26
25
  telnyx/api_resources/brand.py,sha256=N8owqkPjodN0AbsXQegUcUnHPEn6EmVL-3gFJACEh4U,909
27
26
  telnyx/api_resources/bucket.py,sha256=G2S01aq_f7IpdpMSeVC4WxGjsFo8JI6LA1zuQwp-RVU,368
28
27
  telnyx/api_resources/bucket_usage.py,sha256=Z9b97EZ9LMX25U_yroE2C0umr_eVZiBbwrM72cTSp60,203
@@ -95,7 +94,7 @@ telnyx/api_resources/number_portout.py,sha256=LHeiiVxLR25ziZFLvR6gGmuAdaFErzysDN
95
94
  telnyx/api_resources/number_reservation.py,sha256=SJYSBBwK1QLQi6msjvMJUGUd9HZrffKEj2pSNl3rtEc,495
96
95
  telnyx/api_resources/numbers_feature.py,sha256=y69zSo5IVxdtaEkv7nneGgFwLXKg58J0q0KV7WJTwO4,213
97
96
  telnyx/api_resources/ota_update.py,sha256=EAshyhIV8yP2YMLVW7BEGJdCRln6Aa0DdoTnBIZJ950,199
98
- telnyx/api_resources/outbound_voice_profile.py,sha256=arHA9gN6MHVprc_TuT3SxoomfkRBVd1whhA5ybL2Ezs,382
97
+ telnyx/api_resources/outbound_voice_profile.py,sha256=tq6cFo4-qPR2HsruQCr27ZIO8iHciKy61NIP7yIOkpY,398
99
98
  telnyx/api_resources/phone_assignment_profile.py,sha256=nEuK4XkNz-sspFku95F6DmGUCaEE_KvWJoQB2hgx-hE,753
100
99
  telnyx/api_resources/phone_number.py,sha256=OG6wTTCb8mqUXz5-3O-jiqrVuUSVd3G3ld4riYMLTog,4118
101
100
  telnyx/api_resources/phone_number_block_order.py,sha256=l_aBDexyvNTkVeLKonp3AXaOmGRYrPwvRTPM0LOj7wE,271
@@ -114,7 +113,6 @@ telnyx/api_resources/porting_order.py,sha256=vzii9QKdyG9zP6eqw9O0ioiCw6VxvKT81-K
114
113
  telnyx/api_resources/portout.py,sha256=O92nCcvtzNhs2NLHSMAdmH27iDp44riK2gO0laCFB4A,1114
115
114
  telnyx/api_resources/presigned_object_url.py,sha256=oo33r5xX3CUUv48rehgFjccQy6AioNYRwOXBceDXHTw,222
116
115
  telnyx/api_resources/private_wireless_gateway.py,sha256=GWglPOwJMUekkHU-wuXR3QwGL2YipO2tkmT1RcHn6zY,339
117
- telnyx/api_resources/public_endpoint.py,sha256=YGNd0GDPr01yRtYWhzUGybTH4KDJ5QmfkHzO81vcE_Y,323
118
116
  telnyx/api_resources/public_internet_gateway.py,sha256=1x2qoGyrtKJJAcSdw0h0gjIJ1ZekH5lKfKruveBDDhQ,337
119
117
  telnyx/api_resources/public_key.py,sha256=iQK2BodZvtHCg9KSsg9ofclpyv0RHBZ_90LTO5Z52xk,201
120
118
  telnyx/api_resources/push_credential.py,sha256=kBCmVn7Znr2C88ZOJIuPnsyQWZxloIyxn_1xnJ2Nwo4,316
@@ -153,11 +151,6 @@ telnyx/api_resources/virtual_cross_connect.py,sha256=Z9eDeR7HEdZkLSTfsoxfYE2lT5x
153
151
  telnyx/api_resources/wdr_detail_report.py,sha256=2_oJmdidVtX4DmPJsn0ff_8G0Gc-PL0Zo63Bym2FPZk,212
154
152
  telnyx/api_resources/webhook.py,sha256=rrvHtbgd6NhoKoYOjrDoGbBWMp2ElP1PJtL6ooNCHG0,194
155
153
  telnyx/api_resources/webhook_deliveries.py,sha256=zCq74p80po6kDZCjLPsTrhQH3NAyGT9OPxQoNCLH9ww,297
156
- telnyx/api_resources/whatsapp_business_account.py,sha256=OCfrVS9C6VZmRMR3lYBRgZX7W56j6J-AvV4bRw1T43M,228
157
- telnyx/api_resources/whatsapp_contact.py,sha256=wp9pU1DguE2_uA9mIm8Wchqwb5Jv163GSBoMKzGZoxs,215
158
- telnyx/api_resources/whatsapp_media.py,sha256=FjAqxVuDHt7_NQ_6B5mhWonSvDNlg2_upibQd096EGc,392
159
- telnyx/api_resources/whatsapp_message.py,sha256=1G0kwDoV7Ckam31B_yTzTFShVcXHPirF_HWRS3ioOls,326
160
- telnyx/api_resources/whatsapp_phone_number.py,sha256=dAsAV8hjFeBJtHAuYB6DBfEFTgx4gZDVVhJvaNuSIGc,266
161
154
  telnyx/api_resources/wireguard_interface.py,sha256=XhqyRiEkLFMjw_c7SOuF6EyLi1tssYgcuNTAtXHlc7w,393
162
155
  telnyx/api_resources/wireless_detail_record_report.py,sha256=dAYdVTkSLRJ2e6bXlHqBX7IX3VQGJIaMZOqDTuIf3a8,446
163
156
  telnyx/api_resources/abstract/__init__.py,sha256=9jcqkJnDYXXCzDIUTRqLGHTI17eKz3i9fMD_0QvySaE,692
@@ -168,8 +161,8 @@ telnyx/api_resources/abstract/listable_api_resource.py,sha256=shWcUha2LYM_WPedBX
168
161
  telnyx/api_resources/abstract/nested_resource_class_methods.py,sha256=dO18YZ4iuqmsvxibbXYfFb-D8Eg9XAKs8IQDGU--gCo,4314
169
162
  telnyx/api_resources/abstract/singleton_api_resource.py,sha256=2g-rKkk2dT8aNJDKEFiaLFRs8wKk31kBTJpku3kpdNE,874
170
163
  telnyx/api_resources/abstract/updateable_api_resource.py,sha256=2_WN99EUfBmnHunfjS3jlwY0EIoU8V7_j9OMRsiqedk,1673
171
- telnyx-2.1.1.dist-info/LICENSE,sha256=h4YEwOcV9A9iTg1cUsg0z7uU7gxj281PMpKWj-AdQWY,1141
172
- telnyx-2.1.1.dist-info/METADATA,sha256=TB1b4LUti6xT3vD26PabWHKAqOk6Kk2zgx4Jjc7GpDk,10658
173
- telnyx-2.1.1.dist-info/WHEEL,sha256=-G_t0oGuE7UD0DrSpVZnq1hHMBV9DD2XkS5v7XpmTnk,110
174
- telnyx-2.1.1.dist-info/top_level.txt,sha256=e59ZDpP51N6b62sY7VrNLq8aR9Ly5-IHtl7zCkGA0Yw,7
175
- telnyx-2.1.1.dist-info/RECORD,,
164
+ telnyx-2.1.2.dist-info/LICENSE,sha256=h4YEwOcV9A9iTg1cUsg0z7uU7gxj281PMpKWj-AdQWY,1141
165
+ telnyx-2.1.2.dist-info/METADATA,sha256=RK_Hvm3OSnMkh_qhs6sMIHr2Fc_hMjWgV1Qx0kn8S3I,10658
166
+ telnyx-2.1.2.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
167
+ telnyx-2.1.2.dist-info/top_level.txt,sha256=e59ZDpP51N6b62sY7VrNLq8aR9Ly5-IHtl7zCkGA0Yw,7
168
+ telnyx-2.1.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any
@@ -1,14 +0,0 @@
1
- from __future__ import absolute_import, division, print_function
2
-
3
- from telnyx.api_resources.abstract import (
4
- CreateableAPIResource,
5
- DeletableAPIResource, ListableAPIResource
6
- )
7
-
8
-
9
- class PublicEndpoint(CreateableAPIResource, DeletableAPIResource, ListableAPIResource):
10
- OBJECT_NAME = "public_endpoint"
11
-
12
-
13
-
14
-
@@ -1,7 +0,0 @@
1
- from __future__ import absolute_import, division, print_function
2
-
3
- from telnyx.api_resources.abstract import ListableAPIResource
4
-
5
-
6
- class WhatsappBusinessAccount(ListableAPIResource):
7
- OBJECT_NAME = "whatsapp_business_account"
@@ -1,7 +0,0 @@
1
- from __future__ import absolute_import, division, print_function
2
-
3
- from telnyx.api_resources.abstract import CreateableAPIResource
4
-
5
-
6
- class WhatsappContact(CreateableAPIResource):
7
- OBJECT_NAME = "whatsapp_contact"
@@ -1,15 +0,0 @@
1
- from __future__ import absolute_import, division, print_function
2
-
3
- from telnyx.api_resources.abstract import (
4
- CreateableAPIResource,
5
- DeletableAPIResource,
6
- ListableAPIResource,
7
- )
8
-
9
-
10
- class WhatsappMedia(ListableAPIResource, CreateableAPIResource, DeletableAPIResource):
11
- OBJECT_NAME = "whatsapp_media"
12
-
13
- @classmethod
14
- def class_url(cls):
15
- return "/v2/whatsapp_media"
@@ -1,13 +0,0 @@
1
- from __future__ import absolute_import, division, print_function
2
-
3
- from telnyx.api_resources.abstract import (
4
- CreateableAPIResource,
5
- ListableAPIResource,
6
- UpdateableAPIResource,
7
- )
8
-
9
-
10
- class WhatsappMessage(
11
- CreateableAPIResource, ListableAPIResource, UpdateableAPIResource
12
- ):
13
- OBJECT_NAME = "whatsapp_message"
@@ -1,7 +0,0 @@
1
- from __future__ import absolute_import, division, print_function
2
-
3
- from telnyx.api_resources.abstract import ListableAPIResource, UpdateableAPIResource
4
-
5
-
6
- class WhatsappPhoneNumber(ListableAPIResource, UpdateableAPIResource):
7
- OBJECT_NAME = "whatsapp_phone_number"
telnyx/six.py DELETED
@@ -1,892 +0,0 @@
1
- # pylint: skip-file
2
- # Copyright (c) 2010-2017 Benjamin Peterson
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- # SOFTWARE.
21
-
22
- """Utilities for writing code that runs on Python 2 and 3"""
23
-
24
- from __future__ import absolute_import
25
-
26
- import functools
27
- import itertools
28
- import operator
29
- import sys
30
- import types
31
-
32
- __author__ = "Benjamin Peterson <benjamin@python.org>"
33
- __version__ = "1.11.0"
34
-
35
-
36
- # Useful for very coarse version differentiation.
37
- PY2 = sys.version_info[0] == 2
38
- PY3 = sys.version_info[0] == 3
39
- PY34 = sys.version_info[0:2] >= (3, 4)
40
-
41
- if PY3:
42
- string_types = str,
43
- integer_types = int,
44
- class_types = type,
45
- text_type = str
46
- binary_type = bytes
47
-
48
- MAXSIZE = sys.maxsize
49
- else:
50
- string_types = basestring,
51
- integer_types = (int, long)
52
- class_types = (type, types.ClassType)
53
- text_type = unicode
54
- binary_type = str
55
-
56
- if sys.platform.startswith("java"):
57
- # Jython always uses 32 bits.
58
- MAXSIZE = int((1 << 31) - 1)
59
- else:
60
- # It's possible to have sizeof(long) != sizeof(Py_ssize_t).
61
- class X(object):
62
-
63
- def __len__(self):
64
- return 1 << 31
65
- try:
66
- len(X())
67
- except OverflowError:
68
- # 32-bit
69
- MAXSIZE = int((1 << 31) - 1)
70
- else:
71
- # 64-bit
72
- MAXSIZE = int((1 << 63) - 1)
73
- del X
74
-
75
-
76
- def _add_doc(func, doc):
77
- """Add documentation to a function."""
78
- func.__doc__ = doc
79
-
80
-
81
- def _import_module(name):
82
- """Import module, returning the module after the last dot."""
83
- __import__(name)
84
- return sys.modules[name]
85
-
86
-
87
- class _LazyDescr(object):
88
-
89
- def __init__(self, name):
90
- self.name = name
91
-
92
- def __get__(self, obj, tp):
93
- result = self._resolve()
94
- setattr(obj, self.name, result) # Invokes __set__.
95
- try:
96
- # This is a bit ugly, but it avoids running this again by
97
- # removing this descriptor.
98
- delattr(obj.__class__, self.name)
99
- except AttributeError:
100
- pass
101
- return result
102
-
103
-
104
- class MovedModule(_LazyDescr):
105
-
106
- def __init__(self, name, old, new=None):
107
- super(MovedModule, self).__init__(name)
108
- if PY3:
109
- if new is None:
110
- new = name
111
- self.mod = new
112
- else:
113
- self.mod = old
114
-
115
- def _resolve(self):
116
- return _import_module(self.mod)
117
-
118
- def __getattr__(self, attr):
119
- _module = self._resolve()
120
- value = getattr(_module, attr)
121
- setattr(self, attr, value)
122
- return value
123
-
124
-
125
- class _LazyModule(types.ModuleType):
126
-
127
- def __init__(self, name):
128
- super(_LazyModule, self).__init__(name)
129
- self.__doc__ = self.__class__.__doc__
130
-
131
- def __dir__(self):
132
- attrs = ["__doc__", "__name__"]
133
- attrs += [attr.name for attr in self._moved_attributes]
134
- return attrs
135
-
136
- # Subclasses should override this
137
- _moved_attributes = []
138
-
139
-
140
- class MovedAttribute(_LazyDescr):
141
-
142
- def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
143
- super(MovedAttribute, self).__init__(name)
144
- if PY3:
145
- if new_mod is None:
146
- new_mod = name
147
- self.mod = new_mod
148
- if new_attr is None:
149
- if old_attr is None:
150
- new_attr = name
151
- else:
152
- new_attr = old_attr
153
- self.attr = new_attr
154
- else:
155
- self.mod = old_mod
156
- if old_attr is None:
157
- old_attr = name
158
- self.attr = old_attr
159
-
160
- def _resolve(self):
161
- module = _import_module(self.mod)
162
- return getattr(module, self.attr)
163
-
164
-
165
- class _SixMetaPathImporter(object):
166
-
167
- """
168
- A meta path importer to import six.moves and its submodules.
169
-
170
- This class implements a PEP302 finder and loader. It should be compatible
171
- with Python 2.5 and all existing versions of Python3
172
- """
173
-
174
- def __init__(self, six_module_name):
175
- self.name = six_module_name
176
- self.known_modules = {}
177
-
178
- def _add_module(self, mod, *fullnames):
179
- for fullname in fullnames:
180
- self.known_modules[self.name + "." + fullname] = mod
181
-
182
- def _get_module(self, fullname):
183
- return self.known_modules[self.name + "." + fullname]
184
-
185
- def find_module(self, fullname, path=None):
186
- if fullname in self.known_modules:
187
- return self
188
- return None
189
-
190
- def __get_module(self, fullname):
191
- try:
192
- return self.known_modules[fullname]
193
- except KeyError:
194
- raise ImportError("This loader does not know module " + fullname)
195
-
196
- def load_module(self, fullname):
197
- try:
198
- # in case of a reload
199
- return sys.modules[fullname]
200
- except KeyError:
201
- pass
202
- mod = self.__get_module(fullname)
203
- if isinstance(mod, MovedModule):
204
- mod = mod._resolve()
205
- else:
206
- mod.__loader__ = self
207
- sys.modules[fullname] = mod
208
- return mod
209
-
210
- def is_package(self, fullname):
211
- """
212
- Return true, if the named module is a package.
213
-
214
- We need this method to get correct spec objects with
215
- Python 3.4 (see PEP451)
216
- """
217
- return hasattr(self.__get_module(fullname), "__path__")
218
-
219
- def get_code(self, fullname):
220
- """Return None
221
-
222
- Required, if is_package is implemented"""
223
- self.__get_module(fullname) # eventually raises ImportError
224
- return None
225
- get_source = get_code # same as get_code
226
-
227
- _importer = _SixMetaPathImporter(__name__)
228
-
229
-
230
- class _MovedItems(_LazyModule):
231
-
232
- """Lazy loading of moved objects"""
233
- __path__ = [] # mark as package
234
-
235
-
236
- _moved_attributes = [
237
- MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
238
- MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
239
- MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"),
240
- MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
241
- MovedAttribute("intern", "__builtin__", "sys"),
242
- MovedAttribute("map", "itertools", "builtins", "imap", "map"),
243
- MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"),
244
- MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"),
245
- MovedAttribute("getoutput", "commands", "subprocess"),
246
- MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
247
- MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"),
248
- MovedAttribute("reduce", "__builtin__", "functools"),
249
- MovedAttribute("shlex_quote", "pipes", "shlex", "quote"),
250
- MovedAttribute("StringIO", "StringIO", "io"),
251
- MovedAttribute("UserDict", "UserDict", "collections"),
252
- MovedAttribute("UserList", "UserList", "collections"),
253
- MovedAttribute("UserString", "UserString", "collections"),
254
- MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
255
- MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
256
- MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),
257
- MovedModule("builtins", "__builtin__"),
258
- MovedModule("configparser", "ConfigParser"),
259
- MovedModule("copyreg", "copy_reg"),
260
- MovedModule("dbm_gnu", "gdbm", "dbm.gnu"),
261
- MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread"),
262
- MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
263
- MovedModule("http_cookies", "Cookie", "http.cookies"),
264
- MovedModule("html_entities", "htmlentitydefs", "html.entities"),
265
- MovedModule("html_parser", "HTMLParser", "html.parser"),
266
- MovedModule("http_client", "httplib", "http.client"),
267
- MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
268
- MovedModule("email_mime_image", "email.MIMEImage", "email.mime.image"),
269
- MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"),
270
- MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"),
271
- MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"),
272
- MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
273
- MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
274
- MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
275
- MovedModule("cPickle", "cPickle", "pickle"),
276
- MovedModule("queue", "Queue"),
277
- MovedModule("reprlib", "repr"),
278
- MovedModule("socketserver", "SocketServer"),
279
- MovedModule("_thread", "thread", "_thread"),
280
- MovedModule("tkinter", "Tkinter"),
281
- MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
282
- MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
283
- MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"),
284
- MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"),
285
- MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
286
- MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"),
287
- MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
288
- MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"),
289
- MovedModule("tkinter_colorchooser", "tkColorChooser",
290
- "tkinter.colorchooser"),
291
- MovedModule("tkinter_commondialog", "tkCommonDialog",
292
- "tkinter.commondialog"),
293
- MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"),
294
- MovedModule("tkinter_font", "tkFont", "tkinter.font"),
295
- MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
296
- MovedModule("tkinter_tksimpledialog", "tkSimpleDialog",
297
- "tkinter.simpledialog"),
298
- MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"),
299
- MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"),
300
- MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"),
301
- MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
302
- MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
303
- MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"),
304
- ]
305
- # Add windows specific modules.
306
- if sys.platform == "win32":
307
- _moved_attributes += [
308
- MovedModule("winreg", "_winreg"),
309
- ]
310
-
311
- for attr in _moved_attributes:
312
- setattr(_MovedItems, attr.name, attr)
313
- if isinstance(attr, MovedModule):
314
- _importer._add_module(attr, "moves." + attr.name)
315
- del attr
316
-
317
- _MovedItems._moved_attributes = _moved_attributes
318
-
319
- moves = _MovedItems(__name__ + ".moves")
320
- _importer._add_module(moves, "moves")
321
-
322
-
323
- class Module_six_moves_urllib_parse(_LazyModule):
324
-
325
- """Lazy loading of moved objects in six.moves.urllib_parse"""
326
-
327
-
328
- _urllib_parse_moved_attributes = [
329
- MovedAttribute("ParseResult", "urlparse", "urllib.parse"),
330
- MovedAttribute("SplitResult", "urlparse", "urllib.parse"),
331
- MovedAttribute("parse_qs", "urlparse", "urllib.parse"),
332
- MovedAttribute("parse_qsl", "urlparse", "urllib.parse"),
333
- MovedAttribute("urldefrag", "urlparse", "urllib.parse"),
334
- MovedAttribute("urljoin", "urlparse", "urllib.parse"),
335
- MovedAttribute("urlparse", "urlparse", "urllib.parse"),
336
- MovedAttribute("urlsplit", "urlparse", "urllib.parse"),
337
- MovedAttribute("urlunparse", "urlparse", "urllib.parse"),
338
- MovedAttribute("urlunsplit", "urlparse", "urllib.parse"),
339
- MovedAttribute("quote", "urllib", "urllib.parse"),
340
- MovedAttribute("quote_plus", "urllib", "urllib.parse"),
341
- MovedAttribute("unquote", "urllib", "urllib.parse"),
342
- MovedAttribute("unquote_plus", "urllib", "urllib.parse"),
343
- MovedAttribute("unquote_to_bytes", "urllib", "urllib.parse", "unquote", "unquote_to_bytes"),
344
- MovedAttribute("urlencode", "urllib", "urllib.parse"),
345
- MovedAttribute("splitquery", "urllib", "urllib.parse"),
346
- MovedAttribute("splittag", "urllib", "urllib.parse"),
347
- MovedAttribute("splituser", "urllib", "urllib.parse"),
348
- MovedAttribute("splitvalue", "urllib", "urllib.parse"),
349
- MovedAttribute("uses_fragment", "urlparse", "urllib.parse"),
350
- MovedAttribute("uses_netloc", "urlparse", "urllib.parse"),
351
- MovedAttribute("uses_params", "urlparse", "urllib.parse"),
352
- MovedAttribute("uses_query", "urlparse", "urllib.parse"),
353
- MovedAttribute("uses_relative", "urlparse", "urllib.parse"),
354
- ]
355
- for attr in _urllib_parse_moved_attributes:
356
- setattr(Module_six_moves_urllib_parse, attr.name, attr)
357
- del attr
358
-
359
- Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes
360
-
361
- _importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"),
362
- "moves.urllib_parse", "moves.urllib.parse")
363
-
364
-
365
- class Module_six_moves_urllib_error(_LazyModule):
366
-
367
- """Lazy loading of moved objects in six.moves.urllib_error"""
368
-
369
-
370
- _urllib_error_moved_attributes = [
371
- MovedAttribute("URLError", "urllib2", "urllib.error"),
372
- MovedAttribute("HTTPError", "urllib2", "urllib.error"),
373
- MovedAttribute("ContentTooShortError", "urllib", "urllib.error"),
374
- ]
375
- for attr in _urllib_error_moved_attributes:
376
- setattr(Module_six_moves_urllib_error, attr.name, attr)
377
- del attr
378
-
379
- Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes
380
-
381
- _importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"),
382
- "moves.urllib_error", "moves.urllib.error")
383
-
384
-
385
- class Module_six_moves_urllib_request(_LazyModule):
386
-
387
- """Lazy loading of moved objects in six.moves.urllib_request"""
388
-
389
-
390
- _urllib_request_moved_attributes = [
391
- MovedAttribute("urlopen", "urllib2", "urllib.request"),
392
- MovedAttribute("install_opener", "urllib2", "urllib.request"),
393
- MovedAttribute("build_opener", "urllib2", "urllib.request"),
394
- MovedAttribute("pathname2url", "urllib", "urllib.request"),
395
- MovedAttribute("url2pathname", "urllib", "urllib.request"),
396
- MovedAttribute("getproxies", "urllib", "urllib.request"),
397
- MovedAttribute("Request", "urllib2", "urllib.request"),
398
- MovedAttribute("OpenerDirector", "urllib2", "urllib.request"),
399
- MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"),
400
- MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"),
401
- MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"),
402
- MovedAttribute("ProxyHandler", "urllib2", "urllib.request"),
403
- MovedAttribute("BaseHandler", "urllib2", "urllib.request"),
404
- MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"),
405
- MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"),
406
- MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"),
407
- MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"),
408
- MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"),
409
- MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"),
410
- MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"),
411
- MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"),
412
- MovedAttribute("HTTPHandler", "urllib2", "urllib.request"),
413
- MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"),
414
- MovedAttribute("FileHandler", "urllib2", "urllib.request"),
415
- MovedAttribute("FTPHandler", "urllib2", "urllib.request"),
416
- MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"),
417
- MovedAttribute("UnknownHandler", "urllib2", "urllib.request"),
418
- MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"),
419
- MovedAttribute("urlretrieve", "urllib", "urllib.request"),
420
- MovedAttribute("urlcleanup", "urllib", "urllib.request"),
421
- MovedAttribute("URLopener", "urllib", "urllib.request"),
422
- MovedAttribute("FancyURLopener", "urllib", "urllib.request"),
423
- MovedAttribute("proxy_bypass", "urllib", "urllib.request"),
424
- MovedAttribute("parse_http_list", "urllib2", "urllib.request"),
425
- MovedAttribute("parse_keqv_list", "urllib2", "urllib.request"),
426
- ]
427
- for attr in _urllib_request_moved_attributes:
428
- setattr(Module_six_moves_urllib_request, attr.name, attr)
429
- del attr
430
-
431
- Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes
432
-
433
- _importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"),
434
- "moves.urllib_request", "moves.urllib.request")
435
-
436
-
437
- class Module_six_moves_urllib_response(_LazyModule):
438
-
439
- """Lazy loading of moved objects in six.moves.urllib_response"""
440
-
441
-
442
- _urllib_response_moved_attributes = [
443
- MovedAttribute("addbase", "urllib", "urllib.response"),
444
- MovedAttribute("addclosehook", "urllib", "urllib.response"),
445
- MovedAttribute("addinfo", "urllib", "urllib.response"),
446
- MovedAttribute("addinfourl", "urllib", "urllib.response"),
447
- ]
448
- for attr in _urllib_response_moved_attributes:
449
- setattr(Module_six_moves_urllib_response, attr.name, attr)
450
- del attr
451
-
452
- Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes
453
-
454
- _importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"),
455
- "moves.urllib_response", "moves.urllib.response")
456
-
457
-
458
- class Module_six_moves_urllib_robotparser(_LazyModule):
459
-
460
- """Lazy loading of moved objects in six.moves.urllib_robotparser"""
461
-
462
-
463
- _urllib_robotparser_moved_attributes = [
464
- MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"),
465
- ]
466
- for attr in _urllib_robotparser_moved_attributes:
467
- setattr(Module_six_moves_urllib_robotparser, attr.name, attr)
468
- del attr
469
-
470
- Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes
471
-
472
- _importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"),
473
- "moves.urllib_robotparser", "moves.urllib.robotparser")
474
-
475
-
476
- class Module_six_moves_urllib(types.ModuleType):
477
-
478
- """Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
479
- __path__ = [] # mark as package
480
- parse = _importer._get_module("moves.urllib_parse")
481
- error = _importer._get_module("moves.urllib_error")
482
- request = _importer._get_module("moves.urllib_request")
483
- response = _importer._get_module("moves.urllib_response")
484
- robotparser = _importer._get_module("moves.urllib_robotparser")
485
-
486
- def __dir__(self):
487
- return ['parse', 'error', 'request', 'response', 'robotparser']
488
-
489
- _importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"),
490
- "moves.urllib")
491
-
492
-
493
- def add_move(move):
494
- """Add an item to six.moves."""
495
- setattr(_MovedItems, move.name, move)
496
-
497
-
498
- def remove_move(name):
499
- """Remove item from six.moves."""
500
- try:
501
- delattr(_MovedItems, name)
502
- except AttributeError:
503
- try:
504
- del moves.__dict__[name]
505
- except KeyError:
506
- raise AttributeError("no such move, %r" % (name,))
507
-
508
-
509
- if PY3:
510
- _meth_func = "__func__"
511
- _meth_self = "__self__"
512
-
513
- _func_closure = "__closure__"
514
- _func_code = "__code__"
515
- _func_defaults = "__defaults__"
516
- _func_globals = "__globals__"
517
- else:
518
- _meth_func = "im_func"
519
- _meth_self = "im_self"
520
-
521
- _func_closure = "func_closure"
522
- _func_code = "func_code"
523
- _func_defaults = "func_defaults"
524
- _func_globals = "func_globals"
525
-
526
-
527
- try:
528
- advance_iterator = next
529
- except NameError:
530
- def advance_iterator(it):
531
- return it.next()
532
- next = advance_iterator
533
-
534
-
535
- try:
536
- callable = callable
537
- except NameError:
538
- def callable(obj):
539
- return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
540
-
541
-
542
- if PY3:
543
- def get_unbound_function(unbound):
544
- return unbound
545
-
546
- create_bound_method = types.MethodType
547
-
548
- def create_unbound_method(func, cls):
549
- return func
550
-
551
- Iterator = object
552
- else:
553
- def get_unbound_function(unbound):
554
- return unbound.im_func
555
-
556
- def create_bound_method(func, obj):
557
- return types.MethodType(func, obj, obj.__class__)
558
-
559
- def create_unbound_method(func, cls):
560
- return types.MethodType(func, None, cls)
561
-
562
- class Iterator(object):
563
-
564
- def next(self):
565
- return type(self).__next__(self)
566
-
567
- callable = callable
568
- _add_doc(get_unbound_function,
569
- """Get the function out of a possibly unbound function""")
570
-
571
-
572
- get_method_function = operator.attrgetter(_meth_func)
573
- get_method_self = operator.attrgetter(_meth_self)
574
- get_function_closure = operator.attrgetter(_func_closure)
575
- get_function_code = operator.attrgetter(_func_code)
576
- get_function_defaults = operator.attrgetter(_func_defaults)
577
- get_function_globals = operator.attrgetter(_func_globals)
578
-
579
-
580
- if PY3:
581
- def iterkeys(d, **kw):
582
- return iter(d.keys(**kw))
583
-
584
- def itervalues(d, **kw):
585
- return iter(d.values(**kw))
586
-
587
- def iteritems(d, **kw):
588
- return iter(d.items(**kw))
589
-
590
- def iterlists(d, **kw):
591
- return iter(d.lists(**kw))
592
-
593
- viewkeys = operator.methodcaller("keys")
594
-
595
- viewvalues = operator.methodcaller("values")
596
-
597
- viewitems = operator.methodcaller("items")
598
- else:
599
- def iterkeys(d, **kw):
600
- return d.iterkeys(**kw)
601
-
602
- def itervalues(d, **kw):
603
- return d.itervalues(**kw)
604
-
605
- def iteritems(d, **kw):
606
- return d.iteritems(**kw)
607
-
608
- def iterlists(d, **kw):
609
- return d.iterlists(**kw)
610
-
611
- viewkeys = operator.methodcaller("viewkeys")
612
-
613
- viewvalues = operator.methodcaller("viewvalues")
614
-
615
- viewitems = operator.methodcaller("viewitems")
616
-
617
- _add_doc(iterkeys, "Return an iterator over the keys of a dictionary.")
618
- _add_doc(itervalues, "Return an iterator over the values of a dictionary.")
619
- _add_doc(iteritems,
620
- "Return an iterator over the (key, value) pairs of a dictionary.")
621
- _add_doc(iterlists,
622
- "Return an iterator over the (key, [values]) pairs of a dictionary.")
623
-
624
-
625
- if PY3:
626
- def b(s):
627
- return s.encode("latin-1")
628
-
629
- def u(s):
630
- return s
631
- unichr = chr
632
- import struct
633
- int2byte = struct.Struct(">B").pack
634
- del struct
635
- byte2int = operator.itemgetter(0)
636
- indexbytes = operator.getitem
637
- iterbytes = iter
638
- import io
639
- StringIO = io.StringIO
640
- BytesIO = io.BytesIO
641
- _assertCountEqual = "assertCountEqual"
642
- if sys.version_info[1] <= 1:
643
- _assertRaisesRegex = "assertRaisesRegexp"
644
- _assertRegex = "assertRegexpMatches"
645
- else:
646
- _assertRaisesRegex = "assertRaisesRegex"
647
- _assertRegex = "assertRegex"
648
- else:
649
- def b(s):
650
- return s
651
- # Workaround for standalone backslash
652
-
653
- def u(s):
654
- return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
655
- unichr = unichr
656
- int2byte = chr
657
-
658
- def byte2int(bs):
659
- return ord(bs[0])
660
-
661
- def indexbytes(buf, i):
662
- return ord(buf[i])
663
- iterbytes = functools.partial(itertools.imap, ord)
664
- import StringIO
665
- StringIO = BytesIO = StringIO.StringIO
666
- _assertCountEqual = "assertItemsEqual"
667
- _assertRaisesRegex = "assertRaisesRegexp"
668
- _assertRegex = "assertRegexpMatches"
669
- _add_doc(b, """Byte literal""")
670
- _add_doc(u, """Text literal""")
671
-
672
-
673
- def assertCountEqual(self, *args, **kwargs):
674
- return getattr(self, _assertCountEqual)(*args, **kwargs)
675
-
676
-
677
- def assertRaisesRegex(self, *args, **kwargs):
678
- return getattr(self, _assertRaisesRegex)(*args, **kwargs)
679
-
680
-
681
- def assertRegex(self, *args, **kwargs):
682
- return getattr(self, _assertRegex)(*args, **kwargs)
683
-
684
-
685
- if PY3:
686
- exec_ = getattr(moves.builtins, "exec")
687
-
688
- def reraise(tp, value, tb=None):
689
- try:
690
- if value is None:
691
- value = tp()
692
- if value.__traceback__ is not tb:
693
- raise value.with_traceback(tb)
694
- raise value
695
- finally:
696
- value = None
697
- tb = None
698
-
699
- else:
700
- def exec_(_code_, _globs_=None, _locs_=None):
701
- """Execute code in a namespace."""
702
- if _globs_ is None:
703
- frame = sys._getframe(1)
704
- _globs_ = frame.f_globals
705
- if _locs_ is None:
706
- _locs_ = frame.f_locals
707
- del frame
708
- elif _locs_ is None:
709
- _locs_ = _globs_
710
- exec("""exec _code_ in _globs_, _locs_""")
711
-
712
- exec_("""def reraise(tp, value, tb=None):
713
- try:
714
- raise tp, value, tb
715
- finally:
716
- tb = None
717
- """)
718
-
719
-
720
- if sys.version_info[:2] == (3, 2):
721
- exec_("""def raise_from(value, from_value):
722
- try:
723
- if from_value is None:
724
- raise value
725
- raise value from from_value
726
- finally:
727
- value = None
728
- """)
729
- elif sys.version_info[:2] > (3, 2):
730
- exec_("""def raise_from(value, from_value):
731
- try:
732
- raise value from from_value
733
- finally:
734
- value = None
735
- """)
736
- else:
737
- def raise_from(value, from_value):
738
- raise value
739
-
740
-
741
- print_ = getattr(moves.builtins, "print", None)
742
- if print_ is None:
743
- def print_(*args, **kwargs):
744
- """The new-style print function for Python 2.4 and 2.5."""
745
- fp = kwargs.pop("file", sys.stdout)
746
- if fp is None:
747
- return
748
-
749
- def write(data):
750
- if not isinstance(data, basestring):
751
- data = str(data)
752
- # If the file has an encoding, encode unicode with it.
753
- if (isinstance(fp, file) and
754
- isinstance(data, unicode) and
755
- fp.encoding is not None):
756
- errors = getattr(fp, "errors", None)
757
- if errors is None:
758
- errors = "strict"
759
- data = data.encode(fp.encoding, errors)
760
- fp.write(data)
761
- want_unicode = False
762
- sep = kwargs.pop("sep", None)
763
- if sep is not None:
764
- if isinstance(sep, unicode):
765
- want_unicode = True
766
- elif not isinstance(sep, str):
767
- raise TypeError("sep must be None or a string")
768
- end = kwargs.pop("end", None)
769
- if end is not None:
770
- if isinstance(end, unicode):
771
- want_unicode = True
772
- elif not isinstance(end, str):
773
- raise TypeError("end must be None or a string")
774
- if kwargs:
775
- raise TypeError("invalid keyword arguments to print()")
776
- if not want_unicode:
777
- for arg in args:
778
- if isinstance(arg, unicode):
779
- want_unicode = True
780
- break
781
- if want_unicode:
782
- newline = unicode("\n")
783
- space = unicode(" ")
784
- else:
785
- newline = "\n"
786
- space = " "
787
- if sep is None:
788
- sep = space
789
- if end is None:
790
- end = newline
791
- for i, arg in enumerate(args):
792
- if i:
793
- write(sep)
794
- write(arg)
795
- write(end)
796
- if sys.version_info[:2] < (3, 3):
797
- _print = print_
798
-
799
- def print_(*args, **kwargs):
800
- fp = kwargs.get("file", sys.stdout)
801
- flush = kwargs.pop("flush", False)
802
- _print(*args, **kwargs)
803
- if flush and fp is not None:
804
- fp.flush()
805
-
806
- _add_doc(reraise, """Reraise an exception.""")
807
-
808
- if sys.version_info[0:2] < (3, 4):
809
- def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS,
810
- updated=functools.WRAPPER_UPDATES):
811
- def wrapper(f):
812
- f = functools.wraps(wrapped, assigned, updated)(f)
813
- f.__wrapped__ = wrapped
814
- return f
815
- return wrapper
816
- else:
817
- wraps = functools.wraps
818
-
819
-
820
- def with_metaclass(meta, *bases):
821
- """Create a base class with a metaclass."""
822
- # This requires a bit of explanation: the basic idea is to make a dummy
823
- # metaclass for one level of class instantiation that replaces itself with
824
- # the actual metaclass.
825
- class metaclass(type):
826
-
827
- def __new__(cls, name, this_bases, d):
828
- return meta(name, bases, d)
829
-
830
- @classmethod
831
- def __prepare__(cls, name, this_bases):
832
- return meta.__prepare__(name, bases)
833
- return type.__new__(metaclass, 'temporary_class', (), {})
834
-
835
-
836
- def add_metaclass(metaclass):
837
- """Class decorator for creating a class with a metaclass."""
838
- def wrapper(cls):
839
- orig_vars = cls.__dict__.copy()
840
- slots = orig_vars.get('__slots__')
841
- if slots is not None:
842
- if isinstance(slots, str):
843
- slots = [slots]
844
- for slots_var in slots:
845
- orig_vars.pop(slots_var)
846
- orig_vars.pop('__dict__', None)
847
- orig_vars.pop('__weakref__', None)
848
- return metaclass(cls.__name__, cls.__bases__, orig_vars)
849
- return wrapper
850
-
851
-
852
- def python_2_unicode_compatible(klass):
853
- """
854
- A decorator that defines __unicode__ and __str__ methods under Python 2.
855
- Under Python 3 it does nothing.
856
-
857
- To support Python 2 and 3 with a single code base, define a __str__ method
858
- returning text and apply this decorator to the class.
859
- """
860
- if PY2:
861
- if '__str__' not in klass.__dict__:
862
- raise ValueError("@python_2_unicode_compatible cannot be applied "
863
- "to %s because it doesn't define __str__()." %
864
- klass.__name__)
865
- klass.__unicode__ = klass.__str__
866
- klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
867
- return klass
868
-
869
-
870
- # Complete the moves implementation.
871
- # This code is at the end of this module to speed up module loading.
872
- # Turn this module into a package.
873
- __path__ = [] # required for PEP 302 and PEP 451
874
- __package__ = __name__ # see PEP 366 @ReservedAssignment
875
- if globals().get("__spec__") is not None:
876
- __spec__.submodule_search_locations = [] # PEP 451 @UndefinedVariable
877
- # Remove other six meta path importers, since they cause problems. This can
878
- # happen if six is removed from sys.modules and then reloaded. (Setuptools does
879
- # this for some reason.)
880
- if sys.meta_path:
881
- for i, importer in enumerate(sys.meta_path):
882
- # Here's some real nastiness: Another "instance" of the six module might
883
- # be floating around. Therefore, we can't use isinstance() to check for
884
- # the six meta path importer, since the other six instance will have
885
- # inserted an importer with different class.
886
- if (type(importer).__name__ == "_SixMetaPathImporter" and
887
- importer.name == __name__):
888
- del sys.meta_path[i]
889
- break
890
- del i, importer
891
- # Finally, add the importer to the meta path import hook.
892
- sys.meta_path.append(_importer)