daveoncode / python-string-utils Goto Github PK
View Code? Open in Web Editor NEWA handy Python library to validate, manipulate and generate strings
License: MIT License
A handy Python library to validate, manipulate and generate strings
License: MIT License
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.
# This should return True I believe
>>> string_utils.is_snake_case("user")
False
# looks like correct behavior
>>> string_utils.is_snake_case("user_name")
True
RFC 5322 (https://tools.ietf.org/html/rfc5322) allows usage of double quotes in email, such as "test@test"@example.com
. However, the is_email() function does not account for this.
Hello,
Here are some scenarios where is_url
shows unexpected behaviour:
http://google.abcdefghi
is valid but is_url
states False
in its test suite- constraining TLD to length 6 but TLD length specified by RFC 1034 is 63 octets. Real TLDs available here of length >6 http://data.iana.org/TLD/tlds-alpha-by-domain.txthttp://www.foo.bar./
is valid as per https://www.w3.org/Addressing/URL/url-spec.txt#page13 while is_url
returns False
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 \*
"""
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
.
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"
This is a valid slug '123____123'
while the is_slug
returns false for instances containing consecutive underscore('_'
)
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.
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)
Would it be acceptable adding a function for truncating long strings at word boundaries?
I am thinking something along the lines of this answer: https://stackoverflow.com/a/250373
Happy to prepare a PR for this if that would be ok.
Hello,
I'm listing some scenarios where the is_email
fails:
email@localhost
, email@[127.0.0.1]
are valid while the function 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
[email protected]
and [email protected]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.