Skip to content

Commit c384fdf

Browse files
committed
adding the rest of the files
1 parent 1aa9e36 commit c384fdf

13 files changed

+704
-0
lines changed

.gitignore

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
*.pex
2+
# Created by https://www.toptal.com/developers/gitignore/api/python,macos,linux
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=python,macos,linux
4+
5+
### Linux ###
6+
*~
7+
8+
# temporary files which can be created if a process still has a handle open of a deleted file
9+
.fuse_hidden*
10+
11+
# KDE directory preferences
12+
.directory
13+
14+
# Linux trash folder which might appear on any partition or disk
15+
.Trash-*
16+
17+
# .nfs files are created when an open file is removed but is still being accessed
18+
.nfs*
19+
20+
### macOS ###
21+
# General
22+
.DS_Store
23+
.AppleDouble
24+
.LSOverride
25+
26+
# Icon must end with two \r
27+
Icon
28+
29+
# Thumbnails
30+
._*
31+
32+
# Files that might appear in the root of a volume
33+
.DocumentRevisions-V100
34+
.fseventsd
35+
.Spotlight-V100
36+
.TemporaryItems
37+
.Trashes
38+
.VolumeIcon.icns
39+
.com.apple.timemachine.donotpresent
40+
41+
# Directories potentially created on remote AFP share
42+
.AppleDB
43+
.AppleDesktop
44+
Network Trash Folder
45+
Temporary Items
46+
.apdisk
47+
48+
### Python ###
49+
# Byte-compiled / optimized / DLL files
50+
__pycache__/
51+
*.py[cod]
52+
*$py.class
53+
54+
# C extensions
55+
*.so
56+
57+
# Distribution / packaging
58+
.Python
59+
build/
60+
develop-eggs/
61+
dist/
62+
downloads/
63+
eggs/
64+
.eggs/
65+
lib/
66+
lib64/
67+
parts/
68+
sdist/
69+
var/
70+
wheels/
71+
pip-wheel-metadata/
72+
share/python-wheels/
73+
*.egg-info/
74+
.installed.cfg
75+
*.egg
76+
MANIFEST
77+
78+
# PyInstaller
79+
# Usually these files are written by a python script from a template
80+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
81+
*.manifest
82+
*.spec
83+
84+
# Installer logs
85+
pip-log.txt
86+
pip-delete-this-directory.txt
87+
88+
# Unit test / coverage reports
89+
htmlcov/
90+
.tox/
91+
.nox/
92+
.coverage
93+
.coverage.*
94+
.cache
95+
nosetests.xml
96+
coverage.xml
97+
*.cover
98+
*.py,cover
99+
.hypothesis/
100+
.pytest_cache/
101+
102+
# Translations
103+
*.mo
104+
*.pot
105+
106+
# Django stuff:
107+
*.log
108+
local_settings.py
109+
db.sqlite3
110+
db.sqlite3-journal
111+
112+
# Flask stuff:
113+
instance/
114+
.webassets-cache
115+
116+
# Scrapy stuff:
117+
.scrapy
118+
119+
# Sphinx documentation
120+
docs/_build/
121+
122+
# PyBuilder
123+
target/
124+
125+
# Jupyter Notebook
126+
.ipynb_checkpoints
127+
128+
# IPython
129+
profile_default/
130+
ipython_config.py
131+
132+
# pyenv
133+
.python-version
134+
135+
# pipenv
136+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
137+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
138+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
139+
# install all needed dependencies.
140+
#Pipfile.lock
141+
142+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
143+
__pypackages__/
144+
145+
# Celery stuff
146+
celerybeat-schedule
147+
celerybeat.pid
148+
149+
# SageMath parsed files
150+
*.sage.py
151+
152+
# Environments
153+
.env
154+
.venv
155+
env/
156+
venv/
157+
ENV/
158+
env.bak/
159+
venv.bak/
160+
161+
# Spyder project settings
162+
.spyderproject
163+
.spyproject
164+
165+
# Rope project settings
166+
.ropeproject
167+
168+
# mkdocs documentation
169+
/site
170+
171+
# mypy
172+
.mypy_cache/
173+
.dmypy.json
174+
dmypy.json
175+
176+
# Pyre type checker
177+
.pyre/
178+
179+
# pytype static type analyzer
180+
.pytype/
181+
182+
# End of https://www.toptal.com/developers/gitignore/api/python,macos,linux

Makefile

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Application options
2+
APP_NAME := babble
3+
4+
# Doc options
5+
SPHINXOPTS ?=
6+
SPHINXBUILD ?= sphinx-build
7+
SOURCEDIR = docs
8+
BUILDDIR = build
9+
10+
.PHONY: help
11+
help:
12+
@echo "Available Options:"
13+
@echo " WRITE THIS UP"
14+
15+
.PHONY: clean-pyc
16+
clean-pyc:
17+
find . -name '*.pyc' -exec rm -f {} +
18+
find . -name '*.pyo' -exec rm -f {} +
19+
find . -name '*~' -exec rm -f {} +
20+
find . -name '__pycache__' -exec rm -fr {} +
21+
22+
.PHONY: clean-build
23+
clean-build:
24+
rm -rf build/
25+
rm -rf dist/
26+
rm -rf *.egg-info
27+
28+
clean-pex:
29+
rm -f *.pex
30+
rm -f requirements.txt
31+
32+
.PHONY: clean
33+
clean: clean-build clean-pyc clean-pex
34+
35+
requirements.txt:
36+
pip -q install pipreqs
37+
pipreqs --no-pin
38+
39+
.PHONY: interperter
40+
interperter: requirements.txt
41+
pip . -q pex
42+
pex . -o interperter.pex
43+
44+
$(APP_NAME).pex: requirements.txt
45+
pip install -r requirements.txt
46+
python setup.py develop
47+
pex . -o $(APP_NAME).pex -e $(APP_NAME):launcher
48+
49+
.PHONY: dist
50+
dist: $(APP_NAME).pex
51+
52+
.PHONY: run
53+
run: $(APP_NAME).pex
54+
./$(APP_NAME).pex -c examples/gunicorn.conf.py
55+
56+
.PHONY: prototype
57+
prototype:
58+
pex -r requirements.txt -- dev.py
59+
60+
dev.pyc:
61+
python dev.py
62+
63+
.PHONY: clean-pyc dev
64+
dev: dev.pyc
65+
66+
.PHONY: lint
67+
lint:
68+
pylint babble/*
69+
70+
.PHONY: lint-extras
71+
lint-extras:
72+
pylint *.py
73+
74+
test: clean-pyc
75+
echo "NEED A TESTER"
76+
77+
coverage:
78+
echo "NEED COVERAGE"
79+
80+
coverage-upload:
81+
echo "NEED COVERAGE UPLOADED"
82+
83+
docs:
84+
@mkdir -p "$(BUILDDIR)"
85+
@mkdir -p {"$(BUILDDIR)/doctrees","$(BUILDDIR)/html"}
86+
$(SPHINXBUILD) -M "html" "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -v
87+
88+
clean-docs:
89+
@rm -rf "$(BUILDDIR)"
90+
91+
.PHONY: env
92+
env:
93+
pip install -r requirements.txt
94+
95+
.PHONY: pypi
96+
pypi: clean
97+
python setup.py sdist
98+
python setup.py bdist_wheel
99+
pip install twine
100+
twine upload dist/*
101+
102+
.PHONY: install
103+
install: clean
104+
python setup.py install
105+
106+
test_xml_to_json:
107+
curl -i -H "Content-Type: application/xml" -X POST \
108+
-d '<?xml version="1.0" ?><person><name>john</name><age>20</age></person>' \
109+
http://127.0.0.1:8080/xml_to_json
110+
111+
test_xml_to_json_socket:
112+
curl -i -H "Content-Type: application/xml" -X POST \
113+
-d '<?xml version="1.0" ?><person><name>john</name><age>20</age></person>' \
114+
--unix-socket gunicorn.sock \
115+
http://127.0.0.1:8080/xml_to_json
116+
117+
test_json_to_xml:
118+
curl -i -H "Content-Type: application/json" -X POST \
119+
-d '{"userId":"1", "username": "fizz bizz"}' \
120+
http://127.0.0.1:8080/json_to_xml

babble/__init__.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import argparse
2+
import types
3+
from importlib.machinery import SourceFileLoader
4+
import logging
5+
from .web_server import StandaloneApplication
6+
from .web_api import app
7+
8+
logger = logging.getLogger(__name__)
9+
10+
__version__ = 0.1
11+
12+
def config_importer(config_path):
13+
logger.info("LOGGING TEST FOR A CONFIG FILE")
14+
omit_config_keys = ["__builtins__", '__doc__', '__loader__',
15+
'__name__', '__package__', '__spec__']
16+
17+
loader = SourceFileLoader("conf", config_path)
18+
mod = types.ModuleType(loader.name)
19+
loader.exec_module(mod)
20+
options = vars(mod)
21+
for key in omit_config_keys:
22+
del options[key]
23+
return options
24+
25+
def launcher(live_reload=False):
26+
logging.basicConfig(level=logging.DEBUG,
27+
format='%(asctime)s %(name)s %(levelname)s:%(message)s')
28+
29+
arg_parse = argparse.ArgumentParser(description="A super basic Flask + Gunicorn app")
30+
arg_parse.add_argument("-c", "--config-file", dest="config_file",
31+
help="Config File location", default=None)
32+
args = arg_parse.parse_args()
33+
34+
if not args.config_file:
35+
options = {
36+
'bind': '%s:%s' % ('127.0.0.1', '8080'),
37+
'workers': 3,
38+
'reload': live_reload,
39+
}
40+
else:
41+
options = config_importer(args.config_file)
42+
StandaloneApplication(app, options).run()

babble/conversions.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import json
2+
import xmltodict
3+
import dicttoxml
4+
5+
def xml_to_json(raw_xml):
6+
parsed_xml = xmltodict.parse(raw_xml, process_namespaces=True)
7+
return json.dumps(parsed_xml)
8+
9+
def json_to_xml(raw_json):
10+
parsed_json = json.loads(raw_json)
11+
return dicttoxml.dicttoxml(parsed_json)

babble/module_scanner.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pip_module_scanner.scanner import Scanner, ScannerException
2+
3+
try:
4+
scanner = Scanner(path="babble/")
5+
scanner.run()
6+
7+
# do whatever you want with the results here
8+
# example:
9+
for lib in scanner.libraries_found:
10+
print ("Found module %s at version %s" % (lib.key, lib.version))
11+
12+
except ScannerException as e:
13+
print("Error: %s" % str(e))

0 commit comments

Comments
 (0)