summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2011-08-14 16:11:29 +0000
committerelie <elie>2011-08-14 16:11:29 +0000
commit49602734a7dc5d864427e28178d1d1d8d801ce46 (patch)
treed6feafafaefa5b5dc81ebeb125857f3cd6250a85
parentcde81d1bac8358a22f1eb701dfc71e660c87c782 (diff)
downloadpyasn1-git-49602734a7dc5d864427e28178d1d1d8d801ce46.tar.gz
drop string module usage
-rw-r--r--CHANGES.txt3
-rw-r--r--pyasn1/codec/ber/encoder.py11
-rw-r--r--pyasn1/codec/cer/encoder.py3
-rw-r--r--pyasn1/type/base.py1
-rw-r--r--pyasn1/type/constraint.py3
-rw-r--r--pyasn1/type/tag.py3
-rw-r--r--pyasn1/type/univ.py43
-rw-r--r--setup.py3
8 files changed, 28 insertions, 42 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index ee8ac6b..b3a5b6c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,7 +2,8 @@ Revision 0.0.14
---------------
- Major overhawl for Python 2K/3K compatibility:
- + Get rid of types
+ + Get rid of old-style types
+ + Drop string module usage
Revision 0.0.13
---------------
diff --git a/pyasn1/codec/ber/encoder.py b/pyasn1/codec/ber/encoder.py
index 23e57a2..63f9f01 100644
--- a/pyasn1/codec/ber/encoder.py
+++ b/pyasn1/codec/ber/encoder.py
@@ -1,5 +1,4 @@
# BER encoder
-import string
from pyasn1.type import base, tag, univ, char, useful
from pyasn1.codec.ber import eoo
from pyasn1 import error
@@ -94,7 +93,7 @@ class IntegerEncoder(AbstractItemEncoder):
(octets[0] == 0 and octets[1] & 0x80 == 0 or \
octets[0] == 0xff and octets[1] & 0x80 != 0):
del octets[0]
- return string.join(map(chr, octets), ''), 0
+ return ''.join(map(chr, octets)), 0
class BitStringEncoder(AbstractItemEncoder):
def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
@@ -105,9 +104,7 @@ class BitStringEncoder(AbstractItemEncoder):
r[i] = r.get(i,0) | value[p]<<(7-j)
p = p + 1
keys = r.keys(); keys.sort()
- return chr(7-j) + string.join(
- map(lambda k,r=r: chr(r[k]), keys),''
- ), 0
+ return chr(7-j) + ''.join(map(lambda k,r=r: chr(r[k]), keys)), 0
else:
pos = 0; substrate = ''
while 1:
@@ -182,9 +179,9 @@ class ObjectIdentifierEncoder(AbstractItemEncoder):
subid = subid >> 7
# Convert packed Sub-Object ID to string and add packed
# it to resulted Object ID
- octets = octets + (string.join(res, ''),)
+ octets = octets + (''.join(res),)
- return string.join(octets, ''), 0
+ return ''.join(octets), 0
class RealEncoder(AbstractItemEncoder):
def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
diff --git a/pyasn1/codec/cer/encoder.py b/pyasn1/codec/cer/encoder.py
index a93378b..cb8ab67 100644
--- a/pyasn1/codec/cer/encoder.py
+++ b/pyasn1/codec/cer/encoder.py
@@ -1,5 +1,4 @@
# CER encoder
-import string
from pyasn1.type import univ
from pyasn1.codec.ber import encoder
@@ -65,7 +64,7 @@ class SetOfEncoder(encoder.SequenceOfEncoder):
encodeFun(client[idx], defMode, maxChunkSize)
)
compSubs.sort() # perhaps padding's not needed
- substrate = string.join(compSubs, '')
+ substrate = ''.join(compSubs)
return substrate, 1
tagMap = encoder.tagMap.copy()
diff --git a/pyasn1/type/base.py b/pyasn1/type/base.py
index 142d904..a024e74 100644
--- a/pyasn1/type/base.py
+++ b/pyasn1/type/base.py
@@ -1,6 +1,5 @@
# Base classes for ASN.1 types
from operator import getslice, setslice, delslice
-from string import join
from pyasn1.type import constraint, tagmap
from pyasn1 import error
diff --git a/pyasn1/type/constraint.py b/pyasn1/type/constraint.py
index 683aacb..4398f1c 100644
--- a/pyasn1/type/constraint.py
+++ b/pyasn1/type/constraint.py
@@ -11,7 +11,6 @@
Original concept and code by Mike C. Fletcher.
"""
-import string
from pyasn1.type import error
class AbstractConstraint:
@@ -34,7 +33,7 @@ class AbstractConstraint:
def __repr__(self):
return '%s(%s)' % (
self.__class__.__name__,
- string.join(map(lambda x: repr(x), self._values), ', ')
+ ', '.join(map(lambda x: repr(x), self._values))
)
# __cmp__ must accompany __hash__
def __cmp__(self, other):
diff --git a/pyasn1/type/tag.py b/pyasn1/type/tag.py
index 364857f..5fdd569 100644
--- a/pyasn1/type/tag.py
+++ b/pyasn1/type/tag.py
@@ -1,6 +1,5 @@
# ASN.1 types tags
from operator import getslice
-from string import join
from pyasn1 import error
tagClassUniversal = 0x00
@@ -62,7 +61,7 @@ class TagSet:
def __repr__(self):
return '%s(%s)' % (
self.__class__.__name__,
- join(map(lambda x: repr(x), self.__superTags), ', ')
+ ', '.join(map(lambda x: repr(x), self.__superTags))
)
def __add__(self, superTag):
diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py
index 76f9a3a..3b54bc6 100644
--- a/pyasn1/type/univ.py
+++ b/pyasn1/type/univ.py
@@ -1,5 +1,4 @@
# ASN.1 "universal" data types
-import string
import operator
from pyasn1.type import base, tag, constraint, namedtype, namedval, tagmap
from pyasn1.codec.ber import eoo
@@ -64,14 +63,11 @@ class Integer(base.AbstractSimpleAsn1Item):
if r is not None:
return r
try:
- return string.atoi(value)
- except:
- try:
- return string.atol(value)
- except:
- raise error.PyAsn1Error(
- 'Can\'t coerce %s into integer' % value
- )
+ return int(value)
+ except ValueError, why:
+ raise error.PyAsn1Error(
+ 'Can\'t coerce %s into integer: %s' % (value, why)
+ )
def prettyOut(self, value):
r = self.__namedValues.getName(value)
@@ -213,7 +209,7 @@ class BitString(base.AbstractSimpleAsn1Item):
elif value[-2:] == '\'H':
for v in value[1:-2]:
i = 4
- v = string.atoi(v, 16)
+ v = int(v, 16)
while i:
i = i - 1
r.append((v>>i)&0x01)
@@ -223,7 +219,7 @@ class BitString(base.AbstractSimpleAsn1Item):
'Bad BIT STRING value notation %s' % value
)
else:
- for i in string.split(value, ','):
+ for i in value.split(','):
j = self.__namedValues.getValue(i)
if j is None:
raise error.PyAsn1Error(
@@ -249,7 +245,7 @@ class BitString(base.AbstractSimpleAsn1Item):
)
def prettyOut(self, value):
- return '\"\'%s\'B\"' % string.join(map(str, value), '')
+ return '\"\'%s\'B\"' % ''.join(map(str, value))
class OctetString(base.AbstractSimpleAsn1Item):
tagSet = baseTagSet = tag.initTagSet(
@@ -292,12 +288,12 @@ class OctetString(base.AbstractSimpleAsn1Item):
p = ''
for v in value[1:-2]:
if p:
- r = r + chr(string.atoi(p+v, 16))
+ r = r + chr(int(p+v, 16))
p = ''
else:
p = v
if p:
- r = r + chr(string.atoi(p+'0', 16))
+ r = r + chr(int(p+'0', 16))
else:
raise error.PyAsn1Error(
'Bad OCTET STRING value notation %s' % value
@@ -371,17 +367,14 @@ class ObjectIdentifier(base.AbstractSimpleAsn1Item):
return tuple(value)
elif isinstance(value, str):
r = []
- for element in filter(None, string.split(value, '.')):
+ for element in filter(None, value.split('.')):
try:
- r.append(string.atoi(element, 0))
- except string.atoi_error:
- try:
- r.append(string.atol(element, 0))
- except string.atol_error, why:
- raise error.PyAsn1Error(
- 'Malformed Object ID %s at %s: %s' %
- (str(value), self.__class__.__name__, why)
- )
+ r.append(int(element, 0))
+ except ValueError, why:
+ raise error.PyAsn1Error(
+ 'Malformed Object ID %s at %s: %s' %
+ (str(value), self.__class__.__name__, why)
+ )
value = tuple(r)
pass
@@ -403,7 +396,7 @@ class ObjectIdentifier(base.AbstractSimpleAsn1Item):
r.append(str(subOid))
if r[-1] and r[-1][-1] == 'L':
r[-1][-1] = r[-1][:-1]
- return string.join(r, '.')
+ return '.'.join(r)
class Real(base.AbstractSimpleAsn1Item):
_plusInf = float('inf')
diff --git a/setup.py b/setup.py
index 9223793..8c436e5 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import sys
-import string
def howto_install_setuptools():
print """Error: You need setuptools Python package!
@@ -17,7 +16,7 @@ try:
}
except ImportError:
for arg in sys.argv:
- if string.find(arg, 'egg') != -1:
+ if arg.find('egg') != -1:
howto_install_setuptools()
sys.exit(1)
from distutils.core import setup