Revision f8426b5c

b/kamaki/cli/commands/pithos.py
40 40
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
41 41
from kamaki.cli.utils import (
42 42
    format_size, to_bytes, print_dict, print_items, pretty_keys, pretty_dict,
43
    page_hold, bold, ask_user, get_path_size, print_json)
43
    page_hold, bold, ask_user, get_path_size, print_json, guess_mime_type)
44 44
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument
45 45
from kamaki.cli.argument import KeyValueArgument, DateArgument
46 46
from kamaki.cli.argument import ProgressBarArgument
......
983 983
    @errors.pithos.container
984 984
    @errors.pithos.object_path
985 985
    def _run(self):
986
        ctype, cenv = guess_mime_type(self.path)
986 987
        self._optional_output(self.client.create_object_by_manifestation(
987 988
            self.path,
988
            content_encoding=self['content_encoding'],
989
            content_encoding=self['content_encoding'] or cenc,
989 990
            content_disposition=self['content_disposition'],
990
            content_type=self['content_type'],
991
            content_type=self['content_type'], or ctype,
991 992
            sharing=self['sharing'],
992 993
            public=self['public']))
993 994

  
......
1135 1136
        container_info_cache = dict()
1136 1137
        for f, rpath in self._path_pairs(local_path, remote_path):
1137 1138
            print('%s --> %s:%s' % (f.name, self.client.container, rpath))
1139
            if not (self['content_type'] and self['content_encoding']):
1140
                ctype, cenc = guess_mime_type(f.name)
1141
                params['content_type'] = self['content_type'] or ctype
1142
                params['content_encoding'] = self['content_encoding'] or cenc
1138 1143
            if self['unchunked']:
1139 1144
                r = self.client.upload_object_unchunked(
1140 1145
                    rpath, f,
b/kamaki/cli/utils.py
75 75
            print('')
76 76

  
77 77

  
78
def guess_mime_type(
79
        filename,
80
        default_content_type='application/octet-stream',
81
        default_encoding=None):
82
    assert filename, 'Cannot guess mimetype for empty filename'
83
    try:
84
        from mimetypes import guess_type
85
        ctype, cenc = guess_type(filename)
86
        return ctype or default_content_type, cenc or default_encoding
87
    except ImportError:
88
        print 'WARNING: Cannot import mimetypes, using defaults'
89
        return (default_content_type, default_encoding)
90

  
91

  
78 92
def remove_colors():
79 93
    global bold
80 94
    global red
b/kamaki/clients/pithos/__init__.py
456 456
            format='json',
457 457
            hashmap=True,
458 458
            content_type=content_type,
459
            content_encoding=content_encoding,
459 460
            if_etag_match=if_etag_match,
460 461
            if_etag_not_match='*' if if_not_exist else None,
461 462
            etag=etag,

Also available in: Unified diff