示例#1
0
文件: defines.py 项目: Crazertz/Time
 def wrapper(*argv, **argd):
     t_ansi    = GuessStringType.t_ansi
     t_unicode = GuessStringType.t_unicode
     v_types   = [ type(item) for item in argv ]
     v_types.extend( [ type(value) for (key, value) in compat.iteritems(argd) ] )
     if t_unicode in v_types:
         argv = list(argv)
         for index in compat.xrange(len(argv)):
             if v_types[index] == t_unicode:
                 argv[index] = t_ansi(argv[index])
         for key, value in argd.items():
             if type(value) == t_unicode:
                 argd[key] = t_ansi(value)
     return fn(*argv, **argd)
示例#2
0
 def wrapper(*argv, **argd):
     t_ansi = GuessStringType.t_ansi
     t_unicode = GuessStringType.t_unicode
     v_types = [type(item) for item in argv]
     v_types.extend(
         [type(value) for (key, value) in compat.iteritems(argd)])
     if t_unicode in v_types:
         argv = list(argv)
         for index in compat.xrange(len(argv)):
             if v_types[index] == t_unicode:
                 argv[index] = t_ansi(argv[index])
         for key, value in list(argd.items()):
             if type(value) == t_unicode:
                 argd[key] = t_ansi(value)
     return fn(*argv, **argd)
示例#3
0
    def __call__(self, *argv, **argd):

        # Shortcut to self.t_ansi
        t_ansi = self.t_ansi

        # Get the types of all arguments for the function
        v_types = [type(item) for item in argv]
        v_types.extend(
            [type(value) for (key, value) in compat.iteritems(argd)])

        # Get the appropriate function for the default type
        if self.t_default == t_ansi:
            fn = self.fn_ansi
        else:
            fn = self.fn_unicode

        # If at least one argument is a Unicode string...
        if self.t_unicode in v_types:

            # If al least one argument is an ANSI string,
            # convert all ANSI strings to Unicode
            if t_ansi in v_types:
                argv = list(argv)
                for index in compat.xrange(len(argv)):
                    if v_types[index] == t_ansi:
                        argv[index] = compat.str(argv[index])
                for (key, value) in list(argd.items()):
                    if type(value) == t_ansi:
                        argd[key] = compat.str(value)

            # Use the W version
            fn = self.fn_unicode

        # If at least one argument is an ANSI string,
        # but there are no Unicode strings...
        elif t_ansi in v_types:

            # Use the A version
            fn = self.fn_ansi

        # Call the function and return the result
        return fn(*argv, **argd)
示例#4
0
文件: defines.py 项目: Crazertz/Time
    def __call__(self, *argv, **argd):

        # Shortcut to self.t_ansi
        t_ansi    = self.t_ansi

        # Get the types of all arguments for the function
        v_types   = [ type(item) for item in argv ]
        v_types.extend( [ type(value) for (key, value) in compat.iteritems(argd) ] )

        # Get the appropriate function for the default type
        if self.t_default == t_ansi:
            fn = self.fn_ansi
        else:
            fn = self.fn_unicode

        # If at least one argument is a Unicode string...
        if self.t_unicode in v_types:

            # If al least one argument is an ANSI string,
            # convert all ANSI strings to Unicode
            if t_ansi in v_types:
                argv = list(argv)
                for index in compat.xrange(len(argv)):
                    if v_types[index] == t_ansi:
                        argv[index] = compat.unicode(argv[index])
                for (key, value) in argd.items():
                    if type(value) == t_ansi:
                        argd[key] = compat.unicode(value)

            # Use the W version
            fn = self.fn_unicode

        # If at least one argument is an ANSI string,
        # but there are no Unicode strings...
        elif t_ansi in v_types:

            # Use the A version
            fn = self.fn_ansi

        # Call the function and return the result
        return fn(*argv, **argd)
示例#5
0
文件: util.py 项目: 650elx/middleware
    def native_to_win32_pathname(name):
        """
        @type  name: str
        @param name: Native (NT) absolute pathname.

        @rtype:  str
        @return: Win32 absolute pathname.
        """
        # XXX TODO
        # There are probably some native paths that
        # won't be converted by this naive approach.
        if name.startswith(compat.b("\\")):
            if name.startswith(compat.b("\\??\\")):
                name = name[4:]
            elif name.startswith(compat.b("\\SystemRoot\\")):
                system_root_path = os.environ['SYSTEMROOT']
                if system_root_path.endswith('\\'):
                    system_root_path = system_root_path[:-1]
                name = system_root_path + name[11:]
            else:
                for drive_number in compat.xrange(ord('A'), ord('Z') + 1):
                    drive_letter = '%c:' % drive_number
                    try:
                        device_native_path = win32.QueryDosDevice(drive_letter)
                    except WindowsError:
                        e = sys.exc_info()[1]
                        if e.winerror in (win32.ERROR_FILE_NOT_FOUND, \
                                                 win32.ERROR_PATH_NOT_FOUND):
                            continue
                        raise
                    if not device_native_path.endswith(compat.b('\\')):
                        device_native_path += compat.b('\\')
                    if name.startswith(device_native_path):
                        name = drive_letter + compat.b('\\') + \
                                              name[ len(device_native_path) : ]
                        break
        return name
示例#6
0
    def native_to_win32_pathname(name):
        """
        @type  name: str
        @param name: Native (NT) absolute pathname.

        @rtype:  str
        @return: Win32 absolute pathname.
        """
        # XXX TODO
        # There are probably some native paths that
        # won't be converted by this naive approach.
        if name.startswith(compat.b("\\")):
            if name.startswith(compat.b("\\??\\")):
                name = name[4:]
            elif name.startswith(compat.b("\\SystemRoot\\")):
                system_root_path = os.environ['SYSTEMROOT']
                if system_root_path.endswith('\\'):
                    system_root_path = system_root_path[:-1]
                name = system_root_path + name[11:]
            else:
                for drive_number in compat.xrange(ord('A'), ord('Z') + 1):
                    drive_letter = '%c:' % drive_number
                    try:
                        device_native_path = win32.QueryDosDevice(drive_letter)
                    except WindowsError:
                        e = sys.exc_info()[1]
                        if e.winerror in (win32.ERROR_FILE_NOT_FOUND, \
                                                 win32.ERROR_PATH_NOT_FOUND):
                            continue
                        raise
                    if not device_native_path.endswith(compat.b('\\')):
                        device_native_path += compat.b('\\')
                    if name.startswith(device_native_path):
                        name = drive_letter + compat.b('\\') + \
                                              name[ len(device_native_path) : ]
                        break
        return name