~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/conch/ssh/asn1.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
"""
 
5
A basic ASN.1 parser.  Deprecated since Twisted 9.0 in favor of PyASN1.
 
6
 
 
7
Maintainer: Paul Swartz
 
8
"""
 
9
 
 
10
import itertools
 
11
from pyasn1.type import univ
 
12
from pyasn1.codec.ber import decoder, encoder
 
13
from twisted.python.deprecate import deprecated
 
14
from twisted.python import versions
 
15
 
 
16
Twisted9point0 = versions.Version('Twisted', 9, 0, 0)
 
17
 
 
18
def parse(data):
 
19
    return decoder.decode(data)[0]
 
20
 
 
21
parse = deprecated(Twisted9point0)(parse)
 
22
 
 
23
 
 
24
def pack(data):
 
25
    asn1Sequence = univ.Sequence()
 
26
    for index, value in itertools.izip(itertools.count(), data):
 
27
        try:
 
28
            valueAsInteger = univ.Integer(value)
 
29
        except TypeError:
 
30
            raise ValueError("cannot pack %r" % (value,))
 
31
        asn1Sequence.setComponentByPosition(index, univ.Integer(value))
 
32
    return encoder.encode(asn1Sequence)
 
33
 
 
34
pack = deprecated(Twisted9point0)(pack)