6161)
6262
6363if TYPE_CHECKING :
64- from collections .abc import Container , Iterable , Sequence
64+ from collections .abc import Container , Iterable
6565 from types import ModuleType
6666
6767 from ._msi import _Database
68+ from .sequence import _SequenceType
6869
6970__version__ = metadata .version ("python-msilib" )
7071
@@ -187,9 +188,9 @@ def sql(self) -> str:
187188 fields = []
188189 keys = []
189190 self .fields .sort ()
190- fields = [None ] * len (self .fields )
191+ # fields: list[str] = ["" ] * len(self.fields)
191192 for index , name , ftype in self .fields :
192- idx = index - 1
193+ index - 1
193194 unk = ftype & ~ knownbits
194195 if unk :
195196 print (f"{ self .name } .{ name } unknown bits { unk :x} " )
@@ -212,7 +213,8 @@ def sql(self) -> str:
212213 flags = "" if ftype & type_nullable else " NOT NULL"
213214 if ftype & type_localizable :
214215 flags += " LOCALIZABLE"
215- fields [idx ] = f"`{ name } ` { tname } { flags } "
216+ # fields[idx] = f"`{name}` {tname}{flags}"
217+ fields .append (f"`{ name } ` { tname } { flags } " )
216218 if ftype & type_key :
217219 keys .append (f"`{ name } `" )
218220 fields = ", " .join (fields )
@@ -225,22 +227,18 @@ def create(self, db: _Database) -> None:
225227 v .Close ()
226228
227229
228- class _Unspecified :
229- pass
230-
231-
232230def change_sequence (
233- seq : Sequence [ tuple [ str , str | None , int ]] ,
231+ seq : _SequenceType ,
234232 action : str ,
235- seqno : int | type [ _Unspecified ] = _Unspecified ,
236- cond : str | type [ _Unspecified ] = _Unspecified ,
233+ seqno : int | None = None ,
234+ cond : str | None = None ,
237235) -> None :
238236 """Change the sequence number of an action in a sequence list."""
239237 for i in range (len (seq )):
240238 if seq [i ][0 ] == action :
241- if cond is _Unspecified :
239+ if cond is None :
242240 cond = seq [i ][1 ]
243- if seqno is _Unspecified :
241+ if seqno is None :
244242 seqno = seq [i ][2 ]
245243 seq [i ] = (action , cond , seqno )
246244 return
@@ -387,7 +385,7 @@ def gen_id(self, file: str) -> str:
387385 return logical
388386
389387 def append (
390- self , full : str , file : str , logical : str
388+ self , full : str , file : str , logical : str | None
391389 ) -> tuple [int , str ] | None :
392390 if os .path .isdir (full ):
393391 return None
@@ -415,7 +413,7 @@ def commit(self, db: _Database) -> None:
415413class Directory :
416414 db : _Database
417415 cab : CAB
418- basedir : str
416+ basedir : Directory
419417 physical : str
420418 logical : str
421419 component : str | None
@@ -429,7 +427,7 @@ def __init__(
429427 self ,
430428 db : _Database ,
431429 cab : CAB ,
432- basedir : str ,
430+ basedir : Directory ,
433431 physical : str ,
434432 _logical : str ,
435433 default : str ,
@@ -485,7 +483,7 @@ def start_component(
485483 no keyfile is given, the KeyPath is left null in the Component table.
486484 """
487485 if flags is None :
488- flags = self .componentflags
486+ flags = self .componentflags or 0
489487 uuid = gen_uuid () if uuid is None else uuid .upper ()
490488 if component is None :
491489 component = self .logical
@@ -527,37 +525,37 @@ def make_short(self, file: str) -> str:
527525 and file == oldfile
528526 and (not suffix or len (suffix ) <= 3 )
529527 ):
530- file = f"{ prefix } .{ suffix } " if suffix else prefix
528+ newfile = f"{ prefix } .{ suffix } " if suffix else prefix
531529 else :
532- file = None
533- if file is None or file in self .short_names :
530+ newfile = None
531+ if newfile is None or newfile in self .short_names :
534532 prefix = prefix [:6 ]
535533 if suffix :
536534 suffix = suffix [:3 ]
537535 pos = 1
538536 while 1 :
539537 if suffix :
540- file = f"{ prefix } ~{ pos } .{ suffix } "
538+ newfile = f"{ prefix } ~{ pos } .{ suffix } "
541539 else :
542- file = f"{ prefix } ~{ pos } "
543- if file not in self .short_names :
540+ newfile = f"{ prefix } ~{ pos } "
541+ if newfile not in self .short_names :
544542 break
545543 pos += 1
546544 assert pos < 10000
547545 if pos in (10 , 100 , 1000 ):
548546 prefix = prefix [:- 1 ]
549- self .short_names .add (file )
547+ self .short_names .add (newfile )
550548 # restrictions on short names
551- assert not re .search (r'[\?|><:/*"+,;=\[\]]' , file )
552- return file
549+ assert not re .search (r'[\?|><:/*"+,;=\[\]]' , newfile )
550+ return newfile
553551
554552 def add_file (
555553 self ,
556554 file : str ,
557555 src : str | None = None ,
558556 version : str | None = None ,
559557 language : str | None = None ,
560- ) -> str :
558+ ) -> str | None :
561559 """Add a file to the current component of the directory, starting a new
562560 one if there is no current component. By default, the file name in the
563561 source and the file table will be identical. If the src file is
@@ -575,7 +573,10 @@ def add_file(
575573 # restrictions on long names
576574 assert not re .search (r'[\?|><:/*]"' , file )
577575 logical = self .keyfiles .get (file , None )
578- sequence , logical = self .cab .append (absolute , file , logical )
576+ ok = self .cab .append (absolute , file , logical )
577+ if ok is None :
578+ return None
579+ sequence , logical = ok
579580 assert logical not in self .ids
580581 self .ids .add (logical )
581582 short = self .make_short (file )
@@ -655,6 +656,8 @@ def glob(
655656
656657 def remove_pyc (self ) -> None :
657658 """Remove .pyc files on uninstall."""
659+ if not self .component :
660+ self .component = self .logical
658661 add_data (
659662 self .db ,
660663 "RemoveFile" ,
@@ -691,12 +694,11 @@ def __init__(
691694 attributes : int = 0 ,
692695 ) -> None :
693696 self .id = id
694- if parent :
695- parent = parent .id
697+ pid = parent .id if parent else None
696698 add_data (
697699 db ,
698700 "Feature" ,
699- [(id , parent , title , desc , display , level , directory , attributes )],
701+ [(id , pid , title , desc , display , level , directory , attributes )],
700702 )
701703
702704 def set_current (self ) -> None :
@@ -886,7 +888,7 @@ def radiogroup(
886888 w : int ,
887889 h : int ,
888890 attr : int ,
889- prop : str | None ,
891+ prop : str ,
890892 text : str | None ,
891893 next : str | None ,
892894 ) -> Control :
0 commit comments