Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

StringFragment type to represent parts of str objects; used to avoid copying strings during processing

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 MANIFEST.in
Octocat-spinner-32 README.md
Octocat-spinner-32 setup.py
Octocat-spinner-32 strfrag.py
Octocat-spinner-32 test_strfrag.py
README.md

Strfrag overview

A strfrag.StringFragment represents part of a str object. This can be used to avoid copying long str objects as you incrementally process them.

>>> from strfrag import StringFragment
>>> sf = StringFragment("hello world", 2, 8)
>>> sf
<StringFragment for 0xf74c5240, pos=2, size=8, represents 'llo worl'>
>>> sf[2]
'o'
>>> sf[2:5]
<StringFragment for 0xf74c5240, pos=4, size=3, represents 'o w'>
>>> str(sf)
'llo worl'
>>> sf.as_buffer()
<read-only buffer for 0xf74c5240, size 8, offset 2 at 0xf74c5220>

# StringFragments that represents the same bytes are equal:

>>> StringFragment("hello world", 1, 5) == StringFragment("ello ", 0, 5)
True

Installation

python setup.py install

This installs the modules strfrag and test_strfrag.

Running the tests

Install Twisted, then run trial strfrag

Contributing

Patches and pull requests are welcome.

This coding standard applies: http://ludios.org/coding-standard/ , except don't camel-case anything in strfrag.py.

Something went wrong with that request. Please try again.