Skip to content

Commit

Permalink
implementation of plain representation to most objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
panyanyany authored Jun 16, 2016
2 parents 8eba104 + 62b0ef1 commit 518c405
Show file tree
Hide file tree
Showing 16 changed files with 751 additions and 86 deletions.
1 change: 1 addition & 0 deletions README.md
45 changes: 43 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
beeprint: Beautiful Print
beeprint: Beautifully Print
===
pprint is good, but not clean. So beeprint do it.

Features
===
- print dict elegantly
- format of sequential type is controllable
- outstanding mark to class and instance
- compatible with py2 py3 in same output

Examples
===

Plain Variables
Complicated data
---
```
[
1,
1.1,
's',
'us',
'a中文',
'a中文',
[1],
(1, 2),
function(EmptyFunc),
class(EmptyClassOldStyle),
class(EmptyClassNewStyle),
class(NormalClassOldStyle):
static_props: 1,
class(NormalClassNewStyle):
dicts: {
},
lists: [],
static_props: 1,
instance(NormalClassOldStyle):
static_props: 1,
instance(NormalClassNewStyle):
dicts: {
},
lists: [],
static_props: 1,
method(mth),
method(mth),
{
'key': [],
'key2': {
},
},
]
```

32 changes: 26 additions & 6 deletions beeprint/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,34 @@
# 比如:<CAN NOT PARSE OBJECT>
_PS_CONTENT_FIRST = 2

# an element will occupy a single block
# it has its own leading spaces
_AS_ELEMENT_ = 1
# compares to _AS_ELEMENT_, a value is a component of an element
# it has not leading spaces except a span between a key
# it belongs to a key
_AS_VALUE_ = 2
# when display, these elements need comma between each others
# it must has a parent block
# eg: [1, 2], {'key1': 'val1', 'key2': 'val2'}, (1, 2)
_AS_LIST_ELEMENT_ = \
_AS_DICT_ELEMENT_ = \
_AS_TUPLE_ELEMENT_ = \
_AS_CLASS_ELEMENT_ = 4
_AS_TUPLE_ELEMENT_ = 4

_AS_DICT_ELEMENT_ = 8
_AS_CLASS_ELEMENT_ = 16

# string type
ST_LITERAL = 1 # string literal depends on script's coding
ST_UNICODE = 2
ST_BYTES = 4
_ST_LITERAL_ = 1 # string literal depends on script's coding
_ST_UNICODE_ = 2
_ST_BYTES_ = 4
_ST_UNDEFINED_ = 0

# debug level
_DL_MODULE_ = 1
_DL_FUNC_ = 2
_DL_STATEMENT = 3

# long string
_LS_WRAP_BY_NONE = 0
_LS_WRAP_BY_TERMINAL = 1
_LS_WRAP_BY_80_COLUMN = 2
14 changes: 10 additions & 4 deletions beeprint/debug_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import division
from . import settings as S
from . import constants as C
import inspect


### global variables
Expand All @@ -16,7 +17,12 @@ def add_leading(depth, text):
return text

def debug(level, depth, text):
if S.debug is False:
return
text = add_leading(depth, text)
print(text)
if S.debug_level >= level:
frame_list = inspect.stack()
caller_name = frame_list[1][3]
depth = len(frame_list) - 4
if level == C._DL_FUNC_:
depth -= 1
text = caller_name + ': ' + text
text = add_leading(depth, text)
print(text)
Loading

0 comments on commit 518c405

Please sign in to comment.