if self.__fRadioActivate.get_active():
id = self.__fLicenseIDEntry.get_text()
errs, lic = abstract.[COLOR="Red"]ValidateAndNormalizeLicenseID(id)[/COLOR]
if len(errs) == 0 and id[0] == 'T':
errs.append(_('You cannot enter a trial license id here'))
if len(errs) > 0:
msg = _('Invalid license id: %s. Please check and correct it. Errors found were:\n\n%s') % (id, '\n'.join(errs))
buttons = [dialogs.CButtonSpec(_('_OK'), None, wgtk.STOCK_OK)]
dlg = messages.CMessageDialog(self.fSingletons, _('Invalid License ID'), msg, [], buttons)
dlg.RunAsModal(self)
return True
def ValidateAndNormalizeLicenseID(id):
errs, id2 = __ValidateAndNormalize(id)
if len(id2) > 0 and id2[0] not in kLicenseUseCodes:
errs.append(_('Invalid first character: Should be one of %s') % str(kLicenseUseCodes))
if len(id2) > 1 and id2[1] != kLicenseProdCode:
cur_product = 'Wing IDE %s' % config.kProduct
lic_product = kLicenseProdForCode.get(id2[1], None)
if lic_product is None:
lic_product = _('an unknown product')
else:
lic_product = 'Wing IDE %s' % config.k_ProductNames[lic_product]
errs.append(_('Your license is for %s, but you are currently running %s. Please download the correct product from http://wingware.com/downloads or upgrade your license at https://wingware.com/store/upgrade') % (lic_product, cur_product))
if len(errs) > 0:
check_code = id.strip().upper().replace('-', '')
if len(check_code) == 16:
looks_like_11 = True
for c in check_code:
if c not in '0123456789ABCDEF':
looks_like_11 = False
if looks_like_11:
errs = [_('You cannot activate using a Wing IDE 1.1 license: Please use a trial license or upgrade your license at http://wingware.com/store/upgrade')]
if len(errs) > 0:
return (errs, None)
else:
return ([], id2)
def __ValidateAndNormalize(code):
"""Remove hyphens and extra space/chars in a license id or activation
request, and validate it as within the realm of possibility. Returns
errs, value."""
errs = []
code = code.strip().upper()
code2 = ''
badchars = ''
for c in code:
if c in ('-', ' ', '\t'):
pass
elif c not in textutils.BASE30:
code2 += c
if badchars.find(c) == -1:
badchars += c
else:
code2 += c
if len(badchars) > 0:
errs.append(_('Contains invalid characters: %s') % badchars)
if len(code2) != 20:
errs.append(_('Wrong length (should contain 20 non-hyphen characters)'))
if len(errs) > 0:
return (errs, code2)
else:
return ([], AddHyphens(code2))