GithubHelp home page GithubHelp logo

daveoncode / python-string-utils Goto Github PK

View Code? Open in Web Editor NEW
55.0 55.0 8.0 2.36 MB

A handy Python library to validate, manipulate and generate strings

License: MIT License

Python 99.98% Shell 0.02%
camelcase email-validation ipv4 ipv6 isbn-10 isbn-13 manipulating-strings random-string roman-number-converter snake-case string-compressor string-manipulation strings utility

python-string-utils's People

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

Watchers

 avatar  avatar  avatar  avatar

python-string-utils's Issues

List of values is also a valid json

The is_json function only seems to support a collection of name-value pairs. However, an ordered list of values is also a valid json format (http://json.org/) now, which the validator does not take into account.

For instance, is_json('{"abcs"}') should return True, which is not currently the case.

Deprecation warnings over invalid escape sequences in Python 3.7

Deprecation warning are generated over invalid escape sequences. This can be fixed by using raw strings or escaping the literals again.

find . -iname '*.py'  | xargs -P 4 -I{} python -Walways -m py_compile {} 

./string_utils.py:59: DeprecationWarning: invalid escape sequence \d
  SNAKE_CASE_REPLACE_DASH_RE = re.compile('(-)([a-z\d])')
./string_utils.py:303: DeprecationWarning: invalid escape sequence \d
  re_template = '^[a-z]+([a-z\d]+{sign}|{sign}[a-z\d]+)+[a-z\d]+$'
./string_utils.py:494: DeprecationWarning: invalid escape sequence \d
  r = re_map.get(separator, re.compile('({sign})([a-z\d])'.format(sign=re.escape(separator))))
./tests.py:590: DeprecationWarning: invalid escape sequence \ 
  self.assertEqual(words_count('. . ! <> [] {} + % --- _ = @ # ~ | \ / " \''), 0)
./string_utils.py:541: DeprecationWarning: invalid escape sequence \*
  """

Support for ipv4 mapped ipv6 address

Hello,
The current is_ip and is_ip_v6 functions do not validate an ipv4 mapped ipv6 address.
For instance, is_ip("7::128.128.0.127") returns False while it should return True.

Check for IPv6 address and false positives with ipv4

The is_ip() seems to be missing on checks for the validity of ipv6 addresses, for instance, "3ffe::1".
Also, for ipv4 address, the validator unexpectedly returns True for the invalid address "016.016.016.016"

Check on slug

This is a valid slug '123____123' while the is_slug returns false for instances containing consecutive underscore('_')

Install fails with UnicodeDecodeError in some locales

When trying to install python-string-utils with python 3.6 and pip 20.0.2 in a SLES 15 SP1 docker container, the install fails with this error:

    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4lc71oyc/python-string-utils/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4lc71oyc/python-string-utils/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-4lc71oyc/python-string-utils/pip-egg-info
         cwd: /tmp/pip-install-4lc71oyc/python-string-utils/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-4lc71oyc/python-string-utils/setup.py", line 4, in <module>
        long_description = readme.read()
      File "/usr/lib64/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 8392: ordinal not in range(128)
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

README.md has some non-ASCII characters, and it appears that the locale in the docker container uses ascii encoding by default. Likely setup.py just needs to specify utf-8 encoding to open README.md.

package is installed but script says it is not installed via script

Hi. Below is AI generated code to check if a certain python package is installed or not.
It checks for python-string-utils and jsonschema packages existance.
For python-string-utils it prints below EVERY TIME the script is ran:

python-string-utils is not installed or is not the desired version. Installing...
python-string-utils (1.0.0) has been successfully installed.

For jsonschema it prints below immediately:

jsonschema (4.17.3) is already installed.

What could be the issue that is causing python-string-utils to be checked always?
Any leads is appreciated.

Code:

import importlib
import subprocess

# Define a list of packages and their desired versions
packages_to_check = [
    {"name": "python-string-utils", "version": "1.0.0"},
    {"name": "jsonschema", "version": "4.17.3"},
]

for package_info in packages_to_check:
    package_name = package_info["name"]
    desired_version = package_info["version"]

    try:
        # Attempt to import the package
        importlib.import_module(package_name)
        print(f"{package_name} ({desired_version}) is already installed.")
    except ImportError:
        print(f"{package_name} is not installed or is not the desired version. Installing...")

        # Install the package with the desired version
        install_command = ["pip3", "install", f"{package_name}=={desired_version}"]

        # Run the installation command
        installation_result = subprocess.run(install_command, capture_output=True, text=True)

        if installation_result.returncode == 0:
            print(f"{package_name} ({desired_version}) has been successfully installed.")
        else:
            print(f"Failed to install {package_name} ({desired_version}).")
            print("Installation error output:")
            print(installation_result.stderr)

Email validation- constraints on domain label and presence of unicode unhandled

Hello,

I'm listing some scenarios where the is_email fails:

  1. domain with localhost not accepted by is_email: email@localhost, email@[127.0.0.1] are valid while the function returns False
  2. unicode not handled- this should be valid but returns false: [email protected].\\xe0\\xa4\\x89\\xe0\\xa4\\xa6\\xe0\\xa4\\xbe\\xe0\\xa4\\xb9\\xe0\\xa4\\xb0\\xe0\\xa4\\xa3.\\xe0\\xa4\\xaa\\xe0\\xa4\\xb0\\xe0\\xa5\\x80\\xe0\\xa4\\x95\\xe0\\xa5\\x8d\\xe0\\xa4\\xb7\\xe0\\xa4\\xbe
  3. domain labels can't begin or end in hyphens '-': These should be invalid but is_email gives true: [email protected] and [email protected]

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.