Skip to content

Commit

Permalink
Merge branch 'master' of github.com:renalreg/PyXB-X
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Feb 22, 2024
2 parents 61df0eb + 6ed979f commit 7443dff
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions pyxb/binding/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class duration (basis.simpleTypeDefinition, datetime.timedelta, basis._Represent
_XsdBaseType = anySimpleType
_ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('duration')

__Lexical_re = re.compile('^(?P<neg>-?)P((?P<years>\d+)Y)?((?P<months>\d+)M)?((?P<days>\d+)D)?(?P<Time>T((?P<hours>\d+)H)?((?P<minutes>\d+)M)?(((?P<seconds>\d+)(?P<fracsec>\.\d+)?)S)?)?$')
__Lexical_re = re.compile(r'^(?P<neg>-?)P((?P<years>\d+)Y)?((?P<months>\d+)M)?((?P<days>\d+)D)?(?P<Time>T((?P<hours>\d+)H)?((?P<minutes>\d+)M)?(((?P<seconds>\d+)(?P<fracsec>\.\d+)?)S)?)?$')

# We do not use weeks
__XSDFields = ( 'years', 'months', 'days', 'hours', 'minutes', 'seconds' )
Expand Down Expand Up @@ -386,13 +386,13 @@ class _PyXBDateTime_base (basis.simpleTypeDefinition, basis._RepresentAsXsdLiter
# Map from strptime/strftime formats to the regular expressions we
# use to extract them. We're more strict than strptime, so not
# trying to use that.
__PatternMap = { '%Y' : '(?P<negYear>-?)(?P<year>\d{4,})'
, '%m' : '(?P<month>\d{2})'
, '%d' : '(?P<day>\d{2})'
, '%H' : '(?P<hour>\d{2})'
, '%M' : '(?P<minute>\d{2})'
, '%S' : '(?P<second>\d{2})(?P<fracsec>\.\d+)?'
, '%Z' : '(?P<tzinfo>Z|[-+]\d\d:\d\d)' }
__PatternMap = { '%Y' : r'(?P<negYear>-?)(?P<year>\d{4,})'
, '%m' : r'(?P<month>\d{2})'
, '%d' : r'(?P<day>\d{2})'
, '%H' : r'(?P<hour>\d{2})'
, '%M' : r'(?P<minute>\d{2})'
, '%S' : r'(?P<second>\d{2})(?P<fracsec>\.\d+)?'
, '%Z' : r'(?P<tzinfo>Z|[-+]\d\d:\d\d)' }

# Cache of compiled regular expressions to parse lexical space of
# a subclass.
Expand Down
2 changes: 1 addition & 1 deletion pyxb/binding/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ def __init__ (self, *args, **kw):

pyxb.namespace.XML.validateComponentModel()

__stripSpaces_re = re.compile('\s\s\s+')
__stripSpaces_re = re.compile(r'\s\s\s+')
def __stripSpaces (self, string):
return self.__stripSpaces_re.sub(' ', string)

Expand Down
8 changes: 4 additions & 4 deletions pyxb/utils/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
# This expression replaces markers in template text with the value
# obtained by looking up the marker in a dictionary.
# %{id} = value
_substIdPattern = re.compile("%{(?P<id>\w+)}")
_substIdPattern = re.compile(r"%{(?P<id>\w+)}")

# This expression performs conditional substitution: if the expression
# provided evaluates to true in a given context, then one value is
# substituted, otherwise the alternative value is substituted.
# %{?<cond>??<true>?:<false>?}
# %{?1 == 2??true?:false?}
_substConditionalPattern = re.compile("%{\?(?P<expr>.+?)\?\?(?P<true>.*?)(\?:(?P<false>.*?))?\?}", re.MULTILINE + re.DOTALL)
_substConditionalPattern = re.compile(r"%{\?(?P<expr>.+?)\?\?(?P<true>.*?)(\?:(?P<false>.*?))?\?}", re.MULTILINE + re.DOTALL)

# This expression tests whether an identifier is defined to a non-None
# value in the context; if so, it replaces the marker with template
Expand All @@ -58,11 +58,11 @@
# with the value of the test expression.
# %{?<id>?+<yessubst>?-?<nosubst>}}
# %{?maybe_text?+?@ is defined to be %{?@}?}
_substIfDefinedPattern = re.compile("%{\?(?P<id>\w+)(\?\+(?P<repl>.*?))?(\?\-(?P<ndrepl>.*?))?\?}", re.MULTILINE + re.DOTALL)
_substIfDefinedPattern = re.compile(r"%{\?(?P<id>\w+)(\?\+(?P<repl>.*?))?(\?\-(?P<ndrepl>.*?))?\?}", re.MULTILINE + re.DOTALL)

# The pattern which, if present in the body of a IfDefined block, is
# replaced by the test expression.
_substDefinedBodyPattern = re.compile("\?@")
_substDefinedBodyPattern = re.compile(r"\?@")

def _bodyIfDefinedPattern (match_object, dictionary):
global _substDefinedBodyPattern
Expand Down
4 changes: 2 additions & 2 deletions pyxb/utils/xmlre.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.

"""Support for regular expressions conformant to the XML Schema specification.
r"""Support for regular expressions conformant to the XML Schema specification.
For the most part, XML regular expressions are similar to the POSIX
ones, and can be handled by the Python C{re} module. The exceptions
Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__ (self, position, description):

_CharClassEsc_re = re.compile(r'\\(?:(?P<cgProp>[pP]{(?P<charProp>[-A-Za-z0-9]+)})|(?P<cgClass>[^pP]))')
def _MatchCharClassEsc(text, position):
"""Parse a U{charClassEsc<http://www.w3.org/TR/xmlschema-2/#nt-charClassEsc>} term.
r"""Parse a U{charClassEsc<http://www.w3.org/TR/xmlschema-2/#nt-charClassEsc>} term.
This is one of:
Expand Down
2 changes: 1 addition & 1 deletion tests/trac/test_issue_0078.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from xml.dom import Node

import os.path
xsd='''<?xml version="1.0" encoding="UTF-8"?>
xsd=r'''<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="tla">
<xs:restriction base="xs:string">
Expand Down
2 changes: 1 addition & 1 deletion tests/trac/test_trac_0047.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pyxb.utils.domutils

import os.path
xsd='''<?xml version="1.0" encoding="UTF-8"?>
xsd=r'''<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="URN:test-trac-0047" xmlns:gml="URN:test-trac-0047">
<simpleType name="NilReasonEnumeration">
<union>
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def testAsPattern (self):

c = CodePointSet()
c.add(']')
self.assertEqual('[\]]', c.asPattern())
self.assertEqual(r'[\]]', c.asPattern())
c = CodePointSet()
c.add('-')
c.add('+')
self.assertEqual('[+\-]', c.asPattern())
self.assertEqual(r'[+\-]', c.asPattern())


def testAsSingleCharacter (self):
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ def testRepr (self):
import os
import re
class TestGetMatchingFiles (unittest.TestCase):
__WXS_re = re.compile('\.wxs$')
__NoExt_re = re.compile('(^|\%s)[^\.]+$' % os.sep)
__WXS_re = re.compile(r'\.wxs$')
__NoExt_re = re.compile(r'(^|\%s)[^\.]+$' % os.sep)
__directory = None
def setUp (self):
self.__directory = tempfile.mkdtemp()
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/test_xmlre.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def testMultiCharEscapes (self):
self.assertEqual(2, position)

def testMatchCharProperty (self):
self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchAtom, "\pL", 0)
self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchAtom, "\p{L", 0)
text = "\p{L}"
self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchAtom, r"\pL", 0)
self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchAtom, r"\p{L", 0)
text = r"\p{L}"
(charset, position) = xmlre._MatchAtom(text, 0)
self.assertEqual(position, len(text))
self.assertEqual(charset, unicode.PropertyMap['L'].asPattern())
text = "\p{IsCyrillic}"
text = r"\p{IsCyrillic}"
(charset, position) = xmlre._MatchAtom(text, 0)
self.assertEqual(position, len(text))
self.assertEqual(charset, unicode.BlockMap['Cyrillic'].asPattern())
Expand Down Expand Up @@ -181,7 +181,7 @@ def testXMLToPython (self):
self.assertEqual('^(?:Why[ ]not\\?)$', xmlre.XMLToPython(r'Why[ ]not\?'))

def testRegularExpressions (self):
text = '[\i-[:]][\c-[:]]*'
text = r'[\i-[:]][\c-[:]]*'
compiled_re = re.compile(xmlre.XMLToPython(text))
self.assertTrue(compiled_re.match('identifier'))
self.assertFalse(compiled_re.match('0bad'))
Expand Down

0 comments on commit 7443dff

Please sign in to comment.