aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2017-01-01 17:24:04 +0100
committerache <ache@ache.one>2017-01-01 17:24:04 +0100
commitda51dfca7b47bc0a5cbb63b7e0af6328b28b0050 (patch)
tree02b3c92a2010d25833bac2dd9ccb402096693a19
Init commitHEADmaster
-rw-r--r--MANIFEST.in1
-rw-r--r--Makefile9
-rw-r--r--README.md21
-rw-r--r--libkyf/__init__.py15
-rw-r--r--libkyf/__pycache__/__init__.cpython-35.pycbin0 -> 340 bytes
-rw-r--r--libkyf/__pycache__/dump.cpython-35.pycbin0 -> 4236 bytes
-rw-r--r--libkyf/__pycache__/load.cpython-35.pycbin0 -> 4230 bytes
-rw-r--r--libkyf/dump.py198
-rw-r--r--libkyf/libkyf.py187
-rw-r--r--libkyf/load.py196
-rw-r--r--setup.py36
11 files changed, 663 insertions, 0 deletions
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..efa752e
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1 @@
+include *.md
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..36afb01
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+
+
+install: libkyf/libkyf.py
+ python setup.py install
+ @echo 'Installation success'
+
+clean:
+ rm -vrf ./build ./dist ./*.egg-info
+ @echo 'Done'
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0248940
--- /dev/null
+++ b/README.md
@@ -0,0 +1,21 @@
+libkyf - BibliothĂšque simple de lecture du format kyg
+================================================================
+
+Ce module permet de facilement et rapidement lire le format kyf.
+
+Le KISS Yolo Format est un langage de description rapide Ă  parser et plus
+simple que les Markup Languages habituels. Sa particularitĂ© et d'ĂȘtre
+fortement typé et de réduire au minimum les échappements afin de rester
+simple et intuitif.
+
+
+import libkyf
+
+import libkyf as kyf
+
+
+Seule 2 fonctions sont utiles chez libky. Load pour lire et dump pour Ă©crire.
+
+
+Licence : GNU GPL v3
+
diff --git a/libkyf/__init__.py b/libkyf/__init__.py
new file mode 100644
index 0000000..673b50a
--- /dev/null
+++ b/libkyf/__init__.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+
+Ce module permet de manipuler des données du format kyf.
+C'est Ă  dire lire et Ă©crire dans ce format.
+
+"""
+
+
+__version__ = "0.1"
+
+from .load import load
+from .dump import dump
diff --git a/libkyf/__pycache__/__init__.cpython-35.pyc b/libkyf/__pycache__/__init__.cpython-35.pyc
new file mode 100644
index 0000000..d8d766a
--- /dev/null
+++ b/libkyf/__pycache__/__init__.cpython-35.pyc
Binary files differ
diff --git a/libkyf/__pycache__/dump.cpython-35.pyc b/libkyf/__pycache__/dump.cpython-35.pyc
new file mode 100644
index 0000000..c5042ec
--- /dev/null
+++ b/libkyf/__pycache__/dump.cpython-35.pyc
Binary files differ
diff --git a/libkyf/__pycache__/load.cpython-35.pyc b/libkyf/__pycache__/load.cpython-35.pyc
new file mode 100644
index 0000000..4f89f05
--- /dev/null
+++ b/libkyf/__pycache__/load.cpython-35.pyc
Binary files differ
diff --git a/libkyf/dump.py b/libkyf/dump.py
new file mode 100644
index 0000000..b58576c
--- /dev/null
+++ b/libkyf/dump.py
@@ -0,0 +1,198 @@
+#!/usr/bin/python
+# -*-coding:utf-8 -*
+
+"""
+
+Implémentation de l'écriture du format kyf.
+
+"""
+
+
+import re, os, sys
+import base64
+import binascii
+import datetime
+
+
+__all__ = ['dump']
+
+
+
+def _tokyf(d, base = '', nbSpace = 0):
+ out = ""
+ for key, v in d.items():
+ if type(v) is int :
+ out += (key +'#' + str(v)) + '\n'
+ elif type(v) is str:
+ out += (key + '=' + v) + '\n'
+ elif type(v) == datetime.datetime:
+ out += (key + '@' + str(v)) + '\n'
+ elif type(v) is dict:
+ out += ( '[ ' + key + ' ]' ) + '\n'
+ out += _tokyf(v, base+key+'.',nbSpace+2)
+ elif type(v) is list:
+ isMultiple=False
+ if len(v) == 0:
+ continue
+ for e in v[1:]:
+ if type(e) is not type(v[0]):
+ isMultiple = True
+ if isMultiple:
+ print(key + ' is a multi typed list', file=sys.stderr)
+ exit()
+ else:
+ if type(v[0]) is int:
+ out += ( '[[#' + base + key + ' ]]' ) + '\n'
+ for i in v :
+ out += '#' + i + '\n'
+ elif type(v[0]) is str:
+ out += ( '[[=' + base + key + ' ]]' ) + '\n'
+ for i in v :
+ out += '=' + i + '\n'
+ elif str(type(v[0])) == "<class 'datetime.datetime'>":
+ out += ( '[[@' + key + ' ]]' ) + '\n'
+ for i in v :
+ out += '@' + i + '\n'
+ elif type(v[0]) is list:
+ out += ( '[[_' + key + ' ]]' ) + '\n'
+ for e in v:
+ out += _tokyf(e, base+key+'.',nbSpace+2)
+ elif type(v[0]) is dict:
+ for e in v:
+ out += ( '[[ ' + key + ' ]]' ) + '\n'
+ out += _tokyf(e, base+key+'.',nbSpace+2)
+ out += ('') + '\n'
+ else:
+ print(key + ' is a list of unknow type !' + str(type(v[0])) + ')',
+ file=sys.stderr)
+ exit()
+ else:
+ print('Type error :' + key +
+ ' don\'t have knowd type (' + str(type(v)) + ')', file=sys.stderr)
+ exit()
+ return out
+
+def getTo( d, key, dico=True ):
+ tD=d
+ ls = key.strip().split('.')
+ for i,k in enumerate(ls):
+ if type(tD) == dict:
+ if k in tD:
+ tD = tD[k]
+ else:
+ if dico:
+ tD[k] = dict()
+ else:
+ tD[k] = list()
+ tD = tD[k]
+ return tD
+ elif type(tD) == list:
+ if type(tD[-1]) == dict:
+ if k in tD[-1] :
+ tD = tD[-1][k]
+ else:
+ if dico:
+ tD[-1][k] = dict()
+ else:
+ tD[-1][k] = list()
+ return tD[-1][k]
+ else:
+ tD = tD[-1];
+ return tD
+
+
+
+
+
+def _fromkyf( d, f ):
+ tD=d
+ listType=type(None)
+ for line in f:
+ line = line.strip()
+ if line :
+ if line[0] == '[':
+ if line[1] == '[': # List
+ if line[2] == ' ': # of table
+ key = line[2:-2].strip()
+ tD = getTo(d, key, dico=False)
+ if type(tD) == list:
+ tD.append(dict());
+ tD = tD[-1]
+ continue
+ else:
+ print('Error', file=sys.stderr)
+ exit()
+ continue
+ elif line[2] == '=':
+ key = line[3:-2].strip()
+ tD = getTo(d, key, dico=False)
+ listType=type('')
+ continue
+ elif line[2] == '#':
+ key = line[2:-2].strip()
+ listType=type(0)
+ tD = getTo(d, key, dico=False)
+ continue
+ elif line[2] == '@':
+ key = line[2:-2].strip()
+ listType=type( None )
+ tD = getTo(d, key, dico=False)
+ continue
+ else: # Table
+ key = line[1:-1].strip()
+ tD = getTo(d, key)
+ continue
+ elif line[0] == '=':
+ if listType == type(''):
+ tD.append(line[1:])
+ else:
+ print('Error', file=sys.stderr)
+ exit()
+ continue
+ elif line[0] == '#':
+ if listType == type(0):
+ tD.append( int(line[1:]) )
+ else:
+ print('Error', file=sys.stderr)
+ continue
+ elif line[0] == '@':
+ if listType == type(None):
+ tD.append(line[1:])
+ else:
+ print('Error', file=sys.stderr)
+ continue
+ else:
+ listType=type(None)
+ i = line.find('=')
+ if i != -1: # String arg
+ key = line[:i].rstrip()
+ tD[key] = line[i+1:].lstrip()
+ continue
+ i = line.find('#')
+ if i != -1: # Number arg
+ key = line[:i].rstrip()
+ value = int(line[1+i:].strip())
+ if key:
+ tD[key] = value
+ elif type(tD) == list:
+ tD.append(value)
+ else:
+ print('Error', file=sys.stderr)
+ exit()
+ continue
+ o = line.find('@')
+ if i != -1: # Date arg
+ print('Date no supported yet')
+ exit()
+ else:
+ print('What ?')
+ exit()
+ return d
+
+def dump( d ) :
+ return _tokyf(d)
+
+def load( f ) :
+ d = dict()
+ return _fromkyf( d, f )
+
diff --git a/libkyf/libkyf.py b/libkyf/libkyf.py
new file mode 100644
index 0000000..b978430
--- /dev/null
+++ b/libkyf/libkyf.py
@@ -0,0 +1,187 @@
+#!/usr/bin/python
+# -*-coding:utf-8 -*
+
+import re, os, sys
+import base64
+import binascii
+import datetime
+
+
+def _tokyf(d, base = '', nbSpace = 0):
+ out = ""
+ for key, v in d.items():
+ if type(v) is int :
+ out += (key +'#' + str(v)) + '\n'
+ elif type(v) is str:
+ out += (key + '=' + v) + '\n'
+ elif type(v) == datetime.datetime:
+ out += (key + '@' + str(v)) + '\n'
+ elif type(v) is dict:
+ out += ( '[ ' + key + ' ]' ) + '\n'
+ out += _tokyf(v, base+key+'.',nbSpace+2)
+ elif type(v) is list:
+ isMultiple=False
+ if len(v) == 0:
+ continue
+ for e in v[1:]:
+ if type(e) is not type(v[0]):
+ isMultiple = True
+ if isMultiple:
+ print(key + ' is a multi typed list', file=sys.stderr)
+ exit()
+ else:
+ if type(v[0]) is int:
+ out += ( '[[#' + base + key + ' ]]' ) + '\n'
+ for i in v :
+ out += '#' + i + '\n'
+ elif type(v[0]) is str:
+ out += ( '[[=' + base + key + ' ]]' ) + '\n'
+ for i in v :
+ out += '=' + i + '\n'
+ elif str(type(v[0])) == "<class 'datetime.datetime'>":
+ out += ( '[[@' + key + ' ]]' ) + '\n'
+ for i in v :
+ out += '@' + i + '\n'
+ elif type(v[0]) is list:
+ out += ( '[[_' + key + ' ]]' ) + '\n'
+ for e in v:
+ out += _tokyf(e, base+key+'.',nbSpace+2)
+ elif type(v[0]) is dict:
+ for e in v:
+ out += ( '[[ ' + key + ' ]]' ) + '\n'
+ out += _tokyf(e, base+key+'.',nbSpace+2)
+ out += ('') + '\n'
+ else:
+ print(key + ' is a list of unknow type !' + str(type(v[0])) + ')',
+ file=sys.stderr)
+ exit()
+ else:
+ print('Type error :' + key +
+ ' don\'t have knowd type (' + str(type(v)) + ')', file=sys.stderr)
+ exit()
+ return out
+
+def getTo( d, key, dico=True ):
+ tD=d
+ ls = key.strip().split('.')
+ for i,k in enumerate(ls):
+ if type(tD) == dict:
+ if k in tD:
+ tD = tD[k]
+ else:
+ if dico:
+ tD[k] = dict()
+ else:
+ tD[k] = list()
+ tD = tD[k]
+ return tD
+ elif type(tD) == list:
+ if type(tD[-1]) == dict:
+ if k in tD[-1] :
+ tD = tD[-1][k]
+ else:
+ if dico:
+ tD[-1][k] = dict()
+ else:
+ tD[-1][k] = list()
+ return tD[-1][k]
+ else:
+ tD = tD[-1];
+ return tD
+
+
+
+
+
+def _fromkyf( d, f ):
+ tD=d
+ listType=type(None)
+ for line in f:
+ line = line.strip()
+ if line :
+ if line[0] == '[':
+ if line[1] == '[': # List
+ if line[2] == ' ': # of table
+ key = line[2:-2].strip()
+ tD = getTo(d, key, dico=False)
+ if type(tD) == list:
+ tD.append(dict());
+ tD = tD[-1]
+ continue
+ else:
+ print('Error', file=sys.stderr)
+ exit()
+ continue
+ elif line[2] == '=':
+ key = line[3:-2].strip()
+ tD = getTo(d, key, dico=False)
+ listType=type('')
+ continue
+ elif line[2] == '#':
+ key = line[2:-2].strip()
+ listType=type(0)
+ tD = getTo(d, key, dico=False)
+ continue
+ elif line[2] == '@':
+ key = line[2:-2].strip()
+ listType=type( None )
+ tD = getTo(d, key, dico=False)
+ continue
+ else: # Table
+ key = line[1:-1].strip()
+ tD = getTo(d, key)
+ continue
+ elif line[0] == '=':
+ if listType == type(''):
+ tD.append(line[1:])
+ else:
+ print('Error', file=sys.stderr)
+ exit()
+ continue
+ elif line[0] == '#':
+ if listType == type(0):
+ tD.append( int(line[1:]) )
+ else:
+ print('Error', file=sys.stderr)
+ continue
+ elif line[0] == '@':
+ if listType == type(None):
+ tD.append(line[1:])
+ else:
+ print('Error', file=sys.stderr)
+ continue
+ else:
+ listType=type(None)
+ i = line.find('=')
+ if i != -1: # String arg
+ key = line[:i].rstrip()
+ tD[key] = line[i+1:].lstrip()
+ continue
+ i = line.find('#')
+ if i != -1: # Number arg
+ key = line[:i].rstrip()
+ value = int(line[1+i:].strip())
+ if key:
+ tD[key] = value
+ elif type(tD) == list:
+ tD.append(value)
+ else:
+ print('Error', file=sys.stderr)
+ exit()
+ continue
+ o = line.find('@')
+ if i != -1: # Date arg
+ print('Date no supported yet')
+ exit()
+ else:
+ print('What ?')
+ exit()
+ return d
+
+def dump( d ) :
+ return _tokyf(d)
+
+def load( f ) :
+ d = dict()
+ return _fromkyf( d, f )
+
diff --git a/libkyf/load.py b/libkyf/load.py
new file mode 100644
index 0000000..6cd1542
--- /dev/null
+++ b/libkyf/load.py
@@ -0,0 +1,196 @@
+#!/usr/bin/python
+# -*-coding:utf-8 -*
+"""
+
+Implementation de la lecture du format kyf
+
+"""
+
+import re, os, sys
+import base64
+import binascii
+import datetime
+
+
+__all__ = ['load']
+
+
+
+def _tokyf(d, base = '', nbSpace = 0):
+ out = ""
+ for key, v in d.items():
+ if type(v) is int :
+ out += (key +'#' + str(v)) + '\n'
+ elif type(v) is str:
+ out += (key + '=' + v) + '\n'
+ elif type(v) == datetime.datetime:
+ out += (key + '@' + str(v)) + '\n'
+ elif type(v) is dict:
+ out += ( '[ ' + key + ' ]' ) + '\n'
+ out += _tokyf(v, base+key+'.',nbSpace+2)
+ elif type(v) is list:
+ isMultiple=False
+ if len(v) == 0:
+ continue
+ for e in v[1:]:
+ if type(e) is not type(v[0]):
+ isMultiple = True
+ if isMultiple:
+ print(key + ' is a multi typed list', file=sys.stderr)
+ exit()
+ else:
+ if type(v[0]) is int:
+ out += ( '[[#' + base + key + ' ]]' ) + '\n'
+ for i in v :
+ out += '#' + i + '\n'
+ elif type(v[0]) is str:
+ out += ( '[[=' + base + key + ' ]]' ) + '\n'
+ for i in v :
+ out += '=' + i + '\n'
+ elif str(type(v[0])) == "<class 'datetime.datetime'>":
+ out += ( '[[@' + key + ' ]]' ) + '\n'
+ for i in v :
+ out += '@' + i + '\n'
+ elif type(v[0]) is list:
+ out += ( '[[_' + key + ' ]]' ) + '\n'
+ for e in v:
+ out += _tokyf(e, base+key+'.',nbSpace+2)
+ elif type(v[0]) is dict:
+ for e in v:
+ out += ( '[[ ' + key + ' ]]' ) + '\n'
+ out += _tokyf(e, base+key+'.',nbSpace+2)
+ out += ('') + '\n'
+ else:
+ print(key + ' is a list of unknow type !' + str(type(v[0])) + ')',
+ file=sys.stderr)
+ exit()
+ else:
+ print('Type error :' + key +
+ ' don\'t have knowd type (' + str(type(v)) + ')', file=sys.stderr)
+ exit()
+ return out
+
+def getTo( d, key, dico=True ):
+ tD=d
+ ls = key.strip().split('.')
+ for i,k in enumerate(ls):
+ if type(tD) == dict:
+ if k in tD:
+ tD = tD[k]
+ else:
+ if dico:
+ tD[k] = dict()
+ else:
+ tD[k] = list()
+ tD = tD[k]
+ return tD
+ elif type(tD) == list:
+ if type(tD[-1]) == dict:
+ if k in tD[-1] :
+ tD = tD[-1][k]
+ else:
+ if dico:
+ tD[-1][k] = dict()
+ else:
+ tD[-1][k] = list()
+ return tD[-1][k]
+ else:
+ tD = tD[-1];
+ return tD
+
+
+
+
+
+def _fromkyf( d, f ):
+ tD=d
+ listType=type(None)
+ for line in f:
+ line = line.strip()
+ if line :
+ if line[0] == '[':
+ if line[1] == '[': # List
+ if line[2] == ' ': # of table
+ key = line[2:-2].strip()
+ tD = getTo(d, key, dico=False)
+ if type(tD) == list:
+ tD.append(dict());
+ tD = tD[-1]
+ continue
+ else:
+ print('Error', file=sys.stderr)
+ exit()
+ continue
+ elif line[2] == '=':
+ key = line[3:-2].strip()
+ tD = getTo(d, key, dico=False)
+ listType=type('')
+ continue
+ elif line[2] == '#':
+ key = line[2:-2].strip()
+ listType=type(0)
+ tD = getTo(d, key, dico=False)
+ continue
+ elif line[2] == '@':
+ key = line[2:-2].strip()
+ listType=type( None )
+ tD = getTo(d, key, dico=False)
+ continue
+ else: # Table
+ key = line[1:-1].strip()
+ tD = getTo(d, key)
+ continue
+ elif line[0] == '=':
+ if listType == type(''):
+ tD.append(line[1:])
+ else:
+ print('Error', file=sys.stderr)
+ exit()
+ continue
+ elif line[0] == '#':
+ if listType == type(0):
+ tD.append( int(line[1:]) )
+ else:
+ print('Error', file=sys.stderr)
+ continue
+ elif line[0] == '@':
+ if listType == type(None):
+ tD.append(line[1:])
+ else:
+ print('Error', file=sys.stderr)
+ continue
+ else:
+ listType=type(None)
+ i = line.find('=')
+ if i != -1: # String arg
+ key = line[:i].rstrip()
+ tD[key] = line[i+1:].lstrip()
+ continue
+ i = line.find('#')
+ if i != -1: # Number arg
+ key = line[:i].rstrip()
+ value = int(line[1+i:].strip())
+ if key:
+ tD[key] = value
+ elif type(tD) == list:
+ tD.append(value)
+ else:
+ print('Error', file=sys.stderr)
+ exit()
+ continue
+ o = line.find('@')
+ if i != -1: # Date arg
+ print('Date no supported yet')
+ exit()
+ else:
+ print('What ?')
+ exit()
+ return d
+
+def dump( d ) :
+ return _tokyf(d)
+
+def load( f ) :
+ d = dict()
+ return _fromkyf( d, f )
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..605be63
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+# -*-coding:utf-8 -*
+
+from setuptools import setup, find_packages
+
+
+import libkyf
+
+
+setup(
+ name='libkyf',
+ version=libkyf.__version__,
+
+ description='A parser for KYF',
+ long_description=open('README.md').read(),
+ author='HĂ©dy Ache',
+ author_email='ache@ache.one',
+ url='http://git.ache.one/kyf',
+ license='GNU GPL v3',
+# install_requires=[],
+# zip_safe=False,
+
+ include_package_data=True,
+
+ packages=find_packages(),
+ classifiers=[
+ "Programming Language :: Python",
+ "Development Status :: 1 - Planning",
+ "Natural Language :: French",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python :: 2.7",
+ "Programming Language :: Python :: 3.5",
+ ]
+
+
+)