20
20
21
21
22
22
def is_gae_server ():
23
- server_software = os .getenv (" SERVER_SOFTWARE" , "" )
24
- return server_software .startswith (" Google App Engine" )
23
+ server_software = os .getenv (' SERVER_SOFTWARE' , '' )
24
+ return server_software .startswith (' Google App Engine' )
25
25
26
26
27
27
class GoogleBlobstoreTemporaryUploadedFile (TemporaryUploadedFile ):
@@ -96,7 +96,7 @@ def __init__(self, location=None, base_url=None, force_use_gcs=False):
96
96
self .force_use_gcs = force_use_gcs
97
97
98
98
def _open (self , name , mode = 'r' ):
99
- filename = self .location + "/" + name
99
+ filename = '{}/{}' . format ( self .location , name )
100
100
101
101
# rb is not supported
102
102
if mode == 'rb' :
@@ -114,7 +114,7 @@ def _open(self, name, mode='r'):
114
114
return gcs_file
115
115
116
116
def _save (self , name , content ):
117
- filename = self .location + "/" + name
117
+ filename = '{}/{}' . format ( self .location , name )
118
118
filename = os .path .normpath (filename )
119
119
type , encoding = mimetypes .guess_type (name )
120
120
cache_control = settings .GOOGLE_CLOUD_STORAGE_DEFAULT_CACHE_CONTROL
@@ -142,7 +142,8 @@ def _save(self, name, content):
142
142
return name
143
143
144
144
def delete (self , name ):
145
- filename = self .location + "/" + name
145
+ filename = '{}/{}' .format (self .location , name )
146
+
146
147
try :
147
148
gcs .delete (filename )
148
149
except gcs .NotFoundError :
@@ -163,14 +164,14 @@ def listdir(self, path=None):
163
164
head , tail = os .path .split (filePath )
164
165
subPath = os .path .join (self .location , path )
165
166
head = head .replace (subPath , '' , 1 )
166
- if head == "" :
167
+ if head == '' :
167
168
head = None
168
169
if not head and tail :
169
170
files .append (tail )
170
171
if head :
171
- if not head .startswith ("/" ):
172
- head = "/" + head
173
- dir = head .split ("/" )[1 ]
172
+ if not head .startswith ('/' ):
173
+ head = '/{}' . format ( head )
174
+ dir = head .split ('/' )[1 ]
174
175
if dir not in directories :
175
176
directories .append (dir )
176
177
return directories , files
@@ -199,10 +200,11 @@ def url(self, name):
199
200
200
201
filename = '/gs{}/{}' .format (self .location , name )
201
202
key = create_gs_key (filename )
202
- local_base_url = getattr (settings , " GOOGLE_CLOUD_STORAGE_DEV_URL" ,
203
- " http://localhost:8001/blobstore/blob/" )
203
+ local_base_url = getattr (settings , ' GOOGLE_CLOUD_STORAGE_DEV_URL' ,
204
+ ' http://localhost:8001/blobstore/blob/' )
204
205
return '{}{}?display=inline' .format (local_base_url , key )
205
206
206
207
def statFile (self , name ):
207
- filename = self .location + "/" + name
208
+ filename = '{}/{}' .format (self .location , name )
209
+
208
210
return gcs .stat (filename )
0 commit comments