Ignore:
Timestamp:
03/07/12 20:15:51 (2 years ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
rebase_source:
78ee9b1644489e06468a72a9633b10cf42a7ef66
Message:

Accept unicode objects in sys.getfilesystemencoding() as filenames to Table save/load functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/orange/lib_kernel.cpp

    r10357 r10460  
    27352735 
    27362736const char *getExtension(const char *name); 
     2737char *getFileSystemEncoding(); // defined in lib_io.cpp 
    27372738 
    27382739PyObject *saveTabDelimited(PyObject *, PyObject *args, PyObject *keyws); 
     
    27452746{ 
    27462747  char *filename; 
     2748  bool free_filename = false; 
    27472749  if (!PyArg_ParseTuple(args, "s:ExampleGenerator.save", &filename)) 
    2748     return PYNULL; 
     2750  { 
     2751      // Try again, this time with the fs encoding. 
     2752      char *encoding = getFileSystemEncoding(); 
     2753      if (!PyArg_ParseTuple(args, "es:ExampleGenerator.save", encoding, &filename)) 
     2754          return PYNULL; 
     2755      free_filename = true; 
     2756      PyErr_Clear(); 
     2757  } 
    27492758 
    27502759  const char *extension = getExtension(filename); 
    27512760  if (!extension) 
     2761  { 
     2762    if (free_filename) 
     2763        PyMem_Free(filename); 
    27522764    PYERROR(PyExc_TypeError, "file name must have an extension", PYNULL); 
     2765  } 
    27532766 
    27542767 
     
    27882801 
    27892802  Py_DECREF(newargs); 
     2803 
     2804  if (free_filename) 
     2805      PyMem_Free(filename); 
     2806 
    27902807  return res; 
    27912808} 
     
    30573074} 
    30583075 
    3059  
    30603076CONSTRUCTOR_KEYWORDS(ExampleTable, "domain use useMetas dontCheckStored dontStore filterMetas filter_metas DC DK NA noClass noCodedDiscrete createNewOn") 
    30613077 
     
    30663082    char *filename = NULL; 
    30673083    if (PyArg_ParseTuple(argstuple, "s", &filename)) 
    3068       return loadDataFromFile(type, filename, argstuple, keywords, false); 
     3084        return loadDataFromFile(type, filename, argstuple, keywords, false); 
     3085 
     3086    PyErr_Clear(); 
     3087 
     3088    /*For a case where the unicode can't be converted to a default 
     3089     * encoding (on most platforms this is ASCII) 
     3090     */ 
     3091    char * coding = getFileSystemEncoding(); 
     3092    if (PyArg_ParseTuple(argstuple, "es", coding, &filename)) 
     3093    { 
     3094        PyObject *rval = loadDataFromFile(type, filename, argstuple, keywords, false); 
     3095        PyMem_Free(filename); 
     3096        return rval; 
     3097    } 
    30693098 
    30703099    PyErr_Clear(); 
Note: See TracChangeset for help on using the changeset viewer.