from py2store.base import Persister
from py2store.util import ModuleNotFoundErrorNiceMessage

with ModuleNotFoundErrorNiceMessage():
    from pyArango.connection import Connection


class ArangoDbPersister(Persister):
    """
    A basic ArangoDB persister.
    >>> from py2store.persisters._arangodb_in_progress import ArangoDbPersister
    >>> s = ArangoDbPersister()
    >>> k = {'key': '777'} # Each collection will happily accept user-defined _key values.
    >>> v = {'val': 'bar'}
    >>> for _key in s:
    ...     del s[_key]
    ...
    >>> k in s
    False
    >>> len(s)
    0
    >>> s[k] = v
    >>> len(s)
    1
    >>> s[k]
    {'val': 'bar'}
    >>> s.get(k)
    {'val': 'bar'}
    >>> s.get({'not': 'a key'}, {'default': 'val'})  # testing s.get with default
    {'default': 'val'}
    >>> list(s.values())
Пример #2
0
from py2store.util import ModuleNotFoundErrorNiceMessage
from py2store.stores.local_store import LocalBinaryStore
from py2store import wrap_kvs

from io import BytesIO

with ModuleNotFoundErrorNiceMessage(
        "docx wasn't found. Search and install python-docx package. "
        "For example, you could do: pip install python-docx"):
    import docx  # https://automatetheboringstuff.com/chapter13/


def get_text_from_docx(doc):
    """Get text from docx.Document object.
    More precisely, 'text' will be the newline-separated concatenation of the .text attributes of every paragraph.
    You can got a document object from a file path of pointer f by doing:
        import docx  # pip install python-docx
        doc = docx.Document(f)
    """
    fullText = []
    for para in doc.paragraphs:
        fullText.append(para.text)
    return '\n'.join(fullText)


def bytes_to_doc(doc_bytes):
    return docx.Document(BytesIO(doc_bytes))


LocalDocxStore = wrap_kvs(LocalBinaryStore,
                          'LocalDocxStore',