istr-python 1.1.5__tar.gz → 1.1.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.5
3
+ Version: 1.1.6
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
@@ -372,7 +372,7 @@ It is also possible to test for square of an ordinary int:
372
372
  ```
373
373
  istr.is_square(4) ==> True
374
374
  istr.is_square(5) ==> False
375
-
375
+ ```
376
376
  #### test for cube
377
377
 
378
378
  It is possible to test whether the value is a perfect cube (provided the istr can be interpreted as an int) with the `is_cube` method, e.g.
@@ -385,6 +385,7 @@ It is also possible to test for cube of an ordinary int:
385
385
  ```
386
386
  istr.is_cube(27) ==> True
387
387
  istr.is_cube(28 ==> False
388
+ ```
388
389
 
389
390
  #### test for power of
390
391
 
@@ -398,6 +399,7 @@ It is also possible to test for power of of an ordinary int:
398
399
  ```
399
400
  istr.is_power_of(81, 4) ==> True
400
401
  istr.is_power_of(82, 4) ==> False
402
+ ```
401
403
 
402
404
  #### test for prime
403
405
 
@@ -784,25 +786,25 @@ operator/function int str Example
784
786
  + x istr(20) + 3 ==> istr('23')
785
787
  _ x istr(20) - 3 ==> istr('17')
786
788
  * x istr(20) * 3 ==> istr('60')
787
- / x istr(20) / 3 ==> istr('6')
788
- // x istr(20) // 3 ==> istr('6')
789
- % x istr(20) % 3 ==> istr('2')
790
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
791
- ** x istr(2) ** 3 ==> istr('8')
792
- <=, <, >, >= x istr('100') > istr('2') ==> True
793
- abs x abs(istr(-20)) ==> istr('20')
794
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
795
- bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
796
- @ x istr(20) @ 3 ==> istr('202020')
797
- | x istr(20) | '5' ==> istr('205')
798
- slicing x istr(12345)[1:3] ==> istr('23')
799
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
800
- len x len(istr(' 20 ')) ==> 4
801
- count x istr(100).count('0') ==> 2
802
- index x istr(' 100 ').index('0') ==> 2
803
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
804
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
805
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
789
+ / x istr(20) / 3 ==> istr('6')
790
+ // x istr(20) // 3 ==> istr('6')
791
+ % x istr(20) % 3 ==> istr('2')
792
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
793
+ ** x istr(2) ** 3 ==> istr('8')
794
+ <=, <, >, >= x istr('100') > istr('2') ==> True
795
+ abs x abs(istr(-20)) ==> istr('20')
796
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
797
+ bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
798
+ @ x istr(20) @ 3 ==> istr('202020')
799
+ | x istr(20) | '5' ==> istr('205')
800
+ slicing x istr(12345)[1:3] ==> istr('23')
801
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
802
+ len x len(istr(' 20 ')) ==> 4
803
+ count x istr(100).count('0') ==> 2
804
+ index x istr(' 100 ').index('0') ==> 2
805
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
806
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
807
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
806
808
  istr('aAbBcC').islower() ==> False
807
809
  istr(' abc ').strip() ==> istr('abc')
808
810
  ...
@@ -359,7 +359,7 @@ It is also possible to test for square of an ordinary int:
359
359
  ```
360
360
  istr.is_square(4) ==> True
361
361
  istr.is_square(5) ==> False
362
-
362
+ ```
363
363
  #### test for cube
364
364
 
365
365
  It is possible to test whether the value is a perfect cube (provided the istr can be interpreted as an int) with the `is_cube` method, e.g.
@@ -372,6 +372,7 @@ It is also possible to test for cube of an ordinary int:
372
372
  ```
373
373
  istr.is_cube(27) ==> True
374
374
  istr.is_cube(28 ==> False
375
+ ```
375
376
 
376
377
  #### test for power of
377
378
 
@@ -385,6 +386,7 @@ It is also possible to test for power of of an ordinary int:
385
386
  ```
386
387
  istr.is_power_of(81, 4) ==> True
387
388
  istr.is_power_of(82, 4) ==> False
389
+ ```
388
390
 
389
391
  #### test for prime
390
392
 
@@ -771,25 +773,25 @@ operator/function int str Example
771
773
  + x istr(20) + 3 ==> istr('23')
772
774
  _ x istr(20) - 3 ==> istr('17')
773
775
  * x istr(20) * 3 ==> istr('60')
774
- / x istr(20) / 3 ==> istr('6')
775
- // x istr(20) // 3 ==> istr('6')
776
- % x istr(20) % 3 ==> istr('2')
777
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
778
- ** x istr(2) ** 3 ==> istr('8')
779
- <=, <, >, >= x istr('100') > istr('2') ==> True
780
- abs x abs(istr(-20)) ==> istr('20')
781
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
782
- bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
783
- @ x istr(20) @ 3 ==> istr('202020')
784
- | x istr(20) | '5' ==> istr('205')
785
- slicing x istr(12345)[1:3] ==> istr('23')
786
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
787
- len x len(istr(' 20 ')) ==> 4
788
- count x istr(100).count('0') ==> 2
789
- index x istr(' 100 ').index('0') ==> 2
790
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
791
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
792
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
776
+ / x istr(20) / 3 ==> istr('6')
777
+ // x istr(20) // 3 ==> istr('6')
778
+ % x istr(20) % 3 ==> istr('2')
779
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
780
+ ** x istr(2) ** 3 ==> istr('8')
781
+ <=, <, >, >= x istr('100') > istr('2') ==> True
782
+ abs x abs(istr(-20)) ==> istr('20')
783
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
784
+ bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
785
+ @ x istr(20) @ 3 ==> istr('202020')
786
+ | x istr(20) | '5' ==> istr('205')
787
+ slicing x istr(12345)[1:3] ==> istr('23')
788
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
789
+ len x len(istr(' 20 ')) ==> 4
790
+ count x istr(100).count('0') ==> 2
791
+ index x istr(' 100 ').index('0') ==> 2
792
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
793
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
794
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
793
795
  istr('aAbBcC').islower() ==> False
794
796
  istr(' abc ').strip() ==> istr('abc')
795
797
  ...
@@ -5,7 +5,7 @@
5
5
  # |_||___/ \__||_|
6
6
  # strings you can count on
7
7
 
8
- __version__ = "1.1.5"
8
+ __version__ = "1.1.6"
9
9
  import functools
10
10
  import itertools
11
11
  import types
@@ -15,7 +15,7 @@ import inspect
15
15
  """
16
16
  Note: the changelog is now in changelog.md
17
17
 
18
- You can view the changelog on www.salabim.org/istr/changelog.html
18
+ You can view the changelog on www.salabim.org/istr/changelog
19
19
 
20
20
  The readme can be viewed on www.salabim.org/istr/
21
21
  """
@@ -202,7 +202,8 @@ class istr(str):
202
202
  it is possible to give more than one parameter, in which case a tuple
203
203
  of the istrs of the parameters will be returned, which can be handy
204
204
  to multiple assign, e.g.
205
- a, b, c = istr(5, 6, 7) ==> a=istr('5') , b=istr('6'), c=istr('7')"""
205
+ a, b, c = istr(5, 6, 7) ==> a=istr('5') , b=istr('6'), c=istr('7')
206
+ """
206
207
 
207
208
  __slots__ = ("_as_int", "_as_repr")
208
209
 
@@ -345,57 +346,30 @@ class istr(str):
345
346
  return int(self._as_int)
346
347
 
347
348
  def is_even(self):
348
- if isinstance(self, istr):
349
- if not self.is_int():
350
- raise TypeError(f"not interpretable as int: {self._frepr(self)}")
351
- n = self._as_int
352
- else:
353
- n = int(self)
354
-
355
- return n % 2 == 0
349
+ return istr.is_divisible_by(self,2)
356
350
 
357
351
  def is_odd(self):
358
- if isinstance(self, istr):
359
- if not self.is_int():
360
- raise TypeError(f"not interpretable as int: {self._frepr(self)}")
361
- n = self._as_int
362
- else:
363
- n = int(self)
352
+ return not istr.is_divisible_by(self,2)
364
353
 
365
- return n % 2 == 1
354
+ def is_divisible_by(self, divisor):
355
+ return istr.interpret_as_int(self) % int(divisor) == 0
366
356
 
367
357
  def is_square(self):
368
- return istr._is_power_of(self, 2)
358
+ return istr.is_power_of(self, 2)
369
359
 
370
360
  def is_cube(self):
371
- return istr._is_power_of(self, 3)
361
+ return istr.is_power_of(self, 3)
372
362
 
373
363
  def is_power_of(self, exponent):
374
- return istr._is_power_of(self, exponent)
375
-
376
- @staticmethod
377
- def _is_power_of(self, exponent):
378
- if isinstance(self, istr):
379
- if not self.is_int():
380
- raise TypeError(f"not interpretable as int: {self._frepr(self)}")
381
- n = self._as_int
382
- else:
383
- n = int(self)
364
+ n = istr.interpret_as_int(self)
384
365
  if exponent < 1:
385
366
  raise ValueError(f"exponent must be >=1; not {exponent}")
386
367
  if not isinstance(exponent, int):
387
368
  raise TypeError(f"exponent must be int; not {type(exponent)}")
388
-
389
369
  return n >= 0 and self == round(n ** (1 / exponent)) ** exponent
390
370
 
391
371
  def is_prime(self):
392
- if isinstance(self, istr):
393
- if not self.is_int():
394
- raise TypeError(f"not interpretable as int: {self._frepr(self)}")
395
- n = self._as_int
396
- else:
397
- n = int(self)
398
-
372
+ n = istr.interpret_as_int(self)
399
373
  if n < 2:
400
374
  return False
401
375
  if n == 2:
@@ -429,6 +403,19 @@ class istr(str):
429
403
  raise ValueError(f"incorrect number of variables {len(letters)}; should be {len(self)}")
430
404
  namespace.update(lookup)
431
405
 
406
+ @classmethod
407
+ def compose(cls, letters, namespace=None):
408
+ """
409
+ compose an istr from individual letter variables
410
+ """
411
+ if namespace is None:
412
+ namespace = inspect.currentframe().f_back.f_globals
413
+ for letter in letters:
414
+ if letter not in namespace:
415
+ raise ValueError(f"variable {letter} not defined")
416
+
417
+ return istr("").join(istr(namespace[letter]) for letter in letters)
418
+
432
419
  def __or__(self, other):
433
420
  try:
434
421
  return self.__class__(str(self).__add__(other))
@@ -462,14 +449,14 @@ class istr(str):
462
449
  def reversed(self):
463
450
  return self[::-1]
464
451
 
465
- def is_divisible_by(self, divisor):
452
+ def interpret_as_int(self):
466
453
  if isinstance(self, istr):
467
454
  if not self.is_int():
468
455
  raise TypeError(f"not interpretable as int: {self._frepr(self)}")
469
456
  n = self._as_int
470
457
  else:
471
458
  n = int(self)
472
- return n % int(divisor) == 0
459
+ return n
473
460
 
474
461
  def _str_method(self, name, *args, **kwargs):
475
462
  return self.__class__(getattr(super(), name)(*args, **kwargs))
@@ -575,7 +562,7 @@ class istr(str):
575
562
  if no args, 0-9 will be used
576
563
 
577
564
  all given args will be used
578
- each arg has to be either null string, <digit>, <digit>-<digit> or -<digit>
565
+ each arg has to be either null string, <digit>, <digit>-<digit>, <digit>- or -<digit>
579
566
 
580
567
  the digits may be '0' through '9' and 'A' through 'Z' (not case sensitive)
581
568
  The returned value will always be in uppercase (if applicable).
@@ -636,19 +623,6 @@ class istr(str):
636
623
  cls._digits_cache[key] = result
637
624
  return result
638
625
 
639
- @classmethod
640
- def compose(cls, letters, namespace=None):
641
- """
642
- compose an istr from individual letter variables
643
- """
644
- if namespace is None:
645
- namespace = inspect.currentframe().f_back.f_globals
646
- for letter in letters:
647
- if letter not in namespace:
648
- raise ValueError(f"variable {letter} not defined")
649
-
650
- return istr("").join(istr(namespace[letter]) for letter in letters)
651
-
652
626
 
653
627
  istr.type = type(istr(0))
654
628
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.5
3
+ Version: 1.1.6
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
@@ -372,7 +372,7 @@ It is also possible to test for square of an ordinary int:
372
372
  ```
373
373
  istr.is_square(4) ==> True
374
374
  istr.is_square(5) ==> False
375
-
375
+ ```
376
376
  #### test for cube
377
377
 
378
378
  It is possible to test whether the value is a perfect cube (provided the istr can be interpreted as an int) with the `is_cube` method, e.g.
@@ -385,6 +385,7 @@ It is also possible to test for cube of an ordinary int:
385
385
  ```
386
386
  istr.is_cube(27) ==> True
387
387
  istr.is_cube(28 ==> False
388
+ ```
388
389
 
389
390
  #### test for power of
390
391
 
@@ -398,6 +399,7 @@ It is also possible to test for power of of an ordinary int:
398
399
  ```
399
400
  istr.is_power_of(81, 4) ==> True
400
401
  istr.is_power_of(82, 4) ==> False
402
+ ```
401
403
 
402
404
  #### test for prime
403
405
 
@@ -784,25 +786,25 @@ operator/function int str Example
784
786
  + x istr(20) + 3 ==> istr('23')
785
787
  _ x istr(20) - 3 ==> istr('17')
786
788
  * x istr(20) * 3 ==> istr('60')
787
- / x istr(20) / 3 ==> istr('6')
788
- // x istr(20) // 3 ==> istr('6')
789
- % x istr(20) % 3 ==> istr('2')
790
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
791
- ** x istr(2) ** 3 ==> istr('8')
792
- <=, <, >, >= x istr('100') > istr('2') ==> True
793
- abs x abs(istr(-20)) ==> istr('20')
794
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
795
- bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
796
- @ x istr(20) @ 3 ==> istr('202020')
797
- | x istr(20) | '5' ==> istr('205')
798
- slicing x istr(12345)[1:3] ==> istr('23')
799
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
800
- len x len(istr(' 20 ')) ==> 4
801
- count x istr(100).count('0') ==> 2
802
- index x istr(' 100 ').index('0') ==> 2
803
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
804
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
805
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
789
+ / x istr(20) / 3 ==> istr('6')
790
+ // x istr(20) // 3 ==> istr('6')
791
+ % x istr(20) % 3 ==> istr('2')
792
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
793
+ ** x istr(2) ** 3 ==> istr('8')
794
+ <=, <, >, >= x istr('100') > istr('2') ==> True
795
+ abs x abs(istr(-20)) ==> istr('20')
796
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
797
+ bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
798
+ @ x istr(20) @ 3 ==> istr('202020')
799
+ | x istr(20) | '5' ==> istr('205')
800
+ slicing x istr(12345)[1:3] ==> istr('23')
801
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
802
+ len x len(istr(' 20 ')) ==> 4
803
+ count x istr(100).count('0') ==> 2
804
+ index x istr(' 100 ').index('0') ==> 2
805
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
806
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
807
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
806
808
  istr('aAbBcC').islower() ==> False
807
809
  istr(' abc ').strip() ==> istr('abc')
808
810
  ...
@@ -10,7 +10,7 @@ authors = [
10
10
  { name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
11
11
  ]
12
12
  description = "istr - strings you can count on"
13
- version = "1.1.5"
13
+ version = "1.1.6"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.7"
16
16
  dependencies = []
File without changes