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