Skip to content

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tb69wn6127 committed Mar 28, 2015
1 parent 16f084e commit b8063c8
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 5 deletions.
6 changes: 6 additions & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
변경사항
==============

v1.5.0
-------

+ ufp.dict 모듈에 Lazy 클래스를 추가함. [`tb69wn6127`_]
+ ufp.terminal.debug 모듈의 print_ 함수에서 '[디버그]'라 출력되는 문구를 '[DEBUG]'문구로 수정. [`tb69wn6127`_]

v1.4.0
-------

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/terminal/debug.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. py:module:: ufp.terminal.debug
.. py:currentmodule:: ufp.terminal.debug
:py:mod:`debug` Module
:py:mod:`debug` 모듈
==========================

.. automodule:: ufp.terminal.debug
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/terminal/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. py:module:: ufp.terminal
.. py:currentmodule:: ufp.terminal
:py:mod:`terminal` Module
:py:mod:`terminal` 모듈
==========================

.. toctree::
Expand Down
2 changes: 1 addition & 1 deletion ufp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import unicode_literals, absolute_import

__title__ = 'ufp'
__version__ = '1.4.0'
__version__ = '1.5.0'
__author__ = '별님'
__license__ = 'GPL v3'
__copyright__ = 'Copyright 2015 별님'
Expand Down
80 changes: 80 additions & 0 deletions ufp/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,86 @@
#-*- coding: utf-8 -*-

from __future__ import unicode_literals, absolute_import, division, print_function
import UserDict

class Lazy(UserDict.UserDict):
"""
설정된 사전 값에 대해 접근 할때 초기화되도록 설정 할 수 있는 사전.
늦은 초기화가 생략 된 경우, 해당 키의 값에 대해서는 늦은 초기화를 사용하지 않도록 설정되어 있습니다.
사용 예는 다음과 같습니다.
.. code-block:: python
>>> import ufp.dict
>>> from ufp.terminal.debug import print_ as debug
>>> dict = ufp.dict.Lazy()
>>> def function():
... debug('inited...')
... return 10
...
>>> dict.add('lazyInitValue', function, True)
>>> dict['lazyInitValue']
[DEBUG] inited...
10
>>> dict['lazyInitValue']
10
"""
def __init__(self, dict=None):
self.data = {}
if dict is not None:
self.update(dict)
self._lazyInitDict = {}

def add(self, key, value, lazyInit=False):
"""
늦은 초기화 여부를 설정하면서 사전에 등록합니다.
:param key: 키
:param value: 값
:param lazyInit: 늦은 초기화 설정. True시 늦은 초기화를 사용함.
"""
self[key] = value
self._lazyInitDict[key] = lazyInit

def items(self):
"""
기존 UserDict.UserDict.items와 같습니다.
"""
for key, value in self.data.items():
if self._lazyInitDict.get(key, False) and callable(value):
value = value()
self.data[key] = value
self._lazyInitDict[key] = False
yield key, value

def values(self):
"""
기존 UserDict.UserDict.values와 같습니다.
"""
return map(lambda k,v: v, self.items())

def __delitem__(self, key):
if key in self._lazyInitDict:
del self._lazyInitDict[key]
del self.data[key]

def setLazyInit(self, key, lazyInit):
"""
개별 키에 대한 늦은 초기화 여부를 설정합니다.
:param key: 키
:param lazyInit: 늦은 초기화 설정. True시 늦은 초기화를 사용함.
"""
self._lazyInitDict[key] = lazyInit

def __getitem__(self, key):
if self._lazyInitDict.get(key, False) and callable(self.data[key]):
self.data[key] = self.data[key]()
self._lazyInitDict[key] = False
return self.data[key]


def setdefault(dict, key, default, empty=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion ufp/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def string(length, chars=_p_string.ascii_letters + _p_string.digits):
:param length: 문자열의 길이
:type length: int
:param chars: 문자 집합\n
[a, ..., z, A, ..., Z, ..., 0, ..., 9] (기본값)
[a, ..., z, A, ..., Z, 0, ..., 9] (기본값)
:type chars: str, unicode, list
:return: 램덤 문자열
:rtype: unicode
Expand Down
2 changes: 1 addition & 1 deletion ufp/terminal/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def print_(*objects, **kwargs):
:type objects: object
:param kwargs: 옵션(__builtin__.print 함수의 인자와 같습니다)
"""
buffer = ANSIColors.sprint('<Red>[디버그]<reset> ')
buffer = ANSIColors.sprint('<Red>[DEBUG]<reset> ')
builtins.print(buffer, end='');
builtins.print(*objects, **kwargs);
pass

0 comments on commit b8063c8

Please sign in to comment.