aboutsummaryrefslogtreecommitdiff
path: root/src/ee
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-08-02 21:42:01 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2018-08-02 21:53:00 +0200
commite1012e314d6c21ad1b75082a292506cd751a9117 (patch)
tree4530dfff8cf7545d8395c6400fe5efc29e490c42 /src/ee
parentb6c8c2c103b98097adef2fd18547feb6fd7e1952 (diff)
downloadee-python-e1012e314d6c21ad1b75082a292506cd751a9117.tar.gz
ee-python-e1012e314d6c21ad1b75082a292506cd751a9117.tar.bz2
ee-python-e1012e314d6c21ad1b75082a292506cd751a9117.tar.xz
ee-python-e1012e314d6c21ad1b75082a292506cd751a9117.zip
o Fixing a bad bug and learning some Python: list.insert(index, value)
will only insert at index if the list is index long. If not it will just append them. Yay. Much better digikey part data now. Creating a ValueList that automatically expands the list. o Stopping with silly key and value replacements. o Updating tests.
Diffstat (limited to 'src/ee')
-rw-r--r--src/ee/digikey/doit.py4
-rw-r--r--src/ee/ds/__init__.py20
2 files changed, 17 insertions, 7 deletions
diff --git a/src/ee/digikey/doit.py b/src/ee/digikey/doit.py
index 6f7c2d5..0452530 100644
--- a/src/ee/digikey/doit.py
+++ b/src/ee/digikey/doit.py
@@ -142,9 +142,7 @@ def download_part_facts(output: DataSet, in_ds: DataSet):
for a in product.attributes:
key = "{}/{}".format(a.attribute_type.id, a.attribute_type.label)
- key = key.replace("%", "_")
- value = a.value.replace("%", "%%")
- o.set(key, value)
+ o.set(key, a.value)
def task_digikey_fetch_full_part_facts():
diff --git a/src/ee/ds/__init__.py b/src/ee/ds/__init__.py
index 5b4da4d..026ab9b 100644
--- a/src/ee/ds/__init__.py
+++ b/src/ee/ds/__init__.py
@@ -15,7 +15,6 @@ class ObjectType(object):
def __init__(self, name: str):
self._name = name
self._fields = [] # type: List[str]
- self._objects = {}
def __eq__(self, o) -> bool:
other = o # type: ObjectType
@@ -54,11 +53,24 @@ class ObjectType(object):
class Object(object):
+ class ValueList(list):
+ """An auto-expanding version of list."""
+
+ def __setitem__(self, index, value):
+ if index >= len(self):
+ self.extend([None] * (index + 1 - len(self)))
+ list.__setitem__(self, index, value)
+
+ def __getitem__(self, index):
+ if index >= len(self):
+ self.extend([None] * (index + 1 - len(self)))
+ return list.__getitem__(self, index)
+
def __init__(self, ds: "DataSet", ot: ObjectType, key: str):
self._ds = ds
self._ot = ot
self._key = key
- self._data = []
+ self._data = Object.ValueList()
@property
def object_type(self):
@@ -72,7 +84,7 @@ class Object(object):
if self._ds._frozen:
raise Exception("This data set is frozen")
idx = self._ot.index_of(key, create=True)
- self._data.insert(idx, value)
+ self._data[idx] = value
return self
@@ -115,7 +127,7 @@ class Object(object):
def get(self, key: str) -> Optional[str]:
idx = self._ot.index_of(key)
- return self._data[idx] if idx is not None and idx < len(self._data) else None
+ return self._data[idx] if idx is not None else None
def get_req(self, key: str) -> str:
idx = self._ot.index_of(key)