Skip to content

Commit

Permalink
spaces in keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe committed Oct 25, 2019
1 parent 13637af commit 22cd13a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

__version = '0.5.4'
__version = '0.5.5'

INSTALL_REQUIRE = ['requests>=2.20.0']

Expand Down
14 changes: 10 additions & 4 deletions src/webscrapetools/keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import itertools
import logging
import threading
from typing import Tuple, Iterable, List, MutableSequence
from typing import Tuple, Iterable, List, MutableSequence, Callable

from webscrapetools import osaccess
from datetime import datetime, timedelta
Expand Down Expand Up @@ -131,14 +131,20 @@ def list_keys():
keys = list()

def gather_keys(line):
yyyymmdd, key_md5, key_commas = line.strip().split(' ')
key = key_commas[1:-1]
fields = line.strip().split(' ')
parts = ' '.join(fields[2:])
key = parts[1:-1]
keys.append(key)

osaccess.process_file_by_line(index_name, line_processor=gather_keys)
scan_entries(gather_keys)
return sorted(keys)


def scan_entries(entry_processor: Callable[[str], None]):
index_name = _fileindex_name()
return osaccess.process_file_by_line(index_name, line_processor=entry_processor)


def is_store_enabled() -> bool:
return _get_store_path() is not None

Expand Down
10 changes: 10 additions & 0 deletions tests/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ def test_store(self):
self.assertListEqual(sorted(list(filter(lambda x: x != '30', map(str, range(100))))), keys)
empty_store()

def test_store_list_keys(self):
set_store_path('./output/tests', max_node_files=10, rebalancing_limit=30)
empty_store()
for count in range(100):
add_to_store('value ' + str(count), bytes(str(count), 'utf-8'))

keys = list_keys()
self.assertListEqual(sorted(['value ' + str(x) for x in range(100)]), keys)
empty_store()

def test_store_duplicate_keys(self):
set_store_path('./output/tests', max_node_files=10, rebalancing_limit=30)
empty_store()
Expand Down

0 comments on commit 22cd13a

Please sign in to comment.