istr-python 1.0.9__tar.gz → 1.0.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {istr_python-1.0.9 → istr_python-1.0.11}/PKG-INFO +20 -5
- {istr_python-1.0.9 → istr_python-1.0.11}/README.md +19 -4
- {istr_python-1.0.9 → istr_python-1.0.11}/istr/istr.py +30 -19
- {istr_python-1.0.9 → istr_python-1.0.11}/istr_python.egg-info/PKG-INFO +20 -5
- {istr_python-1.0.9 → istr_python-1.0.11}/pyproject.toml +1 -1
- {istr_python-1.0.9 → istr_python-1.0.11}/tests/test_istr.py +33 -6
- {istr_python-1.0.9 → istr_python-1.0.11}/istr/LICENSE.txt +0 -0
- {istr_python-1.0.9 → istr_python-1.0.11}/istr/__init__.py +0 -0
- {istr_python-1.0.9 → istr_python-1.0.11}/istr_python.egg-info/SOURCES.txt +0 -0
- {istr_python-1.0.9 → istr_python-1.0.11}/istr_python.egg-info/dependency_links.txt +0 -0
- {istr_python-1.0.9 → istr_python-1.0.11}/istr_python.egg-info/top_level.txt +0 -0
- {istr_python-1.0.9 → istr_python-1.0.11}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.11
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -343,14 +343,29 @@ a, b, c = istr(5, 6, 7) ==> a=istr('5') , b=istr('6'), c=istr('7')
|
|
|
343
343
|
```
|
|
344
344
|
|
|
345
345
|
#### test for even/odd
|
|
346
|
-
It is possible to test for even/odd (provided the istr can be interpreted as an int) with the
|
|
347
|
-
|
|
348
|
-
`is_even` and `is_odd` method, e.g.
|
|
346
|
+
It is possible to test for even/odd (provided the istr can be interpreted as an int) with the `is_even` and `is_odd` method, e.g.
|
|
349
347
|
|
|
350
348
|
```
|
|
351
349
|
istr(4).is_even()) ==> True
|
|
352
350
|
istr(5).is_odd()) ==> True
|
|
353
351
|
```
|
|
352
|
+
#### test for square
|
|
353
|
+
|
|
354
|
+
It is possible to test whether the value is a perfect square (provided the istr can be interpreted as an int) with the `is_square` method, e.g.
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
istr(4).is_square() ==> True
|
|
358
|
+
istr(5).is_square()) ==> False
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
#### test for prime
|
|
362
|
+
|
|
363
|
+
It is possible to test whether the value is a prime number (provided the istr can be interpreted as an int) with the `is_prime` method, e.g.
|
|
364
|
+
|
|
365
|
+
```
|
|
366
|
+
istr(4).is_prime() ==> False
|
|
367
|
+
istr(5).is_prime()) ==> True
|
|
368
|
+
```
|
|
354
369
|
|
|
355
370
|
#### test for divisibility
|
|
356
371
|
|
|
@@ -365,7 +380,7 @@ It is possible to test whether an istr is divisible by a given value with the `i
|
|
|
365
380
|
|
|
366
381
|
#### test whether all characters are distinct
|
|
367
382
|
|
|
368
|
-
With the `all_distinct` method, it is possible to test whether all characters are distinct (i.e. no character
|
|
383
|
+
With the `all_distinct` method, it is possible to test whether all characters are distinct (i.e. no character appears more than once).
|
|
369
384
|
|
|
370
385
|
```
|
|
371
386
|
istr('01234').all_distict() ==> True
|
|
@@ -330,14 +330,29 @@ a, b, c = istr(5, 6, 7) ==> a=istr('5') , b=istr('6'), c=istr('7')
|
|
|
330
330
|
```
|
|
331
331
|
|
|
332
332
|
#### test for even/odd
|
|
333
|
-
It is possible to test for even/odd (provided the istr can be interpreted as an int) with the
|
|
334
|
-
|
|
335
|
-
`is_even` and `is_odd` method, e.g.
|
|
333
|
+
It is possible to test for even/odd (provided the istr can be interpreted as an int) with the `is_even` and `is_odd` method, e.g.
|
|
336
334
|
|
|
337
335
|
```
|
|
338
336
|
istr(4).is_even()) ==> True
|
|
339
337
|
istr(5).is_odd()) ==> True
|
|
340
338
|
```
|
|
339
|
+
#### test for square
|
|
340
|
+
|
|
341
|
+
It is possible to test whether the value is a perfect square (provided the istr can be interpreted as an int) with the `is_square` method, e.g.
|
|
342
|
+
|
|
343
|
+
```
|
|
344
|
+
istr(4).is_square() ==> True
|
|
345
|
+
istr(5).is_square()) ==> False
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
#### test for prime
|
|
349
|
+
|
|
350
|
+
It is possible to test whether the value is a prime number (provided the istr can be interpreted as an int) with the `is_prime` method, e.g.
|
|
351
|
+
|
|
352
|
+
```
|
|
353
|
+
istr(4).is_prime() ==> False
|
|
354
|
+
istr(5).is_prime()) ==> True
|
|
355
|
+
```
|
|
341
356
|
|
|
342
357
|
#### test for divisibility
|
|
343
358
|
|
|
@@ -352,7 +367,7 @@ It is possible to test whether an istr is divisible by a given value with the `i
|
|
|
352
367
|
|
|
353
368
|
#### test whether all characters are distinct
|
|
354
369
|
|
|
355
|
-
With the `all_distinct` method, it is possible to test whether all characters are distinct (i.e. no character
|
|
370
|
+
With the `all_distinct` method, it is possible to test whether all characters are distinct (i.e. no character appears more than once).
|
|
356
371
|
|
|
357
372
|
```
|
|
358
373
|
istr('01234').all_distict() ==> True
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
# |_||___/ \__||_|
|
|
6
6
|
# strings you can count on
|
|
7
7
|
|
|
8
|
-
__version__ = "1.0.
|
|
8
|
+
__version__ = "1.0.11"
|
|
9
9
|
import functools
|
|
10
10
|
import math
|
|
11
|
-
import copy
|
|
12
11
|
import itertools
|
|
13
12
|
|
|
14
13
|
"""
|
|
@@ -345,14 +344,33 @@ class istr(str):
|
|
|
345
344
|
|
|
346
345
|
def is_even(self):
|
|
347
346
|
if not self.is_int():
|
|
348
|
-
raise TypeError(f"
|
|
347
|
+
raise TypeError(f"not interpretable as int: {self._frepr(self)}")
|
|
349
348
|
return self._as_int % 2 == 0
|
|
350
349
|
|
|
351
350
|
def is_odd(self):
|
|
352
351
|
if not self.is_int():
|
|
353
|
-
raise TypeError(f"
|
|
352
|
+
raise TypeError(f"not interpretable as int: {self._frepr(self)}")
|
|
354
353
|
return self._as_int % 2 == 1
|
|
355
354
|
|
|
355
|
+
def is_square(self):
|
|
356
|
+
if not self.is_int():
|
|
357
|
+
raise TypeError(f"not interpretable as int: {self._frepr(self)}")
|
|
358
|
+
return self._as_int >= 0 and self == math.isqrt(self._as_int) ** 2
|
|
359
|
+
|
|
360
|
+
def is_prime(self):
|
|
361
|
+
if not self.is_int():
|
|
362
|
+
raise TypeError(f"not interpretable as int: {self._frepr(self)}")
|
|
363
|
+
if self._as_int < 2:
|
|
364
|
+
return False
|
|
365
|
+
if self._as_int == 2:
|
|
366
|
+
return True
|
|
367
|
+
if not self._as_int & 1:
|
|
368
|
+
return False
|
|
369
|
+
for x in range(3, int(self._as_int**0.5) + 1, 2):
|
|
370
|
+
if self._as_int % x == 0:
|
|
371
|
+
return False
|
|
372
|
+
return True
|
|
373
|
+
|
|
356
374
|
def __or__(self, other):
|
|
357
375
|
try:
|
|
358
376
|
return self.__class__(str(self).__add__(other))
|
|
@@ -385,9 +403,9 @@ class istr(str):
|
|
|
385
403
|
|
|
386
404
|
def reversed(self):
|
|
387
405
|
return self[::-1]
|
|
388
|
-
|
|
406
|
+
|
|
389
407
|
def is_divisible_by(self, divisor):
|
|
390
|
-
return self._as_int % int(divisor)
|
|
408
|
+
return self._as_int % int(divisor) == 0
|
|
391
409
|
|
|
392
410
|
def _str_method(self, name, *args, **kwargs):
|
|
393
411
|
return self.__class__(getattr(super(), name)(*args, **kwargs))
|
|
@@ -436,8 +454,7 @@ class istr(str):
|
|
|
436
454
|
|
|
437
455
|
cls._int_format = int_format
|
|
438
456
|
|
|
439
|
-
def __enter__(self):
|
|
440
|
-
...
|
|
457
|
+
def __enter__(self): ...
|
|
441
458
|
|
|
442
459
|
def __exit__(self, exc_type, exc_value, exc_tb):
|
|
443
460
|
self.saved_cls._int_format = self.saved_int_format
|
|
@@ -456,8 +473,7 @@ class istr(str):
|
|
|
456
473
|
self.saved_cls = cls
|
|
457
474
|
cls._repr_mode = mode
|
|
458
475
|
|
|
459
|
-
def __enter__(self):
|
|
460
|
-
...
|
|
476
|
+
def __enter__(self): ...
|
|
461
477
|
|
|
462
478
|
def __exit__(self, exc_type, exc_value, exc_tb):
|
|
463
479
|
self.saved_cls._repr_mode = self.saved_repr_mode
|
|
@@ -476,8 +492,7 @@ class istr(str):
|
|
|
476
492
|
self.saved_cls = cls
|
|
477
493
|
cls._base = base
|
|
478
494
|
|
|
479
|
-
def __enter__(self):
|
|
480
|
-
...
|
|
495
|
+
def __enter__(self): ...
|
|
481
496
|
|
|
482
497
|
def __exit__(self, exc_type, exc_value, exc_tb):
|
|
483
498
|
self.saved_cls._base = self.saved_base
|
|
@@ -557,12 +572,8 @@ class istr(str):
|
|
|
557
572
|
|
|
558
573
|
|
|
559
574
|
def main():
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
print(istr(19).is_divisible_by(istr(3)))
|
|
564
|
-
print(istr.digits(1,9))
|
|
565
|
-
|
|
575
|
+
...
|
|
576
|
+
|
|
577
|
+
|
|
566
578
|
if __name__ == "__main__":
|
|
567
579
|
main()
|
|
568
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.11
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -343,14 +343,29 @@ a, b, c = istr(5, 6, 7) ==> a=istr('5') , b=istr('6'), c=istr('7')
|
|
|
343
343
|
```
|
|
344
344
|
|
|
345
345
|
#### test for even/odd
|
|
346
|
-
It is possible to test for even/odd (provided the istr can be interpreted as an int) with the
|
|
347
|
-
|
|
348
|
-
`is_even` and `is_odd` method, e.g.
|
|
346
|
+
It is possible to test for even/odd (provided the istr can be interpreted as an int) with the `is_even` and `is_odd` method, e.g.
|
|
349
347
|
|
|
350
348
|
```
|
|
351
349
|
istr(4).is_even()) ==> True
|
|
352
350
|
istr(5).is_odd()) ==> True
|
|
353
351
|
```
|
|
352
|
+
#### test for square
|
|
353
|
+
|
|
354
|
+
It is possible to test whether the value is a perfect square (provided the istr can be interpreted as an int) with the `is_square` method, e.g.
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
istr(4).is_square() ==> True
|
|
358
|
+
istr(5).is_square()) ==> False
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
#### test for prime
|
|
362
|
+
|
|
363
|
+
It is possible to test whether the value is a prime number (provided the istr can be interpreted as an int) with the `is_prime` method, e.g.
|
|
364
|
+
|
|
365
|
+
```
|
|
366
|
+
istr(4).is_prime() ==> False
|
|
367
|
+
istr(5).is_prime()) ==> True
|
|
368
|
+
```
|
|
354
369
|
|
|
355
370
|
#### test for divisibility
|
|
356
371
|
|
|
@@ -365,7 +380,7 @@ It is possible to test whether an istr is divisible by a given value with the `i
|
|
|
365
380
|
|
|
366
381
|
#### test whether all characters are distinct
|
|
367
382
|
|
|
368
|
-
With the `all_distinct` method, it is possible to test whether all characters are distinct (i.e. no character
|
|
383
|
+
With the `all_distinct` method, it is possible to test whether all characters are distinct (i.e. no character appears more than once).
|
|
369
384
|
|
|
370
385
|
```
|
|
371
386
|
istr('01234').all_distict() ==> True
|
|
@@ -304,7 +304,34 @@ def test_even_odd():
|
|
|
304
304
|
assert not istr(1).is_even()
|
|
305
305
|
|
|
306
306
|
assert istr(12345678).is_even()
|
|
307
|
-
|
|
307
|
+
with pytest.raises(TypeError, match=re.escape(f"not interpretable as int")):
|
|
308
|
+
istr("a").is_odd()
|
|
309
|
+
with pytest.raises(TypeError, match=re.escape(f"not interpretable as int")):
|
|
310
|
+
istr("a").is_even()
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def test_is_square():
|
|
314
|
+
assert not istr(-1).is_square()
|
|
315
|
+
assert istr(0).is_square()
|
|
316
|
+
assert istr(1).is_square()
|
|
317
|
+
assert not istr(2).is_square()
|
|
318
|
+
assert istr(4).is_square()
|
|
319
|
+
assert istr(16).is_square()
|
|
320
|
+
assert not istr(99).is_square()
|
|
321
|
+
with pytest.raises(TypeError, match=re.escape(f"not interpretable as int")):
|
|
322
|
+
istr("a").is_square()
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def test_is_prime():
|
|
326
|
+
assert not istr(0).is_prime()
|
|
327
|
+
assert not istr(1).is_prime()
|
|
328
|
+
assert istr(2).is_prime()
|
|
329
|
+
assert istr(3).is_prime()
|
|
330
|
+
assert not istr(4).is_prime()
|
|
331
|
+
assert istr(97).is_prime()
|
|
332
|
+
assert not istr(99).is_prime()
|
|
333
|
+
with pytest.raises(TypeError, match=re.escape(f"not interpretable as int")):
|
|
334
|
+
istr("a").is_prime()
|
|
308
335
|
|
|
309
336
|
|
|
310
337
|
def test_join():
|
|
@@ -555,12 +582,14 @@ def test_base():
|
|
|
555
582
|
with istr.base(10):
|
|
556
583
|
assert a * a == 225
|
|
557
584
|
|
|
558
|
-
|
|
585
|
+
|
|
586
|
+
def test_is_divisible():
|
|
559
587
|
assert istr(18).is_divisible_by(3)
|
|
560
588
|
assert istr(18).is_divisible_by(istr(3))
|
|
561
589
|
assert not istr(19).is_divisible_by(3)
|
|
562
590
|
assert not istr(19).is_divisible_by(istr(3))
|
|
563
|
-
|
|
591
|
+
|
|
592
|
+
|
|
564
593
|
def test_digits():
|
|
565
594
|
assert istr.digits().equals(istr("0123456789"))
|
|
566
595
|
assert istr.digits("").equals(istr("0123456789"))
|
|
@@ -628,8 +657,7 @@ def test_all_distinct():
|
|
|
628
657
|
|
|
629
658
|
|
|
630
659
|
def test_subclassing():
|
|
631
|
-
class jstr(istr):
|
|
632
|
-
...
|
|
660
|
+
class jstr(istr): ...
|
|
633
661
|
|
|
634
662
|
assert jstr(5).equals(jstr(5))
|
|
635
663
|
assert repr(jstr(*range(3))) == "(jstr('0'), jstr('1'), jstr('2'))"
|
|
@@ -637,4 +665,3 @@ def test_subclassing():
|
|
|
637
665
|
|
|
638
666
|
if __name__ == "__main__":
|
|
639
667
|
pytest.main(["-vv", "-s", "-x", __file__])
|
|
640
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|