Exemplo n.º 1
0
from .state_abbr import (
    MAPPER_STATE_ABBR_SHORT_TO_LONG,
    MAPPER_STATE_ABBR_LONG_TO_SHORT,
)

SORT_BY_DIST = "dist"
"""
a string for ``sort_by`` arguments. order the result by distance from a coordinates.
"""

DEFAULT_LIMIT = 5
"""
default number of results to return.
"""

HOME = Path.home().abspath
HOME_USZIPCODE = Path(HOME, ".uszipcode").abspath


def validate_enum_arg(
    enum_class: typing.Type[enum.Enum],
    attr: str,
    value: enum.Enum,
):
    if not isinstance(value, enum_class):
        raise TypeError(
            ("param '{}' validation error: "
             "'{}' is not a valid {} type!").format(attr, value, enum_class))

    if value not in enum_class:  # pragma: no cover
        raise ValueError(
Exemplo n.º 2
0
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals

import base64
from pathlib_mate import Path
from cryptography.fernet import Fernet
from windtalker.cipher import BaseCipher
from windtalker.exc import PasswordError
from windtalker import fingerprint
from windtalker import py23

if py23.is_py2:
    input = raw_input

HOME_DIR = Path.home()
WINDTALKER_CONFIG_FILE = Path(HOME_DIR, ".windtalker")


def read_windtalker_password():  # pragma: no cover
    return WINDTALKER_CONFIG_FILE.read_text(encoding="utf-8").strip()


class SymmetricCipher(Fernet, BaseCipher):
    """
    A symmetric encryption algorithm utility class helps you easily
    encrypt/decrypt text, files and even a directory.

    :param password: The secret password you use to encrypt all your message.
      If you feel uncomfortable to put that in your code, you can leave it
      empty. The system will ask you manually enter that later.
Exemplo n.º 3
0
"""

from __future__ import print_function

import requests

from pathlib_mate import Path

try:
    from .pkg.atomicwrites import atomic_write
    from .pkg.sqlalchemy_mate import engine_creator
except:
    from uszipcode.pkg.atomicwrites import atomic_write
    from uszipcode.pkg.sqlalchemy_mate import engine_creator

db_file_dir = Path.home().append_parts(".uszipcode")
db_file_dir.mkdir(exist_ok=True)

simple_db_file_path = db_file_dir.append_parts("simple_db.sqlite")
db_file_path = db_file_dir.append_parts("db.sqlite")


def is_simple_db_file_exists():
    if simple_db_file_path.exists():
        if simple_db_file_path.size >= 5 * 1000 * 1000:
            return True
    return False


def is_db_file_exists():
    if db_file_path.exists():
Exemplo n.º 4
0
  http://federalgovernmentzipcodes.us/
- 2010 zcta2010 population, wage, houseunit, land, water area data from
  from http://proximityone.com/cen2010_zcta_dp.htm
- 2015-10-01 geometry google map geocoding data from http://maps.google.com
"""

import requests
from pathlib_mate import Path
from pathlib_mate.helper import repr_data_size
from atomicwrites import atomic_write
import sqlalchemy_mate as sam

SIMPLE_DB_FILE_DOWNLOAD_URL = "https://github.com/MacHu-GWU/uszipcode-project/releases/download/1.0.1.db/simple_db.sqlite"
COMPREHENSIVE_DB_FILE_DOWNLOAD_URL = "https://github.com/MacHu-GWU/uszipcode-project/releases/download/1.0.1.db/comprehensive_db.sqlite"

USZIPCODE_HOME = Path(Path.home(), ".uszipcode")
DEFAULT_SIMPLE_DB_FILE_PATH = Path(USZIPCODE_HOME, "simple_db.sqlite")
DEFAULT_COMPREHENSIVE_DB_FILE_PATH = Path(USZIPCODE_HOME,
                                          "comprehensive_db.sqlite")


def download_db_file(
    db_file_path: str,
    download_url: str,
    chunk_size: int,
    progress_size: int,
):
    Path(db_file_path).parent.mkdir(parents=True, exist_ok=True)

    print(f"Download {db_file_path} from {download_url} ...")
    response = requests.get(download_url, stream=True)