本文整理汇总了Python中pyaid.string.StringUtils.StringUtils.begins方法的典型用法代码示例。如果您正苦于以下问题:Python StringUtils.begins方法的具体用法?Python StringUtils.begins怎么用?Python StringUtils.begins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyaid.string.StringUtils.StringUtils
的用法示例。
在下文中一共展示了StringUtils.begins方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generateHeaders
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import begins [as 别名]
def _generateHeaders(self, keyName, expires =None, eTag =None, maxAge =-1):
"""Doc..."""
headers = dict()
if expires:
if isinstance(expires, unicode):
headers['Expires'] = expires.encode('utf-8', 'ignore')
elif isinstance(expires, str):
headers['Expires'] = expires
else:
headers['Expires'] = TimeUtils.dateTimeToWebTimestamp(expires)
elif eTag:
headers['ETag'] = unicode(eTag)
if maxAge > -1:
headers['Cache-Control'] = 'public, max-age=' + unicode(maxAge)
if keyName.endswith('.jpg'):
contentType = MIME_TYPES.JPEG_IMAGE
elif keyName.endswith('.png'):
contentType = MIME_TYPES.PNG_IMAGE
elif keyName.endswith('.gif'):
contentType = MIME_TYPES.GIF_IMAGE
else:
contentType = FileUtils.getMimeType(keyName)
if StringUtils.begins(contentType, ('text/', 'application/')):
headers['Content-Type'] = contentType + '; charset=UTF-8'
else:
headers['Content-Type'] = contentType
return headers
示例2: name
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import begins [as 别名]
def name(self, value):
value = value.strip()
if StringUtils.begins(value.upper(), ['M', 'P']):
self.left = value[1].upper() == 'L'
self.pes = value[0].upper() == 'P'
else:
self.left = value[0].upper() == 'L'
self.pes = value[1].upper() == 'P'
self.number = value[2:].upper()
示例3: _generateHeaders
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import begins [as 别名]
def _generateHeaders(
cls, keyName, expires =None, eTag =None, maxAge =-1, gzipped =False
):
"""Doc..."""
headers = dict()
if expires:
if StringUtils.isStringType(expires):
headers['Expires'] = StringUtils.toBytes(expires)
elif StringUtils.isBinaryType(expires):
headers['Expires'] = expires
else:
headers['Expires'] = StringUtils.toBytes(
TimeUtils.dateTimeToWebTimestamp(expires))
elif eTag:
headers['ETag'] = StringUtils.toBytes(eTag)
if maxAge > -1:
headers['Cache-Control'] = StringUtils.toBytes(
'max-age=%s; public' % maxAge)
if keyName.endswith('.jpg'):
contentType = MIME_TYPES.JPEG_IMAGE
elif keyName.endswith('.png'):
contentType = MIME_TYPES.PNG_IMAGE
elif keyName.endswith('.gif'):
contentType = MIME_TYPES.GIF_IMAGE
else:
contentType = FileUtils.getMimeType(keyName)
if StringUtils.begins(contentType, ('text/', 'application/')):
contentType = '%s; charset=UTF-8' % contentType
headers['Content-Type'] = contentType
if gzipped:
headers['Content-Encoding'] = 'gzip'
return headers
示例4: getByName
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import begins [as 别名]
def getByName(cls, name, session, **kwargs):
""" Returns the Tracks_Track model instance for the specified name
(e.g., 'LM3'). Note that one filters on other properties as
specified by the kwargs.
"""
name = name.strip()
if len(name) < 3:
return None
# confusingly, the name might be found in one of two formats, e.g.,
# either LM3 or ML3
if StringUtils.begins(name.upper(), ['M', 'P']):
left = name[1].upper() == 'L'
pes = name[0].upper() == 'P'
else:
left = name[0].upper() == 'L'
pes = name[1].upper() == 'P'
number = name[2:].upper()
kwargs[TrackPropEnum.LEFT.name] = left
kwargs[TrackPropEnum.PES.name] = pes
kwargs[TrackPropEnum.NUMBER.name] = number
results = cls.getByProperties(session, **kwargs)
return results
示例5: _renderImpl
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import begins [as 别名]
def _renderImpl(self, **kwargs):
a = self.attrs
align = a.getAsEnumerated(
TagAttributesEnum.ALIGNMENT,
AlignmentEnum,
AlignmentEnum.CENTER)
wide = a.getAsUnit(
TagAttributesEnum.WIDTH,
0,
defaultUnit='px',
unitType=int)
tall = a.getAsUnit(
TagAttributesEnum.HEIGHT,
0,
defaultUnit='px',
unitType=int)
url, urlKeyData = a.get(
TagAttributesEnum.URL,
None,
returnKey=True)
if not url:
MarkupAttributeError(
tag=self,
errorDef=MarkupAttributeError.ERROR_DEFINITION_NT(
u'no-image-specified',
u'No Image Specified',
u'Missing image URL or path definition attribute.'),
attribute=urlKeyData[0],
attributeData=urlKeyData[1],
attributeGroup=TagAttributesEnum.URL).log()
#--- LOCAL IMAGE SIZE
# For local images, try to get the size from the image file if it exists
if not StringUtils.begins(url, [u'http', u'//']):
img = LocalImage(url, self.processor.site)
if img.exists:
wide.value = img.width
tall.value = img.height
w = wide.value if wide.value > 0 else 640
h = tall.value if tall.value > 0 else 360
#--- HTML ATTRIBUTES ---#
a.styles.add({'max-width':unicode(w) + 'px', 'max-height':unicode(h) + 'px'}, 'imageBox')
a.data.add({'width':unicode(wide), 'height':unicode(tall)})
a.data.add('src', url, 'image')
a.classes.add('sfml-lazyImage', 'image')
a.classes.add('sfml-imageBox', 'imageBox')
if a.getAsBool(TagAttributesEnum.INLINE, False, kwargs, True):
a.styles.add({'display':'inline-block'})
#--- HORIZONTAL ALIGNMENT
# Set the alignment of the image within the box, which defaults sto center.
if align == 'r':
a.styles.add({
'text-align':'right',
'margin:':'auto 0 auto auto'},
'imageBox')
elif align == 'l':
a.styles.add({
'text-align':'left',
'margin':'auto auto 0 auto'},
'imageBox')
else:
a.styles.add({
'text-align':'center',
'margin':'auto'},
'imageBox')
示例6: print
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import begins [as 别名]
# INPUTS
inputPath = FileUtils.createPath('input', isDir=True)
if os.path.exists(inputPath):
SystemUtils.remove(inputPath)
os.makedirs(inputPath)
localDatabasePath = FileUtils.createPath(
rootPath, '..', 'resources', 'local', 'apps', 'Cadence', 'data', isDir=True)
if not os.path.exists(localDatabasePath):
print('[ERROR]: No local database resource folder exists')
sys.exit(1)
for filename in os.listdir(localDatabasePath):
if StringUtils.begins(filename, '.'):
# Skip '.' hidden files
continue
source = FileUtils.createPath(localDatabasePath, filename)
target = FileUtils.createPath(inputPath, filename)
if not SystemUtils.copy(source, target):
print('[ERROR]: Failed to copy "%s" database file from local app resources' % filename)
sys.exit(2)
print('[COPIED]: %s -> %s' % (
filename,
target.replace(FileUtils.getDirectoryOf(rootPath), '') ))
#---------------------------------------------------------------------------------------------------
# OUTPUTS
示例7: _removeHTMLTagWhitespace
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import begins [as 别名]
def _removeHTMLTagWhitespace(self, source):
preserveBlocks = DomUtils.getPreserveBlocks(source)
res = MarkupProcessor._HTML_INSIDE_TAG_PATTERN.finditer(source)
if res:
for r in res:
start = r.start()
end = r.end()
replace = r.group('tag').replace(u'\n', u' ')
source = source[:start] + replace + source[end:]
res = MarkupProcessor._HTML_PRE_TAG_WHITESPACE_PATTERN.finditer(source)
if res:
for r in res:
start = r.start()
end = r.end()
tag = r.group('tag')
preSource = source[:start]
if StringUtils.begins(tag, (u'<span', u'<a')):
strippedPreSource = preSource.strip()
# Preserve lines between span tags
if StringUtils.ends(strippedPreSource, (u'</span>', u'</a>')):
continue
# Preserve lines between span tags and non-html entities like text
if not strippedPreSource.endswith(u'>'):
continue
skip = False
for b in preserveBlocks:
if b.start <= start <= b.end or b.start <= end <= b.end:
skip = True
break
if skip:
continue
length = len(r.group('whitespace'))
replace = u' '*length + tag
source = preSource + replace + source[end:]
res = MarkupProcessor._HTML_POST_TAG_WHITESPACE_PATTERN.finditer(source)
if res:
for r in res:
start = r.start()
end = r.end()
tag = r.group('tag')
postSource = source[end:]
if tag in (u'</span>', u'</a>'):
strippedPostSource = postSource.strip()
# Preserve lines between span tags
if StringUtils.begins(strippedPostSource, (u'<span', u'<a')):
continue
# Preserve lines between span tags and non-html entities like text
if not strippedPostSource.startswith(u'<'):
continue
skip = False
for b in preserveBlocks:
if b.start <= start <= b.end or b.start <= end <= b.end:
skip = True
break
if skip:
continue
length = len(r.group('whitespace'))
replace = tag + u' '*length
source = source[:start] + replace + postSource
return source