sedeuce


Namesedeuce JSON
Version 1.0.9 PyPI version JSON
download
home_pagehttps://github.com/Tails86/sedeuce
SummaryA seductive sed clone in Python with both CLI and library interfaces
upload_time2024-04-19 01:35:32
maintainerNone
docs_urlNone
authorJames Smith
requires_python>=3.6
licenseNone
keywords sed files regex replace
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sedeuce

A seductive sed clone in Python with both CLI and library interfaces

## Shameless Promotion

Check out my other Python clone tools:
- [greplica](https://pypi.org/project/greplica/)
- [refind](https://pypi.org/project/refind/)

## Known Differences with sed

- The Python module `re` is internally used for all regular expressions. The inputted regular
    expression is modified only when basic regular expressions are used in order to reverse meaning
    of escaped characters `+?|{}()`
- Substitute
    - The m/M modifier will act differently due to how Python re handles multiline mode
    - GNU sed extension special sequences not supported
    - All `\n` characters match with $ (end of line) due to use of Python `re`
- Newline can always be escaped with \ in any command

## Contribution

Feel free to open a bug report or make a merge request on [github](https://github.com/Tails86/sedeuce/issues).

## Installation
This project is uploaded to PyPI at https://pypi.org/project/sedeuce/

To install, ensure you are connected to the internet and execute: `python3 -m pip install sedeuce --upgrade`

Once installed, there will be a script called `sedeuce` under Python's script directory. If `sed`
is not found on the system, then a script called `sed` will also be installed. Ensure Python's
scripts directory is under the environment variable `PATH` in order to be able to execute the script
properly from command line.

## CLI Help

```
usage: sedeuce [-h] [-n] [--debug] [-e script] [-f script-file]
               [--follow-symlinks] [-i [SUFFIX]] [-l N] [--posix] [-E] [-s]
               [--sandbox] [-u] [--end END] [-z] [--version] [--verbose]
               [script] [input-file [input-file ...]]

A sed clone in Python with both CLI and library interfaces

positional arguments:
  script                script, only if no other script defined below
  input-file            Input file(s) to parse

optional arguments:
  -h, --help            show this help message and exit
  -n, --quiet, --silent
                        suppress automatic printing of pattern space
  --debug               annotate program execution
  -e script, --expression script
                        add the script to the commands to be executed
  -f script-file, --file script-file
                        add the contents of script-file to the commands to be
                        executed
  --follow-symlinks     follow symlinks when processing in place
  -i [SUFFIX], --in-place [SUFFIX]
                        edit files in place (makes backup if SUFFIX supplied)
  -l N, --line-length N
                        specify the desired line-wrap length for the `l'
                        command
  --posix               disable all extensions.
  -E, -r, --regexp-extended
                        use extended regular expressions in the script
  -s, --separate        consider files as separate rather than as a single,
                        continuous long stream.
  --sandbox             operate in sandbox mode (disable e/r/w commands).
  -u, --unbuffered      load minimal amounts of data from the input files and
                        flush the output buffers more often
  --end END             end-of-line character for parsing search files
                        (default: \n); this does not affect file parsing for -f
                        or --exclude-from
  -z, --null-data       same as --end='\0'
  --version             output version information and exit
  --verbose             show verbose errors
```

## Library Help

sedeuce can be used as a library from another module. The following is a simple example.

```py
import sedeuce
from io import BytesIO
# Create sed object
sed = sedeuce.Sed()
# Set all desired sed settings
sed.extended_regex = True
# Add commands
sed.add_command(sedeuce.SubstituteCommand(None, '([0-9]+)', 'Numbers: \\1'))
# Add files to parse
sed.add_file('path/to/file.txt')
# In this example, parsed data is captured by a BytesIO object
byte_buffer = BytesIO()
# Execute sed parsing with above settings and data
sed.execute(byte_buffer)
# Print the result
print(byte_buffer.getvalue().decode())
```

The following Sed methods may be called to add expressions, commands, and files.

```py
add_expression(self, script:str) -> None:
  '''
  Adds an expression string (i.e. a command line expression string).
  Expressions are parsed and added to my internal list of commands.
  '''

add_command(self, command_or_commands:Union[SedCommand, List[SedCommand]]) -> None:
  ''' Adds a command object or list of commands (one of SedCommand)'''

clear_commands(self) -> None:
  ''' Clears all set commands and expressions '''

add_file(self, file_or_files:Union[str, List[str]]) -> None:
  ''' Adds a file to parse '''

clear_files(self) -> None:
  ''' Clears all files set by add_file '''
```

The following Sed options may be adjusted.

```py
# (property) The sequence of bytes expected at the end of each line
# Returns bytes, can be set as str or bytes
newline = b'\n'

# Parse files in place instead of to stdout
in_place:bool = False

# The suffix to use for creating backup files when in_place is True
in_place_backup_suffix:Union[str,None] = None

# When True, follow symbolic links when in_place is True
follow_symlinks:bool = False

# True to suppress printing of pattern space
suppress_pattern_print:bool = False

# True to use extended regex mode
extended_regex:bool = False

# The line length to use for l command
unambiguous_line_len:int = 70

# When True, restart line count when a new file is opened
separate:bool = False

# Disable e/r/w commands when True
sandbox_mode:bool = False
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Tails86/sedeuce",
    "name": "sedeuce",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "sed, files, regex, replace",
    "author": "James Smith",
    "author_email": "jmsmith86@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/be/f0/1d11c90accc22b1a0814d5e7d7f5904e3b3c6139633b4c18b82920b22b98/sedeuce-1.0.9.tar.gz",
    "platform": null,
    "description": "# sedeuce\n\nA seductive sed clone in Python with both CLI and library interfaces\n\n## Shameless Promotion\n\nCheck out my other Python clone tools:\n- [greplica](https://pypi.org/project/greplica/)\n- [refind](https://pypi.org/project/refind/)\n\n## Known Differences with sed\n\n- The Python module `re` is internally used for all regular expressions. The inputted regular\n    expression is modified only when basic regular expressions are used in order to reverse meaning\n    of escaped characters `+?|{}()`\n- Substitute\n    - The m/M modifier will act differently due to how Python re handles multiline mode\n    - GNU sed extension special sequences not supported\n    - All `\\n` characters match with $ (end of line) due to use of Python `re`\n- Newline can always be escaped with \\ in any command\n\n## Contribution\n\nFeel free to open a bug report or make a merge request on [github](https://github.com/Tails86/sedeuce/issues).\n\n## Installation\nThis project is uploaded to PyPI at https://pypi.org/project/sedeuce/\n\nTo install, ensure you are connected to the internet and execute: `python3 -m pip install sedeuce --upgrade`\n\nOnce installed, there will be a script called `sedeuce` under Python's script directory. If `sed`\nis not found on the system, then a script called `sed` will also be installed. Ensure Python's\nscripts directory is under the environment variable `PATH` in order to be able to execute the script\nproperly from command line.\n\n## CLI Help\n\n```\nusage: sedeuce [-h] [-n] [--debug] [-e script] [-f script-file]\n               [--follow-symlinks] [-i [SUFFIX]] [-l N] [--posix] [-E] [-s]\n               [--sandbox] [-u] [--end END] [-z] [--version] [--verbose]\n               [script] [input-file [input-file ...]]\n\nA sed clone in Python with both CLI and library interfaces\n\npositional arguments:\n  script                script, only if no other script defined below\n  input-file            Input file(s) to parse\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -n, --quiet, --silent\n                        suppress automatic printing of pattern space\n  --debug               annotate program execution\n  -e script, --expression script\n                        add the script to the commands to be executed\n  -f script-file, --file script-file\n                        add the contents of script-file to the commands to be\n                        executed\n  --follow-symlinks     follow symlinks when processing in place\n  -i [SUFFIX], --in-place [SUFFIX]\n                        edit files in place (makes backup if SUFFIX supplied)\n  -l N, --line-length N\n                        specify the desired line-wrap length for the `l'\n                        command\n  --posix               disable all extensions.\n  -E, -r, --regexp-extended\n                        use extended regular expressions in the script\n  -s, --separate        consider files as separate rather than as a single,\n                        continuous long stream.\n  --sandbox             operate in sandbox mode (disable e/r/w commands).\n  -u, --unbuffered      load minimal amounts of data from the input files and\n                        flush the output buffers more often\n  --end END             end-of-line character for parsing search files\n                        (default: \\n); this does not affect file parsing for -f\n                        or --exclude-from\n  -z, --null-data       same as --end='\\0'\n  --version             output version information and exit\n  --verbose             show verbose errors\n```\n\n## Library Help\n\nsedeuce can be used as a library from another module. The following is a simple example.\n\n```py\nimport sedeuce\nfrom io import BytesIO\n# Create sed object\nsed = sedeuce.Sed()\n# Set all desired sed settings\nsed.extended_regex = True\n# Add commands\nsed.add_command(sedeuce.SubstituteCommand(None, '([0-9]+)', 'Numbers: \\\\1'))\n# Add files to parse\nsed.add_file('path/to/file.txt')\n# In this example, parsed data is captured by a BytesIO object\nbyte_buffer = BytesIO()\n# Execute sed parsing with above settings and data\nsed.execute(byte_buffer)\n# Print the result\nprint(byte_buffer.getvalue().decode())\n```\n\nThe following Sed methods may be called to add expressions, commands, and files.\n\n```py\nadd_expression(self, script:str) -> None:\n  '''\n  Adds an expression string (i.e. a command line expression string).\n  Expressions are parsed and added to my internal list of commands.\n  '''\n\nadd_command(self, command_or_commands:Union[SedCommand, List[SedCommand]]) -> None:\n  ''' Adds a command object or list of commands (one of SedCommand)'''\n\nclear_commands(self) -> None:\n  ''' Clears all set commands and expressions '''\n\nadd_file(self, file_or_files:Union[str, List[str]]) -> None:\n  ''' Adds a file to parse '''\n\nclear_files(self) -> None:\n  ''' Clears all files set by add_file '''\n```\n\nThe following Sed options may be adjusted.\n\n```py\n# (property) The sequence of bytes expected at the end of each line\n# Returns bytes, can be set as str or bytes\nnewline = b'\\n'\n\n# Parse files in place instead of to stdout\nin_place:bool = False\n\n# The suffix to use for creating backup files when in_place is True\nin_place_backup_suffix:Union[str,None] = None\n\n# When True, follow symbolic links when in_place is True\nfollow_symlinks:bool = False\n\n# True to suppress printing of pattern space\nsuppress_pattern_print:bool = False\n\n# True to use extended regex mode\nextended_regex:bool = False\n\n# The line length to use for l command\nunambiguous_line_len:int = 70\n\n# When True, restart line count when a new file is opened\nseparate:bool = False\n\n# Disable e/r/w commands when True\nsandbox_mode:bool = False\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A seductive sed clone in Python with both CLI and library interfaces",
    "version": "1.0.9",
    "project_urls": {
        "Bug Reports": "https://github.com/Tails86/sedeuce/issues",
        "Documentation": "https://github.com/Tails86/sedeuce",
        "Homepage": "https://github.com/Tails86/sedeuce",
        "Source Code": "https://github.com/Tails86/sedeuce"
    },
    "split_keywords": [
        "sed",
        " files",
        " regex",
        " replace"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bef01d11c90accc22b1a0814d5e7d7f5904e3b3c6139633b4c18b82920b22b98",
                "md5": "eb366669a3e202dee478e4bf80d3b11e",
                "sha256": "c686ed163e8332c15ed81f91db0c9a679eb20c0f6f5b5eac066553aaca974e73"
            },
            "downloads": -1,
            "filename": "sedeuce-1.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "eb366669a3e202dee478e4bf80d3b11e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 23111,
            "upload_time": "2024-04-19T01:35:32",
            "upload_time_iso_8601": "2024-04-19T01:35:32.081205Z",
            "url": "https://files.pythonhosted.org/packages/be/f0/1d11c90accc22b1a0814d5e7d7f5904e3b3c6139633b4c18b82920b22b98/sedeuce-1.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-19 01:35:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Tails86",
    "github_project": "sedeuce",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "sedeuce"
}
        
Elapsed time: 0.22665s