##// END OF EJS Templates
fallback on defaultencoding if filesystemencoding is None...
MinRK -
Show More
@@ -25,6 +25,8 b' from IPython.utils.importstring import import_item'
25 25 # Code
26 26 #-----------------------------------------------------------------------------
27 27
28 # in case filesystemencoding() returns None:
29 fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
28 30
29 31 def _get_long_path_name(path):
30 32 """Dummy no-op."""
@@ -170,7 +172,7 b' def get_home_dir():'
170 172 root=os.path.abspath(root).rstrip('\\')
171 173 if isdir(os.path.join(root, '_ipython')):
172 174 os.environ["IPYKITROOT"] = root
173 return root.decode(sys.getfilesystemencoding())
175 return root.decode(fs_encoding)
174 176
175 177 if os.name == 'posix':
176 178 # Linux, Unix, AIX, OS X
@@ -185,11 +187,11 b' def get_home_dir():'
185 187 homedir = Popen('echo $HOME', shell=True,
186 188 stdout=PIPE).communicate()[0].strip()
187 189 if homedir:
188 return homedir.decode(sys.getfilesystemencoding())
190 return homedir.decode(fs_encoding)
189 191 else:
190 192 raise HomeDirError('Undefined $HOME, IPython cannot proceed.')
191 193 else:
192 return homedir.decode(sys.getfilesystemencoding())
194 return homedir.decode(fs_encoding)
193 195 elif os.name == 'nt':
194 196 # Now for win9x, XP, Vista, 7?
195 197 # For some strange reason all of these return 'nt' for os.name.
@@ -203,7 +205,7 b' def get_home_dir():'
203 205 pass
204 206 else:
205 207 if isdir(homedir):
206 return homedir.decode(sys.getfilesystemencoding())
208 return homedir.decode(fs_encoding)
207 209
208 210 # Now look for a local home directory
209 211 try:
@@ -212,7 +214,7 b' def get_home_dir():'
212 214 pass
213 215 else:
214 216 if isdir(homedir):
215 return homedir.decode(sys.getfilesystemencoding())
217 return homedir.decode(fs_encoding)
216 218
217 219 # Now the users profile directory
218 220 try:
@@ -221,7 +223,7 b' def get_home_dir():'
221 223 pass
222 224 else:
223 225 if isdir(homedir):
224 return homedir.decode(sys.getfilesystemencoding())
226 return homedir.decode(fs_encoding)
225 227
226 228 # Use the registry to get the 'My Documents' folder.
227 229 try:
@@ -236,7 +238,7 b' def get_home_dir():'
236 238 pass
237 239 else:
238 240 if isdir(homedir):
239 return homedir.decode(sys.getfilesystemencoding())
241 return homedir.decode(fs_encoding)
240 242
241 243 # A user with a lot of unix tools in win32 may have defined $HOME.
242 244 # Try this as a last ditch option.
@@ -246,13 +248,13 b' def get_home_dir():'
246 248 pass
247 249 else:
248 250 if isdir(homedir):
249 return homedir.decode(sys.getfilesystemencoding())
251 return homedir.decode(fs_encoding)
250 252
251 253 # If all else fails, raise HomeDirError
252 254 raise HomeDirError('No valid home directory could be found')
253 255 elif os.name == 'dos':
254 256 # Desperate, may do absurd things in classic MacOS. May work under DOS.
255 return 'C:\\'.decode(sys.getfilesystemencoding())
257 return 'C:\\'.decode(fs_encoding)
256 258 else:
257 259 raise HomeDirError('No valid home directory could be found for your OS')
258 260
@@ -270,7 +272,7 b' def get_xdg_dir():'
270 272 # use ~/.config if not set OR empty
271 273 xdg = env.get("XDG_CONFIG_HOME", None) or os.path.join(get_home_dir(), '.config')
272 274 if xdg and isdir(xdg):
273 return xdg.decode(sys.getfilesystemencoding())
275 return xdg.decode(fs_encoding)
274 276
275 277 return None
276 278
@@ -309,13 +311,13 b' def get_ipython_dir():'
309 311 # not using XDG
310 312 ipdir = home_ipdir
311 313
312 return ipdir.decode(sys.getfilesystemencoding())
314 return ipdir.decode(fs_encoding)
313 315
314 316
315 317 def get_ipython_package_dir():
316 318 """Get the base directory where IPython itself is installed."""
317 319 ipdir = os.path.dirname(IPython.__file__)
318 return ipdir.decode(sys.getfilesystemencoding())
320 return ipdir.decode(fs_encoding)
319 321
320 322
321 323 def get_ipython_module_path(module_str):
@@ -330,7 +332,7 b' def get_ipython_module_path(module_str):'
330 332 mod = import_item(module_str)
331 333 the_path = mod.__file__.replace('.pyc', '.py')
332 334 the_path = the_path.replace('.pyo', '.py')
333 return the_path.decode(sys.getfilesystemencoding())
335 return the_path.decode(fs_encoding)
334 336
335 337
336 338 def expand_path(s):
General Comments 0
You need to be logged in to leave comments. Login now