MCPcopy
hub / github.com/pyload/pyload / findVCards

Method findVCards

module/lib/feedparser.py:2141–2356  ·  view source on GitHub ↗
(self, elmRoot, bAgentParsing=0)

Source from the content-addressed store, hash-verified

2139 return arValues
2140
2141 def findVCards(self, elmRoot, bAgentParsing=0):
2142 sVCards = ''
2143
2144 if not bAgentParsing:
2145 arCards = self.getPropertyValue(elmRoot, 'vcard', bAllowMultiple=1)
2146 else:
2147 arCards = [elmRoot]
2148
2149 for elmCard in arCards:
2150 arLines = []
2151
2152 def processSingleString(sProperty):
2153 sValue = self.getPropertyValue(elmCard, sProperty, self.STRING, bAutoEscape=1).decode(self.encoding)
2154 if sValue:
2155 arLines.append(self.vcardFold(sProperty.upper() + ':' + sValue))
2156 return sValue or u''
2157
2158 def processSingleURI(sProperty):
2159 sValue = self.getPropertyValue(elmCard, sProperty, self.URI)
2160 if sValue:
2161 sContentType = ''
2162 sEncoding = ''
2163 sValueKey = ''
2164 if sValue.startswith('data:'):
2165 sEncoding = ';ENCODING=b'
2166 sContentType = sValue.split(';')[0].split('/').pop()
2167 sValue = sValue.split(',', 1).pop()
2168 else:
2169 elmValue = self.getPropertyValue(elmCard, sProperty)
2170 if elmValue:
2171 if sProperty != 'url':
2172 sValueKey = ';VALUE=uri'
2173 sContentType = elmValue.get('type', '').strip().split('/').pop().strip()
2174 sContentType = sContentType.upper()
2175 if sContentType == 'OCTET-STREAM':
2176 sContentType = ''
2177 if sContentType:
2178 sContentType = ';TYPE=' + sContentType.upper()
2179 arLines.append(self.vcardFold(sProperty.upper() + sEncoding + sContentType + sValueKey + ':' + sValue))
2180
2181 def processTypeValue(sProperty, arDefaultType, arForceType=None):
2182 arResults = self.getPropertyValue(elmCard, sProperty, bAllowMultiple=1)
2183 for elmResult in arResults:
2184 arType = self.getPropertyValue(elmResult, 'type', self.STRING, 1, 1)
2185 if arForceType:
2186 arType = self.unique(arForceType + arType)
2187 if not arType:
2188 arType = arDefaultType
2189 sValue = self.getPropertyValue(elmResult, 'value', self.EMAIL, 0)
2190 if sValue:
2191 arLines.append(self.vcardFold(sProperty.upper() + ';TYPE=' + ','.join(arType) + ':' + sValue))
2192
2193 # AGENT
2194 # must do this before all other properties because it is destructive
2195 # (removes nested class="vcard" nodes so they don't interfere with
2196 # this vcard's other properties)
2197 arAgent = self.getPropertyValue(elmCard, 'agent', bAllowMultiple=1)
2198 for elmAgent in arAgent:

Callers 1

_parseMicroformatsFunction · 0.80

Calls 12

getPropertyValueMethod · 0.95
vcardFoldMethod · 0.95
normalizeMethod · 0.95
toISO8601Method · 0.95
compileMethod · 0.80
joinMethod · 0.80
splitMethod · 0.80
searchMethod · 0.45
getMethod · 0.45
replaceMethod · 0.45
appendMethod · 0.45
extractMethod · 0.45

Tested by

no test coverage detected