Skip to content
Snippets Groups Projects
Commit 1d0fc1f9 authored by inso's avatar inso
Browse files

Fixing python parsing errors

parent 4b0225e8
Branches
Tags
No related merge requests found
......@@ -10,11 +10,12 @@ from mock import Mock
inline_selfcert = ""
class Test_SelfCertification:
'''
classdocs
'''
def test_certification(self):
version = 1
selfcert = SelfCertification.from_inline(version, inline_selfcert)
......@@ -4,13 +4,13 @@ Created on 12 déc. 2014
@author: inso
'''
import pytest
from ucoinpy.documents.transaction import Transaction
from ucoinpy.documents.membership import Membership
from mock import Mock
inline_membership = ""
class Test_Membership:
def test_frominline(self):
membership = Membership.from_inline(inline_membership)
\ No newline at end of file
......@@ -24,9 +24,8 @@ class Peer(Document):
[...]
"""
def __init__(self, version, pubkey, blockid, endpoints, signature):
def __init__(self, version, currency, pubkey, blockid, endpoints, signature):
super(version, currency, [signature])
self.currency = currency
self.pubkey = pubkey
self.blockid = blockid
self.endpoints = endpoints
......
......@@ -5,7 +5,7 @@ Created on 2 déc. 2014
'''
from . import Document
from .. import PROTOCOL_VERSION
import re
class Transaction(Document):
......@@ -47,7 +47,8 @@ SIGNATURE
re_outputs = re.compile("Outputs:\n")
re_pubkey = re.compile("([1-9A-Za-z][^OIl]{43,45})\n")
def __init__(self, version, currency, issuers, inputs, outputs, signatures):
def __init__(self, version, currency, issuers, inputs, outputs,
comment, signatures):
'''
Constructor
'''
......@@ -59,10 +60,10 @@ SIGNATURE
@classmethod
def from_compact(cls, currency, number, compact):
lines = raw.splitlines(True)
lines = compact.splitlines(True)
n = 0
header_data = re_header.match(lines[n])
header_data = Transaction.re_header.match(lines[n])
version = header_data.group(2)
issuers_num = int(header_data.group(3))
inputs_num = int(header_data.group(3))
......@@ -75,7 +76,7 @@ SIGNATURE
signatures = []
for i in range(0, issuers_num):
issuer = re_pubkey.match(lines[n]).group(1)
issuer = Transaction.re_pubkey.match(lines[n]).group(1)
issuers.append(issuer)
n = n + 1
......@@ -94,12 +95,13 @@ SIGNATURE
@classmethod
def from_raw(cls, raw):
lines = raw.splitlines(True)
n = 0
version = Transaction.re_version.match(lines[n]).group(1)
n = n + 1
type = Transaction.re_type.match(lines[n]).group(1)
Transaction.re_type.match(lines[n]).group(1)
n = n + 1
currency = Transaction.re_currency.match(lines[n]).group(1)
......@@ -120,8 +122,8 @@ SIGNATURE
if Transaction.re_inputs.match(lines[n]):
lines = lines + 1
while Transaction.re_outputs.match(lines[n]) is None:
input = InputSource.from_compact(number, lines[n])
inputs.append(input)
input_source = InputSource.from_inline(lines[n])
inputs.append(input_source)
lines = lines + 1
if Transaction.re_outputs.match(lines[n]) is not None:
......@@ -130,10 +132,9 @@ SIGNATURE
outputs.append(output)
lines = lines + 1
if Transaction.re_sign.match(lines[n]) is not None:
while n < lines.len:
sign = re_sign.match(lines[n]).group(1)
sign = Transaction.re_sign.match(lines[n]).group(1)
signatures.append(sign)
lines = lines + 1
......@@ -199,16 +200,19 @@ COMMENT
return doc
class SimpleTransaction(Transaction):
'''
As transaction class, but for only one issuer.
...
'''
def __init__(self, version, currency, issuer, single_input, outputs, comment, signature):
def __init__(self, version, currency, issuer,
single_input, outputs, comment, signature):
'''
Constructor
'''
super(version, currency, [issuer], [single_input], outputs, comment, [signature])
super(version, currency, [issuer], [single_input],
outputs, comment, [signature])
class InputSource():
......@@ -218,7 +222,8 @@ class InputSource():
Compact :
INDEX:SOURCE:FINGERPRINT:AMOUNT
'''
re_inline = re.compile("([0-9]+):(D|T):([0-9]+):([0-9a-fA-F]{5,40}):([0-9]+)")
re_inline = re.compile("([0-9]+):(D|T):([0-9]+):\
([0-9a-fA-F]{5,40}):([0-9]+)")
re_compact = re.compile("([0-9]+):(D|T):([0-9a-fA-F]{5,40}):([0-9]+)")
def __init__(self, index, source, number, txhash, amount):
......@@ -230,24 +235,23 @@ class InputSource():
@classmethod
def from_inline(cls, inline):
data = re_inline.match(inline)
data = InputSource.re_inline.match(inline)
index = data.group(1)
source = data.group(2)
number = data.group(3)
txhash = data.group(4)
amount = data;group(5)
amount = data.group(5)
return cls(data, index, source, number, txhash, amount)
@classmethod
def from_compact(cls, number, compact):
data = re_compact.match(inline)
data = InputSource.re_compact.match(compact)
index = data.group(1)
source = data.group(2)
txhash = data.group(3)
amount = data;group(4)
amount = data.group(4)
return cls(data, index, source, number, txhash, amount)
def inline(self):
return "{0}:{1}:{2}:{3}:{4}".format(self.index,
self.source,
......@@ -267,13 +271,14 @@ class OutputSource():
A Transaction OUTPUT
'''
re_inline = "([1-9A-Za-z][^OIl]{43,45}):([0-9]+)"
def __init__(self, pubkey, amount):
self.pubkey = pubkey
self.amount = amount
@lassmethod
@classmethod
def from_inline(cls, inline):
data = re_inline.match(inline)
data = OutputSource.re_inline.match(inline)
pubkey = data.group(1)
amount = data.group(2)
return cls(pubkey, amount)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment