this repo has no description
at trunk 196 lines 4.6 kB view raw
1#!/usr/bin/env python3 2# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 3"""Array.array module TODO(T55711876): provide an implemenation""" 4 5from builtins import _float, _index, _obj_as_int 6from operator import length_hint 7 8from _builtins import ( 9 _builtin, 10 _bytearray_check, 11 _bytes_check, 12 _float_check, 13 _int_check, 14 _list_check, 15 _list_getitem, 16 _list_len, 17 _object_type_hasattr, 18 _slice_check, 19 _str_check, 20 _str_len, 21 _tuple_check, 22 _tuple_getitem, 23 _tuple_len, 24 _type, 25 _type_subclass_guard, 26 _Unbound, 27 _unimplemented, 28) 29 30 31def _array_append(obj, val): 32 _builtin() 33 34 35def _array_check(obj): 36 _builtin() 37 38 39def _array_getitem(obj, index): 40 _builtin() 41 42 43def _array_new(cls, typecode, init_len): 44 _builtin() 45 46 47def _array_reserve(self, size): 48 _builtin() 49 50 51def _array_setitem(obj, index, value): 52 _builtin() 53 54 55def _array_repeat(self, count): 56 _builtin() 57 58 59def _array_value(typecode, value): 60 if typecode == "f" or typecode == "d": 61 return _float(value) 62 elif typecode == "u": 63 _unimplemented() 64 if _float_check(value): 65 raise TypeError("array item must be integer") 66 return _obj_as_int(value) 67 68 69class array(bootstrap=True): 70 def __getitem__(self, key): 71 result = _array_getitem(self, key) 72 if result is not _Unbound: 73 return result 74 if _slice_check(key): 75 _unimplemented() 76 return _array_getitem(self, _index(key)) 77 78 def __len__(self): 79 _builtin() 80 81 def __mul__(self, other): 82 result = _array_repeat(self, other) 83 if result is not _Unbound: 84 return result 85 return _array_repeat(self, _index(other)) 86 87 @staticmethod 88 def __new__(cls, typecode, initializer=None): 89 _type_subclass_guard(cls, array) 90 if not _str_check(typecode) or _str_len(typecode) != 1: 91 raise TypeError( 92 "array() argument 1 must be a unicode character, not " 93 f"{_type(typecode).__name__}" 94 ) 95 if initializer is None: 96 return _array_new(cls, typecode, 0) 97 98 if typecode != "u": 99 if _str_check(initializer): 100 raise TypeError( 101 "cannot use a str to initialize an array with typecode " 102 f"'{typecode}'" 103 ) 104 if _array_check(initializer) and initializer.typecode == "u": 105 raise TypeError( 106 "cannot use a unicode array to initialize an array with " 107 f"typecode '{typecode}'" 108 ) 109 110 if typecode == "u": 111 _unimplemented() 112 113 result = _array_new(cls, typecode, 0) 114 result.extend(initializer) 115 return result 116 117 def __setitem__(self, key, value): 118 result = _array_setitem(self, key, value) 119 if result is not _Unbound: 120 return result 121 if _slice_check(key): 122 _unimplemented() 123 return _array_setitem(self, _index(key), _array_value(self.typecode, value)) 124 125 def itemsize(self): 126 _unimplemented() 127 128 def append(self, value): 129 result = _array_append(self, value) 130 if result is not _Unbound: 131 return result 132 return _array_append(self, _array_value(self.typecode, value)) 133 134 def buffer_info(self): 135 _unimplemented() 136 137 def byteswap(self): 138 _unimplemented() 139 140 def count(self, value): 141 _unimplemented() 142 143 def extend(self, iterable): 144 if _array_check(iterable): 145 _unimplemented() 146 _array_reserve(self, self.__len__() + length_hint(iterable)) 147 for item in iterable: 148 array.append(self, item) 149 150 def frombytes(self, string_value): 151 _unimplemented() 152 153 def fromfile(self, file_object, num_items): 154 _unimplemented() 155 156 def fromlist(self, list_in): 157 _unimplemented() 158 159 def fromstring(self): 160 _unimplemented() 161 162 def fromunicode(self, unicode_str): 163 _unimplemented() 164 165 def index(self, value): 166 _unimplemented() 167 168 def insert(self, value, position): 169 _unimplemented() 170 171 def pop(self, index): 172 _unimplemented() 173 174 def remove(self, value): 175 _unimplemented() 176 177 def reverse(self): 178 _unimplemented() 179 180 def tobytes(self): 181 _unimplemented() 182 183 def tofile(self, file_object): 184 _unimplemented() 185 186 def tolist(self): 187 _unimplemented() 188 189 def tostring(self): 190 _unimplemented() 191 192 def tounicode(self): 193 _unimplemented() 194 195 196typecodes = "bBuhHiIlLqQfd"