|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 | 15 | from __future__ import with_statement
|
| 16 | +from _weakref import ref |
16 | 17 | import calendar
|
| 18 | +from collections import OrderedDict |
17 | 19 | from collections.abc import Mapping
|
18 | 20 | import datetime
|
19 | 21 | from functools import total_ordering
|
20 |
| -import logging |
21 | 22 | from itertools import chain
|
| 23 | +import keyword |
| 24 | +import logging |
22 | 25 | import pickle
|
23 | 26 | import random
|
24 | 27 | import re
|
25 |
| -import uuid |
| 28 | +import socket |
26 | 29 | import sys
|
| 30 | +import time |
| 31 | +import uuid |
27 | 32 |
|
28 | 33 | _HAS_GEOMET = True
|
29 | 34 | try:
|
@@ -213,147 +218,6 @@ def _resolve_contact_points_to_string_map(contact_points):
|
213 | 218 | )
|
214 | 219 |
|
215 | 220 |
|
216 |
| -try: |
217 |
| - from collections import OrderedDict |
218 |
| -except ImportError: |
219 |
| - # OrderedDict from Python 2.7+ |
220 |
| - |
221 |
| - # Copyright (c) 2009 Raymond Hettinger |
222 |
| - # |
223 |
| - # Permission is hereby granted, free of charge, to any person |
224 |
| - # obtaining a copy of this software and associated documentation files |
225 |
| - # (the "Software"), to deal in the Software without restriction, |
226 |
| - # including without limitation the rights to use, copy, modify, merge, |
227 |
| - # publish, distribute, sublicense, and/or sell copies of the Software, |
228 |
| - # and to permit persons to whom the Software is furnished to do so, |
229 |
| - # subject to the following conditions: |
230 |
| - # |
231 |
| - # The above copyright notice and this permission notice shall be |
232 |
| - # included in all copies or substantial portions of the Software. |
233 |
| - # |
234 |
| - # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
235 |
| - # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
236 |
| - # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
237 |
| - # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
238 |
| - # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
239 |
| - # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
240 |
| - # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
241 |
| - # OTHER DEALINGS IN THE SOFTWARE. |
242 |
| - from UserDict import DictMixin |
243 |
| - |
244 |
| - class OrderedDict(dict, DictMixin): # noqa |
245 |
| - """ A dictionary which maintains the insertion order of keys. """ |
246 |
| - |
247 |
| - def __init__(self, *args, **kwds): |
248 |
| - """ A dictionary which maintains the insertion order of keys. """ |
249 |
| - |
250 |
| - if len(args) > 1: |
251 |
| - raise TypeError('expected at most 1 arguments, got %d' % len(args)) |
252 |
| - try: |
253 |
| - self.__end |
254 |
| - except AttributeError: |
255 |
| - self.clear() |
256 |
| - self.update(*args, **kwds) |
257 |
| - |
258 |
| - def clear(self): |
259 |
| - self.__end = end = [] |
260 |
| - end += [None, end, end] # sentinel node for doubly linked list |
261 |
| - self.__map = {} # key --> [key, prev, next] |
262 |
| - dict.clear(self) |
263 |
| - |
264 |
| - def __setitem__(self, key, value): |
265 |
| - if key not in self: |
266 |
| - end = self.__end |
267 |
| - curr = end[1] |
268 |
| - curr[2] = end[1] = self.__map[key] = [key, curr, end] |
269 |
| - dict.__setitem__(self, key, value) |
270 |
| - |
271 |
| - def __delitem__(self, key): |
272 |
| - dict.__delitem__(self, key) |
273 |
| - key, prev, next = self.__map.pop(key) |
274 |
| - prev[2] = next |
275 |
| - next[1] = prev |
276 |
| - |
277 |
| - def __iter__(self): |
278 |
| - end = self.__end |
279 |
| - curr = end[2] |
280 |
| - while curr is not end: |
281 |
| - yield curr[0] |
282 |
| - curr = curr[2] |
283 |
| - |
284 |
| - def __reversed__(self): |
285 |
| - end = self.__end |
286 |
| - curr = end[1] |
287 |
| - while curr is not end: |
288 |
| - yield curr[0] |
289 |
| - curr = curr[1] |
290 |
| - |
291 |
| - def popitem(self, last=True): |
292 |
| - if not self: |
293 |
| - raise KeyError('dictionary is empty') |
294 |
| - if last: |
295 |
| - key = next(reversed(self)) |
296 |
| - else: |
297 |
| - key = next(iter(self)) |
298 |
| - value = self.pop(key) |
299 |
| - return key, value |
300 |
| - |
301 |
| - def __reduce__(self): |
302 |
| - items = [[k, self[k]] for k in self] |
303 |
| - tmp = self.__map, self.__end |
304 |
| - del self.__map, self.__end |
305 |
| - inst_dict = vars(self).copy() |
306 |
| - self.__map, self.__end = tmp |
307 |
| - if inst_dict: |
308 |
| - return (self.__class__, (items,), inst_dict) |
309 |
| - return self.__class__, (items,) |
310 |
| - |
311 |
| - def keys(self): |
312 |
| - return list(self) |
313 |
| - |
314 |
| - setdefault = DictMixin.setdefault |
315 |
| - update = DictMixin.update |
316 |
| - pop = DictMixin.pop |
317 |
| - values = DictMixin.values |
318 |
| - items = DictMixin.items |
319 |
| - iterkeys = DictMixin.iterkeys |
320 |
| - itervalues = DictMixin.itervalues |
321 |
| - iteritems = DictMixin.iteritems |
322 |
| - |
323 |
| - def __repr__(self): |
324 |
| - if not self: |
325 |
| - return '%s()' % (self.__class__.__name__,) |
326 |
| - return '%s(%r)' % (self.__class__.__name__, self.items()) |
327 |
| - |
328 |
| - def copy(self): |
329 |
| - return self.__class__(self) |
330 |
| - |
331 |
| - @classmethod |
332 |
| - def fromkeys(cls, iterable, value=None): |
333 |
| - d = cls() |
334 |
| - for key in iterable: |
335 |
| - d[key] = value |
336 |
| - return d |
337 |
| - |
338 |
| - def __eq__(self, other): |
339 |
| - if isinstance(other, OrderedDict): |
340 |
| - if len(self) != len(other): |
341 |
| - return False |
342 |
| - for p, q in zip(self.items(), other.items()): |
343 |
| - if p != q: |
344 |
| - return False |
345 |
| - return True |
346 |
| - return dict.__eq__(self, other) |
347 |
| - |
348 |
| - def __ne__(self, other): |
349 |
| - return not self == other |
350 |
| - |
351 |
| - |
352 |
| -# WeakSet from Python 2.7+ (https://code.google.com/p/weakrefset) |
353 |
| - |
354 |
| -from _weakref import ref |
355 |
| - |
356 |
| - |
357 | 221 | class _IterationGuard(object):
|
358 | 222 | # This context manager registers itself in the current iterators of the
|
359 | 223 | # weak container, such as to delay all removals until the context manager
|
@@ -916,10 +780,6 @@ def _serialize_key(self, key):
|
916 | 780 | return self.cass_key_type.serialize(key, self.protocol_version)
|
917 | 781 |
|
918 | 782 |
|
919 |
| -import datetime |
920 |
| -import time |
921 |
| - |
922 |
| - |
923 | 783 | @total_ordering
|
924 | 784 | class Time(object):
|
925 | 785 | '''
|
@@ -1145,97 +1005,9 @@ def __str__(self):
|
1145 | 1005 | # If we overflow datetime.[MIN|MAX]
|
1146 | 1006 | return str(self.days_from_epoch)
|
1147 | 1007 |
|
1148 |
| -import socket |
1149 |
| -if hasattr(socket, 'inet_pton'): |
1150 |
| - inet_pton = socket.inet_pton |
1151 |
| - inet_ntop = socket.inet_ntop |
1152 |
| -else: |
1153 |
| - """ |
1154 |
| - Windows doesn't have socket.inet_pton and socket.inet_ntop until Python 3.4 |
1155 |
| - This is an alternative impl using ctypes, based on this win_inet_pton project: |
1156 |
| - https://github.com/hickeroar/win_inet_pton |
1157 |
| - """ |
1158 |
| - import ctypes |
1159 |
| - |
1160 |
| - class sockaddr(ctypes.Structure): |
1161 |
| - """ |
1162 |
| - Shared struct for ipv4 and ipv6. |
1163 |
| -
|
1164 |
| - https://msdn.microsoft.com/en-us/library/windows/desktop/ms740496(v=vs.85).aspx |
1165 |
| -
|
1166 |
| - ``__pad1`` always covers the port. |
1167 | 1008 |
|
1168 |
| - When being used for ``sockaddr_in6``, ``ipv4_addr`` actually covers ``sin6_flowinfo``, resulting |
1169 |
| - in proper alignment for ``ipv6_addr``. |
1170 |
| - """ |
1171 |
| - _fields_ = [("sa_family", ctypes.c_short), |
1172 |
| - ("__pad1", ctypes.c_ushort), |
1173 |
| - ("ipv4_addr", ctypes.c_byte * 4), |
1174 |
| - ("ipv6_addr", ctypes.c_byte * 16), |
1175 |
| - ("__pad2", ctypes.c_ulong)] |
1176 |
| - |
1177 |
| - if hasattr(ctypes, 'windll'): |
1178 |
| - WSAStringToAddressA = ctypes.windll.ws2_32.WSAStringToAddressA |
1179 |
| - WSAAddressToStringA = ctypes.windll.ws2_32.WSAAddressToStringA |
1180 |
| - else: |
1181 |
| - def not_windows(*args): |
1182 |
| - raise OSError("IPv6 addresses cannot be handled on Windows. " |
1183 |
| - "Missing ctypes.windll") |
1184 |
| - WSAStringToAddressA = not_windows |
1185 |
| - WSAAddressToStringA = not_windows |
1186 |
| - |
1187 |
| - def inet_pton(address_family, ip_string): |
1188 |
| - if address_family == socket.AF_INET: |
1189 |
| - return socket.inet_aton(ip_string) |
1190 |
| - |
1191 |
| - addr = sockaddr() |
1192 |
| - addr.sa_family = address_family |
1193 |
| - addr_size = ctypes.c_int(ctypes.sizeof(addr)) |
1194 |
| - |
1195 |
| - if WSAStringToAddressA( |
1196 |
| - ip_string, |
1197 |
| - address_family, |
1198 |
| - None, |
1199 |
| - ctypes.byref(addr), |
1200 |
| - ctypes.byref(addr_size) |
1201 |
| - ) != 0: |
1202 |
| - raise socket.error(ctypes.FormatError()) |
1203 |
| - |
1204 |
| - if address_family == socket.AF_INET6: |
1205 |
| - return ctypes.string_at(addr.ipv6_addr, 16) |
1206 |
| - |
1207 |
| - raise socket.error('unknown address family') |
1208 |
| - |
1209 |
| - def inet_ntop(address_family, packed_ip): |
1210 |
| - if address_family == socket.AF_INET: |
1211 |
| - return socket.inet_ntoa(packed_ip) |
1212 |
| - |
1213 |
| - addr = sockaddr() |
1214 |
| - addr.sa_family = address_family |
1215 |
| - addr_size = ctypes.c_int(ctypes.sizeof(addr)) |
1216 |
| - ip_string = ctypes.create_string_buffer(128) |
1217 |
| - ip_string_size = ctypes.c_int(ctypes.sizeof(ip_string)) |
1218 |
| - |
1219 |
| - if address_family == socket.AF_INET6: |
1220 |
| - if len(packed_ip) != ctypes.sizeof(addr.ipv6_addr): |
1221 |
| - raise socket.error('packed IP wrong length for inet_ntoa') |
1222 |
| - ctypes.memmove(addr.ipv6_addr, packed_ip, 16) |
1223 |
| - else: |
1224 |
| - raise socket.error('unknown address family') |
1225 |
| - |
1226 |
| - if WSAAddressToStringA( |
1227 |
| - ctypes.byref(addr), |
1228 |
| - addr_size, |
1229 |
| - None, |
1230 |
| - ip_string, |
1231 |
| - ctypes.byref(ip_string_size) |
1232 |
| - ) != 0: |
1233 |
| - raise socket.error(ctypes.FormatError()) |
1234 |
| - |
1235 |
| - return ip_string[:ip_string_size.value - 1] |
1236 |
| - |
1237 |
| - |
1238 |
| -import keyword |
| 1009 | +inet_pton = socket.inet_pton |
| 1010 | +inet_ntop = socket.inet_ntop |
1239 | 1011 |
|
1240 | 1012 |
|
1241 | 1013 | # similar to collections.namedtuple, reproduced here because Python 2.6 did not have the rename logic
|
|
0 commit comments