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