Skip to content
This repository has been archived by the owner on Jun 20, 2020. It is now read-only.

CovenantEyes/py_stringlike

Repository files navigation

stringlike

Build Status Coverage Status PyPi package PyPi downloads

A Python library for implementing string-like classes and lazy strings.

Installation

stringlike is available from PyPI.

To install:

$ pip install stringlike

Or from the source:

$ python setup.py install

Usage

To implement your own StringLike class, inherit from StringLike and implement the __str__ magic function, like this:

from stringlike import StringLike

class StringyThingy(StringLike):
    def __str__(self):
        return self.text_type("A string representation of my class.")
Instances of StringLike class have a text_type property. By default it holds a propper string type for current version of Python: str for Python 3 and unicode for Python 2.

You can redefine text_type property for your needs.

It's strongly recommended to use it anyway just to make your code compatible with different versions of Python.

Use the provided lazy string implementations like this:

from stringlike.lazy import LazyString, CachedLazyString

print "This was lazily {str}".format(str=LazyString(lambda: "generated"))
print "This is {str}".format(str=CachedLazyString(lambda: "cached"))

A more detailed example can be found here.

Unit Tests

To run the unit tests, do this:

$ python tests/run_tests.py

To see the latest test results, check out stringlike's Travis CI page.

Acknowledgements

Special thanks to Eric Shull for much Python help!

License

This package is released under the MIT License. (See LICENSE.txt.)

About

Python library for implementing string-like classes and lazy strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages