Пример #1
0
def unicodeFilename(filename, charset=None):
    if not charset:
        charset = getTerminalCharset()
    try:
        return unicode(filename, charset)
    except UnicodeDecodeError:
        return makePrintable(filename, charset, to_unicode=True)
Пример #2
0
def unicodeFilename(filename, charset=None):
    if not charset:
        charset = getTerminalCharset()
    try:
        return unicode(filename, charset)
    except UnicodeDecodeError:
        return makePrintable(filename, charset, to_unicode=True)
Пример #3
0
 def __init__(self, input, size=None, **args):
     if not hasattr(input, "seek"):
         if size is None:
             input = InputPipe(input, self._setSize)
         else:
             input = InputPipe(input)
     elif size is None:
         try:
             input.seek(0, 2)
             size = input.tell() * 8
         except IOError, err:
             if err.errno == ESPIPE:
                 input = InputPipe(input, self._setSize)
             else:
                 charset = getTerminalCharset()
                 errmsg = unicode(str(err), charset)
                 source = args.get("source", "<inputio:%r>" % input)
                 raise InputStreamError(_("Unable to get size of %s: %s") % (source, errmsg))
def FileInputStream(filename, real_filename=None, **args):
    """
    Create an input stream of a file. filename must be unicode.

    real_filename is an optional argument used to specify the real filename,
    its type can be 'str' or 'unicode'. Use real_filename when you are
    not able to convert filename to real unicode string (ie. you have to
    use unicode(name, 'replace') or unicode(name, 'ignore')).
    """
    assert isinstance(filename, unicode)
    if not real_filename:
        real_filename = filename
    try:
        inputio = open(real_filename, 'rb')
    except IOError, err:
        charset = getTerminalCharset()
        errmsg = unicode(str(err), charset)
        raise InputStreamError(_("Unable to open file %s: %s") % (filename, errmsg))
Пример #5
0
def FileInputStream(filename, real_filename=None, **args):
    """
    Create an input stream of a file. filename must be unicode.

    real_filename is an optional argument used to specify the real filename,
    its type can be 'str' or 'unicode'. Use real_filename when you are
    not able to convert filename to real unicode string (ie. you have to
    use unicode(name, 'replace') or unicode(name, 'ignore')).
    """
    assert isinstance(filename, unicode)
    if not real_filename:
        real_filename = filename
    try:
        inputio = open(real_filename, "rb")
    except IOError, err:
        charset = getTerminalCharset()
        errmsg = unicode(str(err), charset)
        raise InputStreamError(_("Unable to open file %s: %s") % (filename, errmsg))
Пример #6
0
 def __init__(self, input, size=None, **args):
     if not hasattr(input, "seek"):
         if size is None:
             input = InputPipe(input, self._setSize)
         else:
             input = InputPipe(input)
     elif size is None:
         try:
             input.seek(0, 2)
             size = input.tell() * 8
         except IOError, err:
             if err.errno == ESPIPE:
                 input = InputPipe(input, self._setSize)
             else:
                 charset = getTerminalCharset()
                 errmsg = unicode(str(err), charset)
                 source = args.get("source", "<inputio:%r>" % input)
                 raise InputStreamError(
                     _("Unable to get size of %s: %s") % (source, errmsg))