Skip to main content

Generate random strings matching a pattern

Project description

stringbrewer: Generate random strings matching a pattern.

Patterns are specified in the StringBrewer pattern language, and are made up of two parts: a recipe and a set of ingredients. A recipe is essentially a modified form of regular expression; whitespace is not significant, and each ingredient name is replaced by its definition. An ingredient is a space-separated list of items; each item is either a character (specified either as a literal character or as a Unicode codepoint in hexadecimal), a range of characters separated by hyphens, or a union of items separated by commas. Ingredients may also contain references to other ingredients.

This is best understood by example. The pattern below generates Telugu morphemes::

# Generate random Telugu-like morphemes
(Base HalantGroup{0,2} TopPositionedVowel?){1,3}

Base = క-న,ప-హ
Halant = 0C4D
HalantGroup = Halant Base
TopPositionedVowel = 0C46-0C48,0C4A-0C4C

The first line is a comment; the second is the recipe, and the blank line denotes the beginning of the ingredients list. Let's look at the ingredients. A Base is any character either in the range 0x0C15-0C28 or 0C2A-0C39. (We specified these as literals, just because we could). A Halant is the character 0x0C4D. A HalantGroup is a halant followed by a base.

Now you understand the ingredients, the recipe is simple to understand if you think in terms of regular expression syntax: a base followed by zero, one or two halant groups, plus an optional top-positioned vowel, all repeated between one and three times.

__init__

 | __init__(from_string=None, from_file=None, recipe=None, ingredients=None)

Initializes a StringBrewer object

You must provide either a file name, a string, or a recipe string and ingredients dictionary.

Arguments:

  • from_file - A file name of a file containing a pattern.
  • from_string - A pattern in a string.
  • recipe - The recipe part of a pattern.
  • ingredients - A dictionary of regular expressions.

generate_all

 | generate_all()

Generates a list of all combinations.

If there are more than 100,000 combinations, an exception is raised to avoid running out of memory.

generate

 | generate(min_length=0, max_length=None)

Generates a single random combination.

Arguments:

  • min_length - Minimum length (zero if not specified)
  • max_length - Maximum length (no maximum if not specified)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stringbrewer-0.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stringbrewer-0.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file stringbrewer-0.0.1.tar.gz.

File metadata

  • Download URL: stringbrewer-0.0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/18.5 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.16

File hashes

Hashes for stringbrewer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c2d113822f9393500b273cc833a21ce739036c02c62f47042e0f17ef9b9ea649
MD5 aadd6d5e1cca165b9e65870089a9ab7d
BLAKE2b-256 a92e341077c34244cb99a2c245e7f158013ba101427330e14fa4d3d4b6f72530

See more details on using hashes here.

File details

Details for the file stringbrewer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: stringbrewer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/18.5 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.16

File hashes

Hashes for stringbrewer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c04c37a9874a9645b6c311897fcb1f7c7a0c787d207e4777ca966ebd3685d7c3
MD5 851c76b82322726353e33aecf33a3ebf
BLAKE2b-256 04e86104ffdc8d892e2b9a5e584346d38fcb8d858c8fec0f586e64d1899bcd61

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page