Code Monkey home page Code Monkey logo

decorating's People

Contributors

boxed avatar masasin avatar mkuznets avatar ryukinix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

decorating's Issues

Implement MonitorStdout decorator

from decorating.stream import Unbuffered
from decorating.decorator import Decorator
import sys

class MonitorStream(Unbuffered):

    def __init__(self, stream):
        self.stream = stream
        self.data = []

    def write(self, message):
        self.stream.write(message)
        self.data.append(message)

class MonitorStdout(Decorator):

    def start(self):
        self.stream = MonitorStream(sys.stdout)
        sys.stdout = self.stream

    def stop(self):
        sys.stdout = sys.__stdout__

monitor_stdout = MonitorStdout()

with monitor_stdout:
    print('test')

print(monitor_stdout.stream.data)

This is just a prototype. The main ideia is get all the stdout content of a isolated context using decorated functions or context managers.

Change `_over_wrapper` to `wrapper` public method on decorating.decorator

This can be useful because we can use things like this:

    from decorating import Decorator
    from logging import getLogger

    logger = getLogger(__name__)
    class ExceptionDumper(Decorator):

         def wrapper(self):
              try:
                   return super().wrapper()
              except Exception as e:
                    logger.exception(e)

So we can decorate any function or use contextmanagers to do dump of exceptions.

Unicode translation on pyinstaller

When using pyinstaller to 'compile' a program using decorating, I am suddenly faced with the following:

Traceback (most recent call last):
File "threading.py", line 801, in __bootstrap_inner
File "threading.py", line 754, in run
File "site-packages/decorating/animation.py", line 157, in _spinner
File "site-packages/decorating/stream.py", line 84, in write
File "site-packages/decorating/stream.py", line 56, in write
UnicodeEncodeError: 'ascii' codec can't encode character u'\u28fe' in position 18: ordinal not in range(128)

The little research I have done points to unicode being cast as strings, and I found a few workarounds based on using locales, but so far, no success.

The library is otherwise working fine and is pretty awesome.

Print while something is animated problem: double-newlines problem

Description

I have some troubles with this, always when something is printed inside of a animated context, decorated or using like context managers (with keyword), the print have double newlines, althoug I solve the problem with the broken animation.

Attempts

The attempt to fix this and other problems underlying of this subject is on that 6fc9e8a I added a example of this too on test_animated.py. You can try running this to replicate the problem.

Image

A image running the tests is here:

image

Python 2 support

Trying to run the animated decorator example on Python 2, froze my machine. Any plans to support older versions of Python?

@animated gives an IndexError

With version decorating (0.2.1b0) of the library, the following code:

from decorating import animated
from time import sleep

@animated
def main():
    sleep(300)

main()

gives me the traceback:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    main()
  File "/home/rahiel/Code/test/venv/lib/python3.5/site-packages/decorating/animation.py", line 159, in __call__
    if callable(args[0]):
IndexError: tuple index out of range

I've installed the package in a virtualenv.

Using with animated(...) works fine.

Fix Portuguese accent in documentation

The project has pretty bad English. This should be fixed. All project docs were written in a hurry and I don't have much experience with writing english documentation so I do appreciate if someone help me with this.

  • README.md

Cache needs expiryTime (seconds)

Feature request:

Make the cache decorator accept an expiry time - the number of seconds that a result should be cached before re-running the wrapped function. This is useful as a way to rate-limit queries to any kind of backing store. The default of None would preserve the current behavior of caching 'forever'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.