istr-python 0.1.1__tar.gz → 0.1.2__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.1
2
2
  Name: istr-python
3
- Version: 0.1.1
3
+ Version: 0.1.2
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
@@ -8,16 +8,21 @@ import math
8
8
  # |_||___/ \__||_|
9
9
  # strings you can count on
10
10
 
11
- __version__ = "0.1.1"
11
+ __version__ = "0.1.2"
12
12
  import functools
13
13
  import math
14
14
 
15
15
  """
16
16
  changelog
17
17
 
18
+ version 0.1.2 2024-04-26
19
+ -------------------------
20
+ Added all relevant string methods to return istrs or data structures with istrs.
21
+ Added corresponding tests.
22
+
18
23
  version 0.1.0 2024-04-22
19
24
  -------------------------
20
- Changed the way istr.range is implemenented.
25
+ Changed the way istr.range is implemennted.
21
26
 
22
27
  Changed the context manager istr.format() to be used directly without the with statement.
23
28
  Also, noww istr.format() works without any argument and then returns the current format.
@@ -38,6 +43,7 @@ version 0.0.8 2024-04-18
38
43
  initial version with changelog
39
44
  """
40
45
 
46
+
41
47
  class _range:
42
48
  """
43
49
  based on https://codereview.stackexchange.com/questions/229073/pure-python-range-implementation
@@ -247,6 +253,8 @@ class istr(str):
247
253
  return cls.range(value.start, value.stop, value.step)
248
254
  if isinstance(value, _range):
249
255
  return value
256
+ if isinstance(value, cls):
257
+ return value
250
258
  if isinstance(value, dict):
251
259
  return type(value)((k, cls(v)) for k, v in value.items())
252
260
  if not isinstance(value, (str, type)) and hasattr(value, "__iter__"):
@@ -258,7 +266,7 @@ class istr(str):
258
266
  as_int = 0
259
267
  else:
260
268
  as_int = cls._to_int(value)
261
- if (cls._format == "" or cls._base != 10) and not isinstance(value,istr):
269
+ if (cls._format == "" or cls._base != 10) and not isinstance(value, istr):
262
270
  if isinstance(value, str):
263
271
  as_str = value
264
272
  else:
@@ -406,10 +414,6 @@ class istr(str):
406
414
  def is_odd(self):
407
415
  return self._as_int % 2 == 1
408
416
 
409
- def join(self, iterable):
410
- s = super().join(iterable)
411
- return self.__class__(s)
412
-
413
417
  def reversed(self):
414
418
  return self[::-1]
415
419
 
@@ -487,19 +491,94 @@ class istr(str):
487
491
  self.saved_cls._base = self.saved_base
488
492
 
489
493
  @classmethod
490
- def range(cls, start,stop=None,step=1):
491
- return _range(cls,start,stop,step)
494
+ def range(cls, start, stop=None, step=1):
495
+ return _range(cls, start, stop, step)
496
+
497
+ def capitalize1(self, *args, **kwargs):
498
+ return self.__class__(super().capitalize(*args, **kwargs))
499
+
500
+ def casefold(self, *args, **kwargs):
501
+ return self.__class__(super().casefold(*args, **kwargs))
502
+
503
+ def center(self, *args, **kwargs):
504
+ return self.__class__(super().center(*args, **kwargs))
505
+
506
+ def expandtabs(self, *args, **kwargs):
507
+ return self.__class__(super().expandtabs(*args, **kwargs))
508
+
509
+ def join(self, *args, **kwargs):
510
+ return self.__class__(super().join(*args, **kwargs))
511
+
512
+ def ljust(self, *args, **kwargs):
513
+ return self.__class__(super().ljust(*args, **kwargs))
514
+
515
+ def lower(self, *args, **kwargs):
516
+ return self.__class__(super().lower(*args, **kwargs))
517
+
518
+ def lstrip(self, *args, **kwargs):
519
+ return self.__class__(super().lstrip(*args, **kwargs))
520
+
521
+ def partition(self, *args, **kwargs):
522
+ return self.__class__(super().partition(*args, **kwargs))
523
+
524
+ def removeprefix(self, *args, **kwargs):
525
+ return self.__class__(super().removeprefix(*args, **kwargs))
492
526
 
527
+ def removesuffix(self, *args, **kwargs):
528
+ return self.__class__(super().removesuffix(*args, **kwargs))
529
+
530
+ def replace(self, *args, **kwargs):
531
+ return self.__class__(super().replace(*args, **kwargs))
532
+
533
+ def rjust(self, *args, **kwargs):
534
+ return self.__class__(super().rjust(*args, **kwargs))
535
+
536
+ def rpartition(self, *args, **kwargs):
537
+ return self.__class__(super().rpartition(*args, **kwargs))
538
+
539
+ def rsplit(self, *args, **kwargs):
540
+ return self.__class__(super().rsplit(*args, **kwargs))
541
+
542
+ def rstrip(self, *args, **kwargs):
543
+ return self.__class__(super().rstrip(*args, **kwargs))
544
+
545
+ def split(self, *args, **kwargs):
546
+ return self.__class__(super().split(*args, **kwargs))
547
+
548
+ def strip(self, *args, **kwargs):
549
+ return self.__class__(super().strip(*args, **kwargs))
550
+
551
+ def swapcase(self, *args, **kwargs):
552
+ return self.__class__(super().swapcase(*args, **kwargs))
553
+
554
+ def title(self, *args, **kwargs):
555
+ return self.__class__(super().title(*args, **kwargs))
556
+
557
+ def translate(self, *args, **kwargs):
558
+ return self.__class__(super().translate(*args, **kwargs))
559
+
560
+ def upper(self, *args, **kwargs):
561
+ return self.__class__(super().upper(*args, **kwargs))
562
+
563
+ def zfill(self, *args, **kwargs):
564
+ return self.__class__(super().zfill(*args, **kwargs))
565
+
566
+ f = "capitalize"
567
+ exec(
568
+ f"""
569
+ def {f}(self, *args, **kwargs):
570
+ return self.__class__(super(istr,self).{f}(*args, **kwargs))
571
+ """,
572
+ globals(),
573
+ locals(),
574
+ )
493
575
 
494
576
 
495
577
  def main():
496
- with istr.base(16):
497
- a = istr(15)
498
- b = a * a
499
- print(b)
500
- c=istr(a)
501
- print(repr(c))
578
+ a = istr("123123")
579
+ print(repr(a.capitalize()))
502
580
 
503
581
 
504
582
  if __name__ == "__main__":
505
- main()
583
+ main()
584
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: istr-python
3
- Version: 0.1.1
3
+ Version: 0.1.2
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
@@ -8,7 +8,7 @@ authors = [
8
8
  {name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com"}
9
9
  ]
10
10
  description = "istr - strings you can count on"
11
- version = "0.1.1"
11
+ version = "0.1.2"
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.7"
14
14
  dependencies = [
@@ -21,3 +21,6 @@ classifiers = [
21
21
  [project.urls]
22
22
  Homepage = "https://github.com/salabim/istr"
23
23
  Repository = "https://github.com/salabim/istr"
24
+
25
+ [tool.setuptools]
26
+ packages = ["istr"]
@@ -408,6 +408,33 @@ def test_repr_mode():
408
408
  with pytest.raises(TypeError):
409
409
  istr.repr_mode("no")
410
410
 
411
+ def test_str_methods():
412
+ a=istr(" 123123 ")
413
+ b=istr("123123")
414
+ assert a.capitalize().equals(a)
415
+ assert a.casefold().equals(a)
416
+ assert a.center(20).equals(istr(' 123123 '))
417
+ assert a.expandtabs(4).equals(a)
418
+ assert istr("").join(("0","1","2")).equals(istr("012"))
419
+ assert a.ljust(20).equals(istr(' 123123 '))
420
+ assert a.lower().equals(a)
421
+ assert a.lstrip().equals(istr('123123 '))
422
+ assert a.partition("3")==(istr(' 12'), istr('3'), istr('123 '))
423
+ assert a.removeprefix(" 12").equals(istr("3123 "))
424
+ assert a.removesuffix("23 ").equals(istr(" 1231"))
425
+ assert a.replace("1","9").equals(istr(" 923923 "))
426
+ assert a.rjust(20).equals(istr(' 123123 '))
427
+ assert b.partition("2")==(istr('1'), istr('2'), istr('3123'))
428
+ assert b.rpartition("2")==(istr('1231'), istr('2'), istr('3'))
429
+ assert b.rsplit("1")==[istr(''), istr('23'), istr('23')]
430
+ assert a.rstrip().equals(istr(' 123123'))
431
+ assert b.split("1")==[istr(''), istr('23'), istr('23')]
432
+ assert a.strip().equals(istr('123123'))
433
+ assert a.swapcase().equals(a)
434
+ assert a.title().equals(a)
435
+ assert a.translate({49: 52}).equals(istr(' 423423 '))
436
+ assert a.upper().equals(a)
437
+ assert b.zfill(10).equals(istr('0000123123'))
411
438
 
412
439
  def test_base():
413
440
  assert istr.base() == 10
File without changes
File without changes