forked from bitshares/python-bitshares
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
77 lines (59 loc) · 2.06 KB
/
Copy pathutils.py
File metadata and controls
77 lines (59 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import re
import time
from datetime import datetime, timezone
from .exceptions import ObjectNotInProposalBuffer
timeFormat = '%Y-%m-%dT%H:%M:%S'
def formatTime(t):
""" Properly Format Time for permlinks
"""
if isinstance(t, float):
return datetime.utcfromtimestamp(t).strftime(timeFormat)
if isinstance(t, datetime):
return t.strftime(timeFormat)
def formatTimeString(t):
""" Properly Format Time for permlinks
"""
return datetime.strptime(t, timeFormat)
def formatTimeFromNow(secs=0):
""" Properly Format Time that is `x` seconds in the future
:param int secs: Seconds to go in the future (`x>0`) or the
past (`x<0`)
:return: Properly formated time for Graphene (`%Y-%m-%dT%H:%M:%S`)
:rtype: str
"""
return datetime.utcfromtimestamp(
time.time() + int(secs)).strftime(timeFormat)
def parse_time(block_time):
"""Take a string representation of time from the blockchain, and parse it
into datetime object.
"""
return datetime.strptime(block_time, timeFormat).replace(
tzinfo=timezone.utc)
def assets_from_string(text):
"""Correctly split a string containing an asset pair.
Splits the string into two assets with the separator being on of the
following: ``:``, ``/``, or ``-``.
"""
return re.split(r'[\-:/]', text)
def test_proposal_in_buffer(buf, operation_name, id):
from .transactionbuilder import ProposalBuilder
from bitsharesbase.operationids import operations
assert isinstance(buf, ProposalBuilder)
operationid = operations.get(operation_name)
_, _, j = id.split(".")
ops = buf.list_operations()
if (len(ops) <= int(j)):
raise ObjectNotInProposalBuffer(
"{} with id {} not found".format(
operation_name,
id
)
)
op = ops[int(j)].json()
if op[0] != operationid:
raise ObjectNotInProposalBuffer(
"{} with id {} not found".format(
operation_name,
id
)
)