Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit dbb6784

Browse files
committed
Replace string concat with os.path.join(DATA_FOLDER,...)
1 parent d690c66 commit dbb6784

File tree

8 files changed

+99
-90
lines changed

8 files changed

+99
-90
lines changed

api/restapi.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _setContentDispositionAndSend(file_path, extension, content_type):
129129
if self.db.filemap.get_file(request.args["hash"][0]) is not None:
130130
image_path = self.db.filemap.get_file(request.args["hash"][0])
131131
else:
132-
image_path = DATA_FOLDER + "cache/" + request.args["hash"][0]
132+
image_path = os.path.join(DATA_FOLDER, "cache", request.args["hash"][0])
133133
if not os.path.exists(image_path) and "guid" in request.args:
134134
node = None
135135
for connection in self.protocol.values():
@@ -722,7 +722,8 @@ def respond(success):
722722
else:
723723
request.write(json.dumps({"success": False, "reason": "Failed to send order confirmation"}))
724724
request.finish()
725-
file_path = DATA_FOLDER + "store/contracts/in progress/" + request.args["id"][0] + ".json"
725+
file_name = request.args["id"][0] + ".json"
726+
file_path = os.path.join(DATA_FOLDER, "store", "contracts", "in progress", file_name)
726727
with open(file_path, 'r') as filename:
727728
order = json.load(filename, object_pairs_hook=OrderedDict)
728729
c = Contract(self.db, contract=order, testnet=self.protocol.testnet)
@@ -758,23 +759,23 @@ def upload_image(self, request):
758759
for image in request.args["image"]:
759760
img = image.decode('base64')
760761
hash_value = digest(img).encode("hex")
761-
with open(DATA_FOLDER + "store/media/" + hash_value, 'wb') as outfile:
762+
with open(os.path.join(DATA_FOLDER, "store", "media", hash_value), 'wb') as outfile:
762763
outfile.write(img)
763-
self.db.filemap.insert(hash_value, DATA_FOLDER + "store/media/" + hash_value)
764+
self.db.filemap.insert(hash_value, os.path.join(DATA_FOLDER, "store", "media", hash_value))
764765
ret.append(hash_value)
765766
elif "avatar" in request.args:
766767
avi = request.args["avatar"][0].decode("base64")
767768
hash_value = digest(avi).encode("hex")
768-
with open(DATA_FOLDER + "store/avatar", 'wb') as outfile:
769+
with open(os.path.join(DATA_FOLDER, "store", "avatar"), 'wb') as outfile:
769770
outfile.write(avi)
770-
self.db.filemap.insert(hash_value, DATA_FOLDER + "store/avatar")
771+
self.db.filemap.insert(hash_value, os.path.join(DATA_FOLDER, "store", "avatar"))
771772
ret.append(hash_value)
772773
elif "header" in request.args:
773774
hdr = request.args["header"][0].decode("base64")
774775
hash_value = digest(hdr).encode("hex")
775-
with open(DATA_FOLDER + "store/header", 'wb') as outfile:
776+
with open(os.path.join(DATA_FOLDER, "store", "header"), 'wb') as outfile:
776777
outfile.write(hdr)
777-
self.db.filemap.insert(hash_value, DATA_FOLDER + "store/header")
778+
self.db.filemap.insert(hash_value, os.path.join(DATA_FOLDER, "store", "header"))
778779
ret.append(hash_value)
779780
request.write(json.dumps({"success": True, "image_hashes": ret}, indent=4))
780781
request.finish()
@@ -794,7 +795,7 @@ def respond(success):
794795
else:
795796
request.write(json.dumps({"success": False, "reason": "Failed to send receipt to vendor"}))
796797
request.finish()
797-
file_path = DATA_FOLDER + "purchases/in progress/" + request.args["id"][0] + ".json"
798+
file_path = os.path.join(DATA_FOLDER, "purchases", "in progress", request.args["id"][0] + ".json")
798799
with open(file_path, 'r') as filename:
799800
order = json.load(filename, object_pairs_hook=OrderedDict)
800801
c = Contract(self.db, contract=order, testnet=self.protocol.testnet)
@@ -1138,27 +1139,27 @@ def get_order(self, request):
11381139
#TODO: if this is either a funded direct payment sale or complete moderated sale but
11391140
#TODO: the payout tx has not hit the blockchain, rebroadcast.
11401141

1141-
if os.path.exists(DATA_FOLDER + "purchases/unfunded/" + request.args["order_id"][0] + ".json"):
1142-
file_path = DATA_FOLDER + "purchases/unfunded/" + request.args["order_id"][0] + ".json"
1142+
filename = request.args["order_id"][0] + ".json"
1143+
if os.path.exists(os.path.join(DATA_FOLDER, "purchases", "unfunded", filename)):
1144+
file_path = os.path.join(DATA_FOLDER, "purchases", "unfunded", filename)
11431145
status = self.db.purchases.get_status(request.args["order_id"][0])
1144-
elif os.path.exists(DATA_FOLDER + "purchases/in progress/" + request.args["order_id"][0] + ".json"):
1145-
file_path = DATA_FOLDER + "purchases/in progress/" + request.args["order_id"][0] + ".json"
1146+
elif os.path.exists(os.path.join(DATA_FOLDER, "purchases", "in progress", filename)):
1147+
file_path = os.path.join(DATA_FOLDER, "purchases", "in progress", filename)
11461148
status = self.db.purchases.get_status(request.args["order_id"][0])
1147-
elif os.path.exists(DATA_FOLDER + "purchases/trade receipts/" + request.args["order_id"][0] + ".json"):
1148-
file_path = DATA_FOLDER + "purchases/trade receipts/" + request.args["order_id"][0] + ".json"
1149+
elif os.path.exists(os.path.join(DATA_FOLDER, "purchases", "trade receipts", filename)):
1150+
file_path = os.path.join(DATA_FOLDER, "purchases", "trade receipts", filename)
11491151
status = self.db.purchases.get_status(request.args["order_id"][0])
1150-
elif os.path.exists(DATA_FOLDER + "store/contracts/unfunded/" + request.args["order_id"][0] + ".json"):
1151-
file_path = DATA_FOLDER + "store/contracts/unfunded/" + request.args["order_id"][0] + ".json"
1152+
elif os.path.exists(os.path.join(DATA_FOLDER, "store", "contracts", "unfunded", filename)):
1153+
file_path = os.path.join(DATA_FOLDER, "store", "contracts", "unfunded", filename)
11521154
status = self.db.sales.get_status(request.args["order_id"][0])
1153-
elif os.path.exists(DATA_FOLDER + "store/contracts/in progress/" + request.args["order_id"][0] + ".json"):
1154-
file_path = DATA_FOLDER + "store/contracts/in progress/" + request.args["order_id"][0] + ".json"
1155+
elif os.path.exists(os.path.join(DATA_FOLDER, "store", "contracts", "in progress", filename)):
1156+
file_path = os.path.join(DATA_FOLDER, "store", "contracts", "in progress", filename)
11551157
status = self.db.sales.get_status(request.args["order_id"][0])
1156-
elif os.path.exists(DATA_FOLDER +
1157-
"store/contracts/trade receipts/" + request.args["order_id"][0] + ".json"):
1158-
file_path = DATA_FOLDER + "store/contracts/trade receipts/" + request.args["order_id"][0] + ".json"
1158+
elif os.path.exists(os.path.join(DATA_FOLDER, "store", "contracts", "trade receipts", filename)):
1159+
file_path = os.path.join(DATA_FOLDER, "store", "contracts", "trade receipts", filename)
11591160
status = self.db.sales.get_status(request.args["order_id"][0])
1160-
elif os.path.exists(DATA_FOLDER + "cases/" + request.args["order_id"][0] + ".json"):
1161-
file_path = DATA_FOLDER + "cases/" + request.args["order_id"][0] + ".json"
1161+
elif os.path.exists(os.path.join(DATA_FOLDER, "cases", filename)):
1162+
file_path = os.path.join(DATA_FOLDER, "cases", filename)
11621163
status = 4
11631164
else:
11641165
request.write(json.dumps({}, indent=4))

api/ws.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,11 @@ def handle_response(listings, node):
168168
}
169169
for country in l.ships_to:
170170
listing_json["listing"]["ships_to"].append(str(CountryCode.Name(country)))
171-
if not os.path.isfile(DATA_FOLDER + 'cache/' + l.thumbnail_hash.encode("hex")):
171+
if not os.path.isfile(os.path.join( \
172+
DATA_FOLDER, 'cache', l.thumbnail_hash.encode("hex"))):
172173
self.factory.mserver.get_image(node, l.thumbnail_hash)
173-
if not os.path.isfile(DATA_FOLDER + 'cache/' + listings.avatar_hash.encode("hex")):
174+
if not os.path.isfile(os.path.join( \
175+
DATA_FOLDER, 'cache', listings.avatar_hash.encode("hex"))):
174176
self.factory.mserver.get_image(node, listings.avatar_hash)
175177
self.transport.write(str(bleach.clean(
176178
json.dumps(listing_json, indent=4), tags=ALLOWED_TAGS)))

db/datastore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ def get_conversations(self):
586586
handle = ""
587587
if val[0] is not None:
588588
try:
589-
with open(DATA_FOLDER + 'cache/' + g[0], "r") as filename:
589+
with open(join(DATA_FOLDER, 'cache', g[0]), "r") as filename:
590590
profile = filename.read()
591591
p = objects.Profile()
592592
p.ParseFromString(profile)

0 commit comments

Comments
 (0)