@@ -154,20 +154,19 @@ def assume_untrusted_cert_issuer(self, value) -> None:
154154 self .set_preference ("webdriver_assume_untrusted_issuer" , value )
155155
156156 @property
157- def encoded (self ):
157+ def encoded (self ) -> str :
158158 """
159159 A zipped, base64 encoded string of profile directory
160160 for use with remote WebDriver JSON wire protocol
161161 """
162162 self .update_preferences ()
163163 fp = BytesIO ()
164- zipped = zipfile .ZipFile (fp , 'w' , zipfile .ZIP_DEFLATED )
165- path_root = len (self .path ) + 1 # account for trailing slash
166- for base , dirs , files in os .walk (self .path ):
167- for fyle in files :
168- filename = os .path .join (base , fyle )
169- zipped .write (filename , filename [path_root :])
170- zipped .close ()
164+ with zipfile .ZipFile (fp , 'w' , zipfile .ZIP_DEFLATED ) as zipped :
165+ path_root = len (self .path ) + 1 # account for trailing slash
166+ for base , _ , files in os .walk (self .path ):
167+ for fyle in files :
168+ filename = os .path .join (base , fyle )
169+ zipped .write (filename , filename [path_root :])
171170 return base64 .b64encode (fp .getvalue ()).decode ('UTF-8' )
172171
173172 def _create_tempfolder (self ):
@@ -185,13 +184,12 @@ def _write_user_prefs(self, user_prefs):
185184 f .write (f'user_pref("{ key } ", { json .dumps (value )} );\n ' )
186185
187186 def _read_existing_userjs (self , userjs ):
188- import warnings
189187
190- PREF_RE = re .compile (r'user_pref\("(.*)",\s(.*)\)' )
188+ pref_pattern = re .compile (r'user_pref\("(.*)",\s(.*)\)' )
191189 try :
192190 with open (userjs , encoding = 'utf-8' ) as f :
193191 for usr in f :
194- matches = re .search (PREF_RE , usr )
192+ matches = pref_pattern .search (usr )
195193 try :
196194 self .default_preferences [matches .group (1 )] = json .loads (matches .group (2 ))
197195 except Exception :
0 commit comments